#!/usr/bin/env python# nagios plugin to check status of kibana cluster health# https://bitbucket.org/snippets/edel/nKAgo/nagios-check-plugin-for-kibana-cluster# Edelberto Mania <ed@zenoradio.com># 20160504endpoint_title="Kibana Cluster Health"ok=0warning=1critical=2importos,sys,requestsfromtimeitimporttimeit## on version python2, we sometimes encounter 'InsecurePlatformWarning'## uncomment below to disable the warning#if sys.version[0]=='2':# import requests.packages.urllib3# requests.packages.urllib3.disable_warnings()iflen(sys.argv)<2:print("usage: {0} KIBANA_ADDRESS:PORT".format(sys.argv[0]))sys.exit(critical)endpoint="http://{0}/_cluster/health".format(sys.argv[1])defquery_health():try:p=requests.get(endpoint)exceptException,e:msg='ERROR: {0}'.format(e)return(critical,e,msg)try:d=p.json()except:msg='Server output not understood'return(critical,None,msg)ifp.status_code!=requests.codes.ok:msg='ERROR: Server returns "{0}"'.format(p.status_code)return(critical,e,msg)iftype(d).__name__=='dict':status=d['status']msg='Cluster "{0}" is {1}'.format(d['cluster_name'],d['status'].upper())ifstatus!='green':msg='Cluster "{0}" is {1}'.format(d['cluster_name'],d['status'].upper())return(critical,d,msg)return(ok,d,msg)if__name__=='__main__':ret=query_health()print("{0}".format(ret[2]))sys.exit(ret[0])
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.