]> git.michaelhowe.org Git - packages/n/nagios-plugins-local.git/commitdiff
Make check_monit more functional
authorMichael Howe <michael@michaelhowe.org>
Sat, 9 Dec 2017 20:41:04 +0000 (20:41 +0000)
committerMichael Howe <michael@michaelhowe.org>
Sat, 9 Dec 2017 20:41:04 +0000 (20:41 +0000)
* handle (one) urllib error
* list which services are unmonitored, rather than just the first

debian/changelog
plugins/check_monit

index 234dcce049405580d5fb9c956b1a21f5bb999ac8..bda9c8ba4906749eb373c8071ca6285d1740efbf 100644 (file)
@@ -1,3 +1,12 @@
+nagios-plugins-local (0.17~test.0) UNRELEASED; urgency=medium
+
+  * check_monit:
+    - improve various aspects:
+      + list all unmonitored services, not just the first
+      + exit with unknown state if can't connect to monit's web interface 
+
+ -- Michael Howe <michael@michaelhowe.org>  Sat, 09 Dec 2017 20:29:00 +0000
+
 nagios-plugins-local (0.16) unstable; urgency=medium
 
   * check_configtool:
index 362d2fdf0c34d2fcc64a193bbd07af254a3bd087..4564d137ba6a89e174609a3a16d871e1fdb49690 100755 (executable)
@@ -18,21 +18,35 @@ p.add_option('-p', '--passwd', action='store', type='string', dest='passwd', def
 options, arguments = p.parse_args()
 
 
-
-request = urllib2.Request("http://%s:%s/_status?format=xml" % (options.host, options.port))
+check_url = "http://%s:%s/_status?format=xml" % (options.host, options.port)
+request = urllib2.Request(check_url)
 base64string = base64.encodestring('%s:%s' % (options.user, options.passwd)).replace('\n', '')
 request.add_header("Authorization", "Basic %s" % base64string)   
-result = urllib2.urlopen(request)
+try:
+    result = urllib2.urlopen(request)
+except urllib2.HTTPError:
+    print "Cannot connect to %s as user '%s'" % (check_url, options.user)
+    sys.exit(3)
 
 dom = parseString("".join(result.readlines()))
+monitored = []
+unmonitored = []
+exitcode = 0
+
 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)
+        unmonitored.append(name)
+    else:
+        monitored.append(name)
+
+if len(unmonitored):
+    print "monit: unmonitored services: %s" % (', '.join(unmonitored))
+    exitcode = 2
+else:
+    print "monit: no unmonitored services"
+    exitcode = 1
+
+sys.exit(exitcode)