1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

Plugin read_serial_temperature: port to python3

This commit is contained in:
Lars Kruse 2020-03-26 02:43:18 +01:00
parent 69ab03d647
commit f468341a07
2 changed files with 29 additions and 33 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
""" """
Paul Wiegmans (p.wiegmans@bonhoeffer.nl) Paul Wiegmans (p.wiegmans@bonhoeffer.nl)
2009 dec 18 2009 dec 18
@ -12,42 +12,39 @@ Linux: "/dev/usb/ttyUSB[n]" or "/dev/ttyUSB[n]"
e.g. "/dev/usb/ttyUSB0" e.g. "/dev/usb/ttyUSB0"
""" """
import sys, serial import sys
import serial
# Open named port at "19200,8,N,1", 1s timeout:: # Open named port at "19200,8,N,1", 1s timeout::
def gettemperature(): def gettemperature():
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1) connection = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
t = 0 # default to munin's value "unknown"
while t<1: result = "U"
line = ser.readline().strip() while True:
if line: line = connection.readline().strip()
temp = str(line.split(" ")[0]) # temperature in tenths celsius if line:
i = len(temp)-1 # temperature in tenths celsius
temp = temp[:i] # return only integer value (as a string) temp = str(line.split(" ")[0])
return temp # return only integer value (as a string)
t += 1 result = temp[:-1]
ser.close() break
connection.close()
return result
# shamelessly copied from weather_temp_ # shamelessly copied from weather_temp_
if len(sys.argv) == 2 and sys.argv[1] == "autoconf": if len(sys.argv) == 2 and sys.argv[1] == "autoconf":
print("yes")
print "yes"
elif len(sys.argv) == 2 and sys.argv[1] == "config": elif len(sys.argv) == 2 and sys.argv[1] == "config":
print('graph_title Temperatuur in de serverruimte')
print 'graph_title Temperatuur in de serverruimte' print('graph_vlabel temperature in C')
print 'graph_vlabel temperature in C' print('graph_category sensors')
print 'graph_category sensors' print('temperature.label temperature')
print 'temperature.label temperature' print('graph_info Dit is de temperatuur in het rek in de serverruimte B104')
print 'graph_info Dit is de temperatuur in het rek in de serverruimte B104' print('graph_scale no')
print 'graph_scale no' # lower limit 10, upper limit 50
# lower limit 10, upper limit 50 print('graph_args --base 1000 -l 10 -u 50')
print 'graph_args --base 1000 -l 10 -u 50'
else: else:
print('temperature.value %s' % gettemperature())
print 'temperature.value %s' % gettemperature()

View file

@ -427,7 +427,6 @@ plugins/system/auth
plugins/system/blockhosts plugins/system/blockhosts
plugins/systemd/systemd_units plugins/systemd/systemd_units
plugins/system/file_length_ plugins/system/file_length_
plugins/system/read_serial_temperature
plugins/tarsnap/tarsnap plugins/tarsnap/tarsnap
plugins/tcp/tcp-retransmissions plugins/tcp/tcp-retransmissions
plugins/tcp/tcp-states plugins/tcp/tcp-states