Created
November 19, 2015 07:23
-
-
Save viviandarkbloom/6bd06bd8fdb479d32e3f to your computer and use it in GitHub Desktop.
for nagios
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/python | |
import sys | |
import json | |
import requests | |
from NagAconda import Plugin | |
__description__ = 'Check Elasticsearch shard info' | |
__url__ = 'https://gerrit.ctgrd.com/#/admin/projects/puppet-modules' | |
__version__ = '1.0.0' | |
def get_cluster_status(url, shard): | |
try: | |
r = requests.get(url) | |
except requests.exceptions.HTTPError: | |
print 'CRITICAL: Unable to connect to %s' %url | |
j = r.json() | |
cluster_status = j['status'] | |
return j[shard] | |
def main(): | |
''' Nagaconda to take care of the actual nagios logic. ''' | |
plugin = Plugin(__description__, __version__) | |
plugin.add_option('H', 'host', 'Server to check', required=True) | |
plugin.add_option('o', 'shard_option', 'type of shard count to check', required=True) | |
plugin.enable_status('warning') | |
plugin.enable_status('critical') | |
plugin.start() | |
url = 'http://%s:9200/_cluster/health' % plugin.options.host | |
shard_count = get_cluster_status(url, plugin.options.shard_option) | |
plugin.set_value('count', shard_count) | |
plugin.set_status_message('%s on %s : %i' % | |
(plugin.options.shard_option, plugin.options.host, shard_count)) | |
plugin.finish() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment