From: Michael Howe Date: Thu, 9 Nov 2017 21:40:33 +0000 (+0000) Subject: New plugin: check_monit X-Git-Tag: 0.15~1 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=092c68a58271d0fa7fa07c519ea1de0aa50ce48b;p=packages%2Fn%2Fnagios-plugins-local.git New plugin: check_monit This will be run on clients, and will check whether monit is happy --- diff --git a/debian/changelog b/debian/changelog index a4daee4..7bd471b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Wed, 06 Sep 2017 19:00:00 +0100 diff --git a/debian/nagios-plugins-local-client.install b/debian/nagios-plugins-local-client.install index dba27fe..f845d36 100644 --- a/debian/nagios-plugins-local-client.install +++ b/debian/nagios-plugins-local-client.install @@ -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 index 0000000..362d2fd --- /dev/null +++ b/plugins/check_monit @@ -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)