creation
[infrastructure.git] / nagios / plugin / check_planetlab.py
diff --git a/nagios/plugin/check_planetlab.py b/nagios/plugin/check_planetlab.py
new file mode 100755 (executable)
index 0000000..02fd473
--- /dev/null
@@ -0,0 +1,97 @@
+#!/usr/bin/env python
+
+#
+# This script is a nagios plugin that allows to check for a host
+#
+
+import sys
+import getopt
+
+import nagios
+import comon_query
+import comon_sensor
+
+command=sys.argv[0]
+revision="$Revision: 1.3 $"
+
+#nagios_plugins_dir="/usr/lib/nagios/plugins"
+
+
+options = 'vhnk:t:'
+long_opts = [ 'version' , 'help', 'no-comon' , 'key=', 'time-out=' ]
+
+
+usage_string="""Usage : %s [-n] [-k private_key] nodename
+Revision %s
+This nagios plugin checks for a given (planetlab) host
+The regular approach is to
+* First try to reach the comon query interface.
+  default host is %s
+  this can be overridden with the --host option (NIY)
+TODO : prevent this stage if a 'none' host is provided
+* If we cannot conclude from this, we then try and reach
+  the comon sensor on the node itself on port %d, 
+TODO : skip on -n option
+* Then, if an ssh private key is provided with the -k option,
+  we try to enter the node as root and check that
+  the pl_conf slice is up and running on the node
+TODO : do this only of the -k option is provided
+* if none of this is conclusive we just check for the ssh server on the node
+  with the standard ssh plugin
+TODO : probably this should be left to the nagios config
+"""%(command,revision,comon_query.SERVER,comon_sensor.PORT)
+
+def usage ():
+    print usage_string
+    sys.exit(1)
+
+####################
+def main ():
+
+    try:
+        opts,args = getopt.getopt(sys.argv[1:], options, long_opts)
+    except getopt.GetoptError:
+        print "Unknown option"
+        usage()
+
+    opt_comon = True
+    opt_key = None
+    opt_timeout = 10
+
+    for o,a in opts:
+        if o in ['-v','--version']:
+            print command,'--',revision
+            sys.exit(3)
+        elif o in ['-h','--help']:
+            usage()
+        elif o in ['-n','--no-comon']:
+            opt_comon = False            
+        elif o in ['-k','--key']:
+            opt_key=a
+        elif o in ['-t','--time-out']:
+            opt_timeout=int(a)
+        else:
+            print "Unknown option",o
+            usage()
+
+    if not len(args) == 1:
+        usage()
+    nodename = args[0]
+
+    status = nagios.UNKNOWN
+
+    status = comon_query.check(nodename)
+    if status != nagios.UNKNOWN:
+        return status
+    
+    if opt_comon:
+        status = comon_sensor.check(nodename,opt_timeout)
+
+#    print "status",status
+    return status
+
+
+if __name__=='__main__':
+    sys.exit(main())
+        
+