Created
September 30, 2013 22:56
-
-
Save pandemicsyn/6771509 to your computer and use it in GitHub Desktop.
check_salt_minions
This file contains hidden or 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 sys | |
import json | |
import subprocess | |
import salt.client | |
error = False | |
keycmd = "sudo salt-key -L --out json --no-color --out-indent=-1" | |
out = subprocess.Popen(keycmd.split(), stdout=subprocess.PIPE).communicate()[0] | |
try: | |
result = json.loads(out) | |
keyhosts = result['minions'] | |
except Exception as err: | |
print out | |
print err | |
sys.exit(1) | |
client = salt.client.LocalClient() | |
result = client.cmd('*', 'test.ping') | |
for host in result: | |
if not result[host]: | |
print "%s is failing salt test.ping for some reason!" % host | |
error = True | |
missing = list(set(keyhosts) - set(result.keys())) | |
if missing == 0 and not error: | |
print "Ok - all hosts responded." | |
sys.exit(0) | |
else: | |
if missing == 0: | |
sys.exit(1) | |
else: | |
print "Warning - %d hosts failed to respond:" % len(missing) | |
for i in missing: | |
print i | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment