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 authentication options #6

Open
wants to merge 1 commit 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
14 changes: 12 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,23 @@ 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 for authentication')
self.add_option('p', 'password', 'password', 'password for authentication')

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 = r'http://%s:%d/_cluster/health' % (host, port)
request = urllib2.Request(url)
if username is not None and password is not None:
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib2.urlopen(request)

except urllib2.HTTPError, e:
raise Status('unknown', ("API failure", None,
"API failure:\n\n%s" % str(e)))
Expand Down
14 changes: 12 additions & 2 deletions check_es_jvm_usage.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,6 +19,8 @@ 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 for authentication')
self.add_option('p', 'password', 'password', 'password for authentication')
self.add_option('C', 'critical_threshold', 'critical_threshold',
'The level at which we throw a CRITICAL alert'
' - defaults to 97% of the JVM setting')
Expand All @@ -28,12 +31,19 @@ def __init__(self):
def check(self, opts, args):
host = opts.host
port = int(opts.port or '9200')
username = opts.username
password = opts.password
critical = int(opts.critical_threshold or '97')
warning = int(opts.warning_threshold or '90')

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

except urllib2.HTTPError, e:
raise Status('unknown', ("API failure", None,
"API failure:\n\n%s" % str(e)))
Expand Down
14 changes: 12 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,24 @@ 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 for authentication')
self.add_option('p', 'password', 'password', 'password for authentication')

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

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

except urllib2.HTTPError, e:
raise Status('unknown', ("API failure", None, "API failure:\n\n%s"
% str(e)))
Expand Down
14 changes: 11 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,26 @@ 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 for authentication')
self.add_option('p', 'password', 'password', 'password for authentication')

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 = r'http://%s:%d/_cluster/state/nodes,master_node/' % (node, port)
request = urllib2.Request(url)
if username is not None and password is not None:
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib2.urlopen(request)
response_body = response.read()
response = json.loads(response_body)
except (urllib2.HTTPError, urllib2.URLError), e:
Expand Down
14 changes: 12 additions & 2 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,23 @@ 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 for authentication')
self.add_option('p', 'password', 'password', 'password for authentication')

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 = r'http://%s:%d/_cluster/health' % (host, port)
request = urllib2.Request(url)
if username is not None and password is not None:
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib2.urlopen(request)

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