Skip to content

Commit 2fefc01

Browse files
committed
probehealth sensor fixed and added to available sensors list, cputemp sensor fix and probe_installer change to include probehealth
1 parent c079158 commit 2fefc01

File tree

4 files changed

+133
-2
lines changed

4 files changed

+133
-2
lines changed

probe_installer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def add_sensor_to_load_list(sensors):
128128
f.write("# Announce modules available in this package\n")
129129
f.write("# Just extend this list for your modules and they will be automatically imported during runtime and\n")
130130
f.write("# are announced to the PRTG Core\n")
131-
f.write("__all__ = [\"Ping\", \"HTTP\", \"Port\", \"SNMPCustom\", \"CPULoad\", \"Memory\", \"Diskspace\", \"SNMPTraffic\", \"DS18B20\"]\n")
131+
f.write("__all__ = [\"Ping\", \"HTTP\", \"Port\", \"SNMPCustom\", \"CPULoad\", \"Memory\", \"Diskspace\", \"SNMPTraffic\", \"DS18B20\", \"CPUTemp\"]\n")
132132
f.write("DS18B20_sensors = [" + str(sensors) + "]\n")
133133
f.close()
134134

sensors/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
# Announce modules available in this package
2222
# Just extend this list for your modules and they will be automatically imported during runtime and
2323
# are announced to the PRTG Core
24-
__all__ = ["Ping", "HTTP", "Port", "SNMPCustom", "CPULoad", "Memory", "Diskspace", "SNMPTraffic", "DS18B20"]
24+
__all__ = ["Ping", "HTTP", "Port", "SNMPCustom", "CPULoad", "Memory", "Diskspace", "SNMPTraffic", "DS18B20", "CPUTemp", "Probehealth"]
2525
DS18B20_sensors = ["000006ad5c3f"]

sensors/cputemp.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env python
2+
#Copyright (c) 2014, Paessler AG <[email protected]>
3+
#All rights reserved.
4+
#Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5+
# following conditions are met:
6+
#1. Redistributions of source code must retain the above copyright notice, this list of conditions
7+
# and the following disclaimer.
8+
#2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
9+
# and the following disclaimer in the documentation and/or other materials provided with the distribution.
10+
#3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
11+
# or promote products derived from this software without specific prior written permission.
12+
13+
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
14+
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
16+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
20+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21+
22+
import gc
23+
import os
24+
import logging
25+
import time
26+
import __init__
27+
28+
class CPUTemp(object):
29+
def __init__(self):
30+
gc.enable()
31+
32+
@staticmethod
33+
def get_kind():
34+
"""
35+
return sensor kind
36+
"""
37+
return "mpcputemp"
38+
39+
@staticmethod
40+
def get_sensordef():
41+
"""
42+
Definition of the sensor and data to be shown in the PRTG WebGUI
43+
"""
44+
sensordefinition = {
45+
"kind": CPUTemp.get_kind(),
46+
"name": "CPU Temperature",
47+
"description": "Returns the CPU temperature",
48+
"default": "yes",
49+
"help": "Returns the CPU temperature",
50+
"tag": "mpcputempsensor",
51+
"groups": [
52+
]
53+
}
54+
return sensordefinition
55+
56+
@staticmethod
57+
def get_data(data):
58+
temperature = CPUTemp()
59+
logging.info("Running sensor: %s" % temperature.get_kind())
60+
try:
61+
temp = temperature.read_temp()
62+
except Exception as e:
63+
logging.error("Ooops Something went wrong with '%s' sensor %s. Error: %s" % (temperature.get_kind(),
64+
data['sensorid'], e))
65+
data = {
66+
"sensorid": int(data['sensorid']),
67+
"error": "Exception",
68+
"code": 1,
69+
"message": "CPUTemp sensor failed. See log for details"
70+
}
71+
return data
72+
tempdata = []
73+
for element in temp:
74+
tempdata.append(element)
75+
data = {
76+
"sensorid": int(data['sensorid']),
77+
"message": "OK",
78+
"channel": tempdata
79+
}
80+
del temperature
81+
gc.collect()
82+
return data
83+
84+
@staticmethod
85+
def read_temp():
86+
data = []
87+
chandata = []
88+
temp = open("/sys/class/thermal/thermal_zone0/temp", "r")
89+
lines = temp.readlines()
90+
temp.close()
91+
temp_string = lines[0]
92+
logging.debug("CPUTemp Debug message: Temperature from file: %s" % temp_string)
93+
temp_c = float(temp_string) / 1000.0
94+
logging.debug("CPUTemp Debug message: Temperature after calculations:: %s" % temp_c)
95+
data.append(temp_c)
96+
for i in range(len(data)):
97+
chandata.append({"name": "CPU Temperature",
98+
"mode": "float",
99+
"unit": "Custom",
100+
"customunit": "C",
101+
"LimitMode": 1,
102+
"LimitMaxError": 40,
103+
"LimitMaxWarning": 35,
104+
"value": float(data[i])})
105+
return chandata

sensors/probehealth.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def get_data(data):
5757
try:
5858
mem = probehealth.read_memory('/proc/meminfo')
5959
cpu = probehealth.read_cpu('/proc/loadavg')
60+
temperature = probehealth.read_temp()
6061
logging.info("Running sensor: %s" % probehealth.get_kind())
6162
except Exception as e:
6263
logging.error("Ooops Something went wrong with '%s' sensor %s. Error: %s" % (probehealth.get_kind(),
@@ -71,6 +72,8 @@ def get_data(data):
7172
probedata = []
7273
for element in mem:
7374
probedata.append(element)
75+
for element in temperature:
76+
probedata.append(element)
7477
for element in cpu:
7578
probedata.append(element)
7679
data = {
@@ -136,3 +139,26 @@ def read_disk(self):
136139
if line.startswith("/"):
137140
tmp.append(line.rstrip())
138141
print disks
142+
143+
def read_temp(self):
144+
data = []
145+
chandata = []
146+
temp = open("/sys/class/thermal/thermal_zone0/temp", "r")
147+
lines = temp.readlines()
148+
temp.close()
149+
temp_string = lines[0]
150+
logging.debug("CPUTemp Debug message: Temperature from file: %s" % temp_string)
151+
temp_c = float(temp_string) / 1000.0
152+
logging.debug("CPUTemp Debug message: Temperature after calculations:: %s" % temp_c)
153+
data.append(temp_c)
154+
for i in range(len(data)):
155+
chandata.append({"name": "CPU Temperature",
156+
"mode": "float",
157+
"unit": "Custom",
158+
"customunit": "C",
159+
"LimitMode": 1,
160+
"LimitMaxError": 40,
161+
"LimitMaxWarning": 35,
162+
"value": float(data[i])})
163+
return chandata
164+

0 commit comments

Comments
 (0)