]> git.michaelhowe.org Git - packages/n/nagios-plugins-local.git/commitdiff
New plugin: check_monit
authorMichael Howe <michael@michaelhowe.org>
Thu, 9 Nov 2017 21:40:33 +0000 (21:40 +0000)
committerMichael Howe <michael@michaelhowe.org>
Thu, 9 Nov 2017 21:40:33 +0000 (21:40 +0000)
This will be run on clients, and will check whether monit is happy

debian/changelog
debian/nagios-plugins-local-client.install
plugins/check_monit [new file with mode: 0755]

index a4daee4d696a15e4832928a6c31af3b12708c469..7bd471b893b80bd110a97ce92b801e36842be533 100644 (file)
@@ -1,7 +1,9 @@
-nagios-plugins-local (0.15~test.0) UNRELEASED; urgency=medium
+nagios-plugins-local (0.15~test.1) UNRELEASED; urgency=medium
 
   * check_md_raid:
     - strip trailing spaces from mdadm state 
+  * nagios-plugins-local-client:
+    - new plugin: check_monit
 
  -- Michael Howe <michael.howe@it.ox.ac.uk>  Wed, 06 Sep 2017 19:00:00 +0100
 
index dba27fe05a2bec0254aefa38244c38eb2e2879cc..f845d3628bae418739290c8bcfc24f64ba34ff87 100644 (file)
@@ -1,5 +1,6 @@
 /usr/lib/nagios/plugins/check_cert
 /usr/lib/nagios/plugins/check_configtool
 /usr/lib/nagios/plugins/check_md_raid
+/usr/lib/nagios/plugins/check_monit
 /usr/lib/nagios/plugins/check_iostat
 /usr/lib/nagios/plugins/check_systemd
diff --git a/plugins/check_monit b/plugins/check_monit
new file mode 100755 (executable)
index 0000000..362d2fd
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+# from https://gist.github.com/mzupan/2911557
+
+import urllib2
+import base64
+import sys
+import optparse
+
+from xml.dom.minidom import parseString
+
+
+p = optparse.OptionParser(conflict_handler="resolve", description= "This Nagios plugin checks monit services if they are actively monitoring.")
+p.add_option('-H', '--host', action='store', type='string', dest='host', default='127.0.0.1', help='The hostname you want to connect to')
+p.add_option('-P', '--port', action='store', type='string', dest='port', default='2812', help='The port you want to connect to')
+p.add_option('-u', '--user', action='store', type='string', dest='user', default='', help='The username to auth as')
+p.add_option('-p', '--passwd', action='store', type='string', dest='passwd', default='', help='The password to use for the user')
+options, arguments = p.parse_args()
+
+
+
+request = urllib2.Request("http://%s:%s/_status?format=xml" % (options.host, options.port))
+base64string = base64.encodestring('%s:%s' % (options.user, options.passwd)).replace('\n', '')
+request.add_header("Authorization", "Basic %s" % base64string)   
+result = urllib2.urlopen(request)
+
+dom = parseString("".join(result.readlines()))
+for service in dom.getElementsByTagName('service'):
+    name = service.getElementsByTagName('name')[0].firstChild.data
+    monitor = int(service.getElementsByTagName('monitor')[0].firstChild.data)
+
+    if monitor == 0:
+        print "%s not monitored" % name
+        sys.exit(2)
+
+
+print "Everything being monitored"
+sys.exit(0)