add support for monitoring the plc servers and api
[monitor.git] / nagios / plugins / checkplc.py
1 #!/usr/bin/python
2
3 from optparse import OptionParser
4
5 import plc
6 import auth
7 import sys
8 import time
9
10 parser = OptionParser()
11 parser.add_option("-H", "--hostname", dest="hostname", help="Check API at given hostname.")
12 parser.add_option("-s", "--seconds", dest="seconds", type="int", default=60, help="Number of seconds for a slow reply.")
13 (options, args) = parser.parse_args()
14
15 server = "https://" + options.hostname + "/PLCAPI/"
16 api = plc.PLC(auth.auth, server)
17
18 try:
19     t1 = time.time()
20     for f in ['GetNodes', 'GetSites', 'GetSlices']:
21         m = api.__getattr__(f)
22         n = m({'peer_id' : None, '-LIMIT' : 25})
23         if len(n) < 10:
24             print "CRITICAL: Failure: API returned too few responses"
25             sys.exit(2)
26     t2 = time.time()
27
28     if t2-t1 > options.seconds:
29         print "WARNING: API returned responses in less than %s seconds" % options.seconds
30         sys.exit(1)
31             
32     print "API test successful"
33     sys.exit(0)
34 except Exception, e:
35     print "CRITICAL: Failure: %s" % str(e)
36     sys.exit(2)