Skip to content

Instantly share code, notes, and snippets.

@djs52
Created October 13, 2014 10:56
Show Gist options
  • Save djs52/705cd764ac782c1ab461 to your computer and use it in GitHub Desktop.
Save djs52/705cd764ac782c1ab461 to your computer and use it in GitHub Desktop.
Simple Nagios Salt check
#!/usr/bin/env python
import salt.client
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
client = salt.client.LocalClient()
result = client.cmd(hostname, 'test.ping')
if result.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