add support for monitoring the plc servers and api
[monitor.git] / nagios / plugins / checkplc.py
diff --git a/nagios/plugins/checkplc.py b/nagios/plugins/checkplc.py
new file mode 100755 (executable)
index 0000000..55f8adf
--- /dev/null
@@ -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)