From 530bef16bb092d76d38c899de29e4db6dbc552a2 Mon Sep 17 00:00:00 2001 From: Michael Nairn Date: Thu, 8 Sep 2016 11:46:17 +0100 Subject: [PATCH 1/2] RHMAP-10068 - Add helper script to force a check of all services. --- Dockerfile | 1 + scripts/host-svc-check | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100755 scripts/host-svc-check diff --git a/Dockerfile b/Dockerfile index 896bc4b..546f421 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,7 @@ RUN yum install -y epel-release && \ COPY supervisord.conf /etc/supervisord.conf COPY make-nagios-fhservices-cfg make-nagios-commands-cfg fhservices.cfg.j2 commands.cfg.j2 /opt/rhmap/ COPY plugins/default/ /opt/rhmap/nagios/plugins/ +COPY scripts/ /opt/rhmap/ RUN chmod -R 755 /opt/rhmap/nagios/plugins/ COPY start /start diff --git a/scripts/host-svc-check b/scripts/host-svc-check new file mode 100755 index 0000000..bbd067b --- /dev/null +++ b/scripts/host-svc-check @@ -0,0 +1,23 @@ +#!/usr/bin/env python +import os +import time + +host = os.getenv('RHMAP_ROUTER_DNS', 'localhost') +nagios_cmd_file = os.getenv('NAGIOS_CMD_FILE', '/var/spool/nagios/cmd/nagios.cmd') + + +# https://old.nagios.org/developerinfo/externalcommands/commandinfo.php?command_id=130 +def force_service_checks(): + print "Forcing service checks on '%s' ..." % (host) + + with open(nagios_cmd_file, "a") as f: + cmd = "[%s] SCHEDULE_FORCED_HOST_SVC_CHECKS;%s;1110741500\n" % (int(time.time()),host) + f.write(cmd) + + print 'Waiting 20s ...' + time.sleep(20) + +force_service_checks() +force_service_checks() + +print 'Done, all service checks should be up to date.' From a4742fc2e67fc43da3bf525db2a633e5c17014c6 Mon Sep 17 00:00:00 2001 From: Michael Nairn Date: Thu, 8 Sep 2016 16:07:44 +0100 Subject: [PATCH 2/2] RHMAP-10225 - Add check-status helper script. Queries the status of the configured hosts 'localhost' services. If any are not in an OK state, it fails with a non 0 exit status. --- scripts/check-status | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 scripts/check-status diff --git a/scripts/check-status b/scripts/check-status new file mode 100755 index 0000000..94b140f --- /dev/null +++ b/scripts/check-status @@ -0,0 +1,35 @@ +#!/usr/bin/env python +import os +import sys +import json +import urllib2 +import base64 + +# Codes returned from the API are different from the normal nagios status codes +# nagios_service_status = {'1' => 'pending', '2' => 'ok', '4' => 'warning', '8' => 'unknown', '16' => 'critical' }; + +host = os.getenv('RHMAP_ROUTER_DNS', 'localhost') +port = os.getenv('NAGIOS_SERVICE_PORT', 8080) +nagios_user = os.getenv('NAGIOS_USER', 'nagiosadmin') +nagios_pass = os.getenv('NAGIOS_PASSWORD', 'password') + +url = 'http://%s:%s/nagios/cgi-bin/statusjson.cgi?query=servicelist' % (host,port) + +request = urllib2.Request(url) +base64string = base64.b64encode('%s:%s' % (nagios_user, nagios_pass)) +request.add_header("Authorization", "Basic %s" % base64string) +resp = urllib2.urlopen(request).read() +data = json.loads(resp) + +exit_status = 0 +if data['data']['servicelist'][host]: + for check, status in data['data']['servicelist'][host].items(): + print 'Service Check: %s, Status Code: %s' % (check, status) + if status != 2: + exit_status = 1 + +else: + print "No service checks defined for host '%s'" % (host) + exit_status = 1 + +sys.exit(exit_status)