Created
March 27, 2012 04:08
-
-
Save SEJeff/2212451 to your computer and use it in GitHub Desktop.
nagios check to make sure the salt minion is available and responding to commands from @bastichelaar
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
#!/usr/bin/env python | |
import salt.cli.caller | |
import salt.config | |
import argparse | |
import sys | |
parser = argparse.ArgumentParser(description='Check if minions are online.') | |
parser.add_argument('hostname', help='The name of the minion to be checked') | |
args = parser.parse_args() | |
hostname = args.hostname | |
opts = salt.config.minion_config("/etc/salt/minion") | |
opts['doc'] = False | |
opts['grains_run'] = False | |
opts['raw_out'] = False | |
opts['json_out'] = True | |
opts['txt_out'] = False | |
opts['yaml_out'] = False | |
opts['color'] = True | |
opts['root_dir'] = None | |
opts['fun'] = "publish.publish" | |
opts['returner'] = None | |
opts['arg'] = (hostname, "test.ping") | |
caller = salt.cli.caller.Caller(opts) | |
result = caller.call() | |
if result.get("return").get(hostname) is True: | |
sys.stdout.write("OK: minion %s is online\n" % hostname) | |
sys.exit(0) | |
else: | |
sys.stderr.write("CRITICAL: minion %s is not online!\n" % hostname) | |
sys.exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm a noob to nagios, python and salt so any help is appreciated. Does this script run on the minion's locally, salt-master or off one of the nagios collectors? I've tried running it on an minion and I get:
Traceback (most recent call last):
File "./check_salt.py", line 2, in ?
import salt.cli.caller
ImportError: No module named salt.cli.caller
salt-master 0.10.2
salt-minion 0.10.2