-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1wire.py
More file actions
executable file
·67 lines (50 loc) · 1.44 KB
/
1wire.py
File metadata and controls
executable file
·67 lines (50 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
import os
from munin import MuninPlugin
BUSPATH = "/sys/bus/w1/devices/"
ALIAS_SUFFIX = "alias_"
class TemperaturePlugin(MuninPlugin):
title = "Temperature"
args = "-l 0"
vlabel = "DegC"
scaled = False
category = "sensors"
def _findSensors(self):
#find the IDs of all sensors on the bus
if not os.path.exists(BUSPATH):
sensors = []
else:
sensors = [f for f in os.listdir(BUSPATH) if os.path.isdir(os.path.join(BUSPATH,f)) and os.path.exists(os.path.join(BUSPATH,f,"w1_slave"))]
#map the alias' to the sensor ID
smap = {}
for s in sensors:
alias = ALIAS_SUFFIX+s[3:] #strip the family ID
if alias in os.environ and not alias in smap.keys():
smap[os.environ[alias]] = s
else:
smap[s] = s
return smap
def _safeName(self, name):
return name.lower().replace(" ","")
@property
def fields(self):
sensors = self._findSensors()
f = []
for name in sensors.keys():
f.append((self._safeName(name),dict(
label = name,
info = "Temperature of "+name,
type = "GAUGE",
min = 0)))
return f
def execute(self):
sensors = self._findSensors()
for name, sensor in sensors.items():
f = open(os.path.join(BUSPATH,sensor,"w1_slave"),"r")
l = f.readlines()
f.close()
temp = int(l[-1].split()[-1].split("=")[-1]) / 1000.0
if temp < 85.0 and "YES" in l[0]:
print "%s.value %.3f" % (self._safeName(name),temp)
if __name__ == "__main__":
TemperaturePlugin().run()