add external commands as stubs for the nagios plugins
[monitor.git] / commands / checkpcu.py
1 #!/usr/bin/python
2
3 import time
4 import sys
5 import os
6
7 from monitor.wrapper import plc
8
9 def argv_to_dict(argv):
10         """
11                 NOTE: very bare-bones, no error checking, will fail easily.
12         """
13         d = {}
14         prev=None
15         for a in argv:
16                 if "--" == a[0:2]:
17                         prev = a[2:]
18                 elif "-" == a[0:1]:
19                         prev = a[1:]
20                 else:
21                         d[prev] = a
22         return d
23
24 def main():
25         d = argv_to_dict(sys.argv[1:])
26
27         api = plc.api
28         if 'hostname' in d or 'H' in d:
29                 try:
30                         hostname = d['host']
31                 except:
32                         hostname = d['H']
33         else:
34                 print "UNKNOWN: argument error"
35                 sys.exit(3)
36
37         try:
38                 n = api.GetNodes(hostname)[0]
39         except:
40                 print "UNKNOWN: API failure"
41                 sys.exit(3)
42
43         t1 = 0
44         t2 = time.time()
45
46         if True:
47                 print "FAKE-OK: PCU test successful"
48                 sys.exit(0)
49         elif False:
50                 print "FAKE-WARNING: PCU configuration incomplete"
51                 sys.exit(1)
52         else:
53                 print "FAKE-CRITICAL: PCU test failed"
54                 sys.exit(2)
55
56
57 if __name__ == '__main__':
58         f = open("/tmp/checkpcu", 'a')
59         f.write("checkpcu %s %s\n" % (time.time(), " ".join(sys.argv[1:])))
60         f.close()
61         main()