-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from mikenairn/RHMAP-10225_status_helper_scripts
Rhmap 10225 status helper scripts
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' |