Skip to content

Commit

Permalink
Merge pull request #39 from mikenairn/RHMAP-10225_status_helper_scripts
Browse files Browse the repository at this point in the history
Rhmap 10225 status helper scripts
  • Loading branch information
mikenairn authored Sep 9, 2016
2 parents 734347b + a4742fc commit 9d42df2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 35 additions & 0 deletions scripts/check-status
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions scripts/host-svc-check
Original file line number Diff line number Diff line change
@@ -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.'

0 comments on commit 9d42df2

Please sign in to comment.