Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support to authentication #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ python:
- 2.7

install:
- pip install -r requirements.txt --use-mirrors
- pip install -r requirements.txt
before_script:
- "pep8 ."
script:
Expand Down
12 changes: 10 additions & 2 deletions check_es_cluster_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from nagioscheck import PerformanceMetric, Status
import urllib2
import optparse
import base64

try:
import json
Expand All @@ -18,14 +19,21 @@ def __init__(self):

self.add_option('H', 'host', 'host', 'The cluster to check')
self.add_option('P', 'port', 'port', 'The ES port - defaults to 9200')
self.add_option('u', 'username', 'username', 'username to login into ES port')
self.add_option('p', 'password', 'password', 'password to login into ES port')

def check(self, opts, args):
host = opts.host
port = int(opts.port or '9200')
username = opts.username
password = opts.password

try:
response = urllib2.urlopen(r'http://%s:%d/_cluster/health'
% (host, port))
url=urllib2.Request(r'http://%s:%d/_cluster/health' % (host, port))
if username and password:
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
url.add_header("Authorization","Basic %s" % base64string)
response = urllib2.urlopen(url)
except urllib2.HTTPError, e:
raise Status('unknown', ("API failure", None,
"API failure:\n\n%s" % str(e)))
Expand Down
35 changes: 26 additions & 9 deletions check_es_jvm_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from nagioscheck import PerformanceMetric, Status
import urllib2
import optparse
import base64

try:
import json
except ImportError:
import simplejson as json


class ESJVMHealthCheck(NagiosCheck):

def __init__(self):
Expand All @@ -24,19 +24,27 @@ def __init__(self):
self.add_option('W', 'warning_threshold', 'warning_threshold',
'The level at which we throw a WARNING alert'
' - defaults to 90% of the JVM setting')
self.add_option('u', 'username', 'username', 'username to login into ES port')
self.add_option('p', 'password', 'password', 'password to login into ES port')

def check(self, opts, args):
host = opts.host
port = int(opts.port or '9200')
critical = int(opts.critical_threshold or '97')
warning = int(opts.warning_threshold or '90')
username = opts.username
password = opts.password

try:
response = urllib2.urlopen(r'http://%s:%d/_nodes/stats/jvm'
% (host, port))
url=urllib2.Request(r'http://%s:%d/_nodes/stats/jvm' % (host, port))
if username and password:
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
url.add_header("Authorization","Basic %s" % base64string)
response = urllib2.urlopen(url)

except urllib2.HTTPError, e:
raise Status('unknown', ("API failure", None,
"API failure:\n\n%s" % str(e)))
"API failure: %s" % str(e)))
except urllib2.URLError, e:
raise Status('critical', (e.reason))

Expand All @@ -51,6 +59,7 @@ def check(self, opts, args):
critical_details = []
warnings = 0
warning_details = []
details=[]

nodes = nodes_jvm_data['nodes']
for node in nodes:
Expand All @@ -65,27 +74,35 @@ def check(self, opts, args):
warnings = warnings + 1
warning_details.append("%s currently running at %s%% JVM mem "
% (node_name, jvm_percentage))
else:
details.append("%s have %s%% JVM mem " % (node_name,jvm_percentage))

if criticals > 0:
raise Status("Critical",
"There are '%s' node(s) in the cluster that have "
"breached the %% JVM heap usage critical threshold "
"of %s%%. They are:\r\n%s"
"of %s%%. They are: %s. OK are: %s "
% (
criticals,
critical,
str("\r\n".join(critical_details))
str(" ".join(critical_details)),
str(" " .join(details))
))
elif warnings > 0:
raise Status("Warning",
"There are '%s' node(s) in the cluster that have "
"breached the %% JVM mem usage warning threshold of "
"%s%%. They are:\r\n%s"
"%s%%. They are: %s OK are: %s"
% (warnings, warning,
str("\r\n".join(warning_details))))
str(" ".join(warning_details)),
str(" ".join(details))
))
else:
raise Status("OK", "All nodes in the cluster are currently below "
"the % JVM mem warning threshold")
"the %% JVM mem warning threshold. OK are: %s"
% (
str(" ".join(details))
))

if __name__ == "__main__":
ESJVMHealthCheck().run()
13 changes: 11 additions & 2 deletions check_es_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from nagioscheck import PerformanceMetric, Status
import urllib2
import optparse
import base64

try:
import json
Expand All @@ -20,15 +21,23 @@ def __init__(self):
'This is the expected number of nodes in the cluster')
self.add_option('H', 'host', 'host', 'The cluster to check')
self.add_option('P', 'port', 'port', 'The ES port - defaults to 9200')
self.add_option('u', 'username', 'username', 'username to login into ES port')
self.add_option('p', 'password', 'password', 'password to login into ES port')

def check(self, opts, args):
host = opts.host
port = int(opts.port or '9200')
nodes_in_cluster = int(opts.nodes_in_cluster)
username = opts.username
password = opts.password

try:
response = urllib2.urlopen(r'http://%s:%d/_cluster/health'
% (host, port))
url=urllib2.Request(r'http://%s:%d/_cluster/health' % (host, port))
if username and password:
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
url.add_header("Authorization","Basic %s" % base64string)
response = urllib2.urlopen(url)

except urllib2.HTTPError, e:
raise Status('unknown', ("API failure", None, "API failure:\n\n%s"
% str(e)))
Expand Down
15 changes: 12 additions & 3 deletions check_es_split_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from nagioscheck import PerformanceMetric, Status
import urllib2
import optparse
import base64

try:
import json
Expand All @@ -18,19 +19,27 @@ def __init__(self):

self.add_option('N', 'nodes', 'nodes', 'Cluster nodes')
self.add_option('P', 'port', 'port', 'The ES port - defaults to 9200')
self.add_option('u', 'username', 'username', 'username to login into ES port')
self.add_option('p', 'password', 'password', 'password to login into ES port')

def check(self, opts, args):
nodes = opts.nodes.split(",")
port = int(opts.port or '9200')
username = opts.username
password = opts.password

masters = []
responding_nodes = []
failed_nodes = []

for node in nodes:
try:
response = urllib2.urlopen(
r'http://%s:%d/_cluster/state/nodes,master_node/'
% (node, port))
url=urllib2.Request(r'http://%s:%d/_cluster/state/nodes,master_node/' % (node, port))
if username and password:
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
url.add_header("Authorization","Basic %s" % base64string)
response = urllib2.urlopen(url)

response_body = response.read()
response = json.loads(response_body)
except (urllib2.HTTPError, urllib2.URLError), e:
Expand Down
15 changes: 12 additions & 3 deletions check_es_unassigned_shards.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from nagioscheck import PerformanceMetric, Status
import urllib2
import optparse
import base64

try:
import json
Expand All @@ -18,14 +19,22 @@ def __init__(self):

self.add_option('H', 'host', 'host', 'The cluster to check')
self.add_option('P', 'port', 'port', 'The ES port - defaults to 9200')
self.add_option('u', 'username', 'username', 'username to login into ES port')
self.add_option('p', 'password', 'password', 'password to login into ES port')

def check(self, opts, args):
host = opts.host
port = int(opts.port or '9200')
username = opts.username
password = opts.password

try:
response = urllib2.urlopen(r'http://%s:%d/_cluster/health'
% (host, port))
url=urllib2.Request(r'http://%s:%d/_cluster/health' % (host, port))
if username and password:
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
url.add_header("Authorization","Basic %s" % base64string)
response = urllib2.urlopen(url)

except urllib2.HTTPError, e:
raise Status('unknown', ("API failure", None,
"API failure:\n\n%s" % str(e)))
Expand All @@ -41,7 +50,7 @@ def check(self, opts, args):

unassigned_shards = es_cluster_health['unassigned_shards']

if es_cluster_health['unassigned_shards'] != unassigned_shards:
if unassigned_shards != 0:
raise Status('CRITICAL',
"There are '%s' unassigned shards in the cluster"
% (unassigned_shards))
Expand Down