X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=nagios%2Fplugins%2Fcheckplc.py;fp=nagios%2Fplugins%2Fcheckplc.py;h=55f8adf724d3831ef629ee22428c44878d739581;hb=b409ce051ff5a7180f50bd1f359107acfebd5671;hp=0000000000000000000000000000000000000000;hpb=1021f78d261f1dace74d5af1b464ccc02fbf4182;p=monitor.git diff --git a/nagios/plugins/checkplc.py b/nagios/plugins/checkplc.py new file mode 100755 index 0000000..55f8adf --- /dev/null +++ b/nagios/plugins/checkplc.py @@ -0,0 +1,36 @@ +#!/usr/bin/python + +from optparse import OptionParser + +import plc +import auth +import sys +import time + +parser = OptionParser() +parser.add_option("-H", "--hostname", dest="hostname", help="Check API at given hostname.") +parser.add_option("-s", "--seconds", dest="seconds", type="int", default=60, help="Number of seconds for a slow reply.") +(options, args) = parser.parse_args() + +server = "https://" + options.hostname + "/PLCAPI/" +api = plc.PLC(auth.auth, server) + +try: + t1 = time.time() + for f in ['GetNodes', 'GetSites', 'GetSlices']: + m = api.__getattr__(f) + n = m({'peer_id' : None, '-LIMIT' : 25}) + if len(n) < 10: + print "CRITICAL: Failure: API returned too few responses" + sys.exit(2) + t2 = time.time() + + if t2-t1 > options.seconds: + print "WARNING: API returned responses in less than %s seconds" % options.seconds + sys.exit(1) + + print "API test successful" + sys.exit(0) +except Exception, e: + print "CRITICAL: Failure: %s" % str(e) + sys.exit(2)