-
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 #41 from mikenairn/RHMAP-10225_helper_script_impro…
…vements RHMAP-10225 - Updated host-svc-check helper script
- Loading branch information
Showing
1 changed file
with
23 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,40 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import time | ||
import argparse | ||
|
||
host = os.getenv('RHMAP_ROUTER_DNS', 'localhost') | ||
nagios_cmd_file = os.getenv('NAGIOS_CMD_FILE', '/var/spool/nagios/cmd/nagios.cmd') | ||
|
||
|
||
def generate_parser(): | ||
parser = argparse.ArgumentParser( | ||
description="Schedule a forced check of all services on this host", | ||
) | ||
parser.add_argument( | ||
"--times", type=int, default=2, | ||
help="Number of times to schedule a forced check", | ||
) | ||
parser.add_argument( | ||
"--delay", type=int, default=20, | ||
help="Time in seconds to delay after each call to force the checks", | ||
) | ||
return parser | ||
|
||
# https://old.nagios.org/developerinfo/externalcommands/commandinfo.php?command_id=130 | ||
def force_service_checks(): | ||
print "Forcing service checks on '%s' ..." % (host) | ||
def force_service_checks(count, total, delay): | ||
print "Forcing service checks on '%s' (%s/%s) ..." % (host, count, total) | ||
|
||
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) | ||
print 'Waiting %ss ...' % (delay) | ||
time.sleep(delay) | ||
|
||
args = generate_parser().parse_args() | ||
|
||
force_service_checks() | ||
force_service_checks() | ||
for i in range(args.times): | ||
force_service_checks(i + 1, args.times, args.delay) | ||
|
||
print 'Done, all service checks should be up to date.' |