Skip to content

Instantly share code, notes, and snippets.

@viviandarkbloom
Created November 19, 2015 07:23
Show Gist options
  • Save viviandarkbloom/1095b5a5199e85a632e1 to your computer and use it in GitHub Desktop.
Save viviandarkbloom/1095b5a5199e85a632e1 to your computer and use it in GitHub Desktop.
plugin for nagios
#!/usr/bin/python
import sys
import json
import requests
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-H",
help='name of elasticsearch host' )
args = parser.parse_args()
url = 'http://%s:9200/_cluster/health' %args.H
r = requests.get(url)
j = r.json()
cluster_status = j['status']
name = j['cluster_name']
if cluster_status == "green":
stat = 'OK'
message = 'cluster %s is OK' %name
elif cluster_status == "yellow":
stat = 'WARN'
message = 'cluster %s is WARN' %name
elif cluster_status == "red":
stat = 'CRITICAL'
message = 'cluster %s is CRITICAL' %name
print '%s - %s' % (stat, message)
if stat == 'OK':
raise SystemExit, 0
elif stat == 'WARNING':
raise SystemExit, 1
elif stat == 'CRITICAL':
raise SystemExit, 2
else:
raise SystemExit, 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment