Skip to content

Commit 17236c2

Browse files
committed
Initial creation of the check_es_nodes script. This also has a requirements and also a setup.py
0 parents  commit 17236c2

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
dist/
3+
venv/
4+
nagios_elasticsearch.egg-info/

check_es_nodes.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/python
2+
from nagioscheck import NagiosCheck, UsageError
3+
from nagioscheck import PerformanceMetric, Status
4+
import urllib2
5+
import optparse
6+
7+
try:
8+
import json
9+
except ImportError:
10+
import simplejson as json
11+
12+
parser = optparse.OptionParser()
13+
parser.add_option('-E','--expected_nodes_in_cluster', dest='nodes_in_cluster')
14+
parser.add_option('-H','--host', dest='host')
15+
parser.add_option('-P','--port', dest='port')
16+
(opts, args) = parser.parse_args()
17+
18+
mandatories = ['nodes_in_cluster', 'host']
19+
for m in mandatories:
20+
if not opts.__dict__[m]:
21+
print "mandatory parameter is missing\n"
22+
exit(-1)
23+
24+
def get_json(uri):
25+
try:
26+
response = urllib2.urlopen(uri)
27+
except urllib2.HTTPError, e:
28+
raise Status('unknown', ("API failure", None, "API failure:\n\n%s" % str(e)))
29+
except urllib2.URLError, e:
30+
raise Status('critical', (e.reason))
31+
32+
response_body = response.read()
33+
34+
try:
35+
json_rep = json.loads(response_body)
36+
except ValueError:
37+
raise Status('unknown', ("API returned nonsense",))
38+
39+
return json_rep
40+
41+
def main():
42+
host = opts.host
43+
port = int(opts.port or '9200')
44+
nodes_in_cluster = int(opts.nodes_in_cluster)
45+
46+
es_cluster_health = get_json(r'http://%s:%d/_cluster/health' %(host, port))
47+
48+
active_cluster_nodes = es_cluster_health['number_of_nodes']
49+
50+
if active_cluster_nodes != nodes_in_cluster:
51+
raise Status('CRITICAL', "The number of nodes in the cluster is not '%s'" %es_cluster_health['number_of_nodes'])
52+
else:
53+
raise Status('OK', "The number of nodes in the clust is good")
54+
55+
if __name__ == "__main__":main()

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nagioscheck==0.1.6
2+
setuptools>=3.4.0
3+
pip>=1.4

setup.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from setuptools import setup, find_packages
2+
from pip.req import parse_requirements
3+
4+
setup(
5+
name="nagios-elasticsearch",
6+
description="A selection of Nagios plugins to monitor ElasticSearch",
7+
version="0.1.0",
8+
packages=find_packages(),
9+
url="https://github.com/anchor/nagios-plugin-elasticsearch",
10+
scripts=["check_es_nodes.py"],
11+
license="MIT",
12+
install_requires=[str(req.req) for req in
13+
parse_requirements("requirements.txt")],
14+
include_package_data=True
15+
)

0 commit comments

Comments
 (0)