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
|
#!/usr/bin/python
import os, sys, time
import rrdtool
from rrdui import *
def readItemValue(host, community, oid):
cmd = "snmpget -c %s -Ov -OQ -v 2c %s %s" % (community, host, oid)
p = os.popen(cmd, "r")
out = p.read()
(pid, status) = os.wait()
status = status >> 8
try:
p.close()
except IOError:
pass
if status != 0:
print "Couldn't query %s for %s" % (host, oid) # XXXXXX
out = "U"
return out.strip()
def updateItems(graphs):
for item in graphs:
if not os.path.exists(item.filedata):
continue
(fields, interval) = item.getPollingInfo()
values = {}
for fieldname in fields.keys():
info = fields[fieldname].split(":")
if len(info) != 4:
raise "Bad src format" # XXXXXXXXX
if info[0] != "SNMP":
raise "Unknown src method: %s" % info[0] # XXXXXXXXX
value = readItemValue(host = info[1], community = info[2], oid = info[3])
values[fieldname] = value
print ":".join(values.keys()), ":".join(values.values())
args = [item.filedata, "--template", ":".join(values.keys()),
"N:%s" % ":".join(values.values())]
rrdtool.update(*args)
graphs = loadGraphs()
while True:
updateItems(graphs)
# TODO: Work out the interval stuff. for now all at 10 seconds
time.sleep(10)
|