Snippets

Edel SM Nagios check plugin for Kibana cluster

Created by Edelberto Mania last modified
#!/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>
# 20160504

endpoint_title="Kibana Cluster Health"
ok=0
warning=1
critical=2

import os,sys,requests
from timeit import timeit

## 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()

if len(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])

def query_health():
	try:p=requests.get(endpoint)
	except Exception,e:
		msg='ERROR: {0}'.format(e)
		return(critical,e,msg)
	try:d=p.json()
	except:
		msg='Server output not understood'
		return(critical,None,msg)
	if p.status_code!=requests.codes.ok:
		msg='ERROR: Server returns "{0}"'.format(p.status_code)
		return(critical,e,msg)
	if type(d).__name__=='dict':
		status=d['status']
		msg='Cluster "{0}" is {1}'.format(d['cluster_name'],d['status'].upper())
		if status!='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)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.