Skip to content

Commit

Permalink
Merge pull request #41 from mikenairn/RHMAP-10225_helper_script_impro…
Browse files Browse the repository at this point in the history
…vements

RHMAP-10225 - Updated host-svc-check helper script
  • Loading branch information
mikenairn authored Sep 16, 2016
2 parents c830b8f + bfedb7e commit bb53b9d
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions scripts/host-svc-check
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.'

0 comments on commit bb53b9d

Please sign in to comment.