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

Added parameters to check for a minimum number of shards and indices #41

Open
wants to merge 2 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ Options:
Issue a warning if the number of master-eligible nodes
in the cluster drops below this number. By default,
do not monitor the number of nodes in the cluster.
-s MIN_SHARDS, --min-shards=MIN_SHARDS
Issue a warning if the number of master-eligible
shards in the cluster drops below this number. By
default, do not monitor the number of shards in the
cluster.
-i MIN_INDICES, --min-indices=MIN_INDICES
Issue a warning if the number of master-eligible
indices in the cluster drops below this number. By
default, do not monitor the number of indices in the
cluster.
-p PORT, --port=PORT TCP port to probe. The ElasticSearch API should be
listening here. Defaults to 9200.
-y YELLOW_CRITICAL, --yellow-critical=TRUE
Expand Down
63 changes: 62 additions & 1 deletion check_elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ class ElasticSearchCheck(NagiosCheck):
"number. By default, do not monitor the "
"number of nodes in the cluster.")

self.add_option('s', 'min-shards', 'min_shards',
"Issue a warning if the number of master-eligible "
"shards in the cluster drops below this number. "
"By default, do not monitor the number of shards "
"in the cluster.")

self.add_option('i', 'min-indices', 'min_indices',
"Issue a warning if the number of master-eligible "
"indices in the cluster drops below this number. "
"By default, do not monitor the number of indices "
"in the cluster.")

self.add_option('p', 'port', 'port',
"TCP port to probe. "
"The ElasticSearch API should be listening "
Expand All @@ -90,14 +102,17 @@ class ElasticSearchCheck(NagiosCheck):
"ElasticSearch API. Defaults to ''.")

self.add_option('y', 'yellow-critical', 'yellow_critical',
"Have plugin issue critical alert on yellow cluster state. Defaults to False.")
"Have plugin issue critical alert on yellow cluster "
"state. Defaults to False.")

def check(self, opts, args):
host = opts.host or "localhost"
port = int(opts.port or '9200')
prefix = opts.prefix or ""
if not prefix.endswith('/'):
prefix += '/'
min_shards = opts.min_shards or ""
min_indices = opts.min_indices or ""

failure_domain = []

Expand All @@ -114,6 +129,24 @@ class ElasticSearchCheck(NagiosCheck):
raise UsageError("Argument to -m/--master-nodes must "
"be a natural number")

if opts.min_shards is not None:
try:
if int(opts.min_shards) < 1:
raise ValueError("'min_shards' must be greater "
"than zero")
except ValueError:
raise UsageError("Argument to -s/--min-shards must "
"be a natural number")

if opts.min_indices is not None:
try:
if int(opts.min_indices) < 1:
raise ValueError("'min_indices' must be greater "
"than zero")
except ValueError:
raise UsageError("Argument to -i/--min-indices must "
"be a natural number")

yellow_critical = opts.yellow_critical and opts.yellow_critical.lower() not in ('f', 'false', 'n', 'no')
if yellow_critical:
HEALTH_MAP[1] = 'critical'
Expand Down Expand Up @@ -495,6 +528,34 @@ class ElasticSearchCheck(NagiosCheck):
if downgraded:
msg = ("Missing master-eligible nodes")

# Assertion: You have as many master-eligible shards in the
# cluster as you think you ought to.
downgraded = False

if opts.min_shards is not None:
if n_shards < int(opts.min_shards):
downgraded |= self.downgrade_health(YELLOW)
detail.append("Expected to find %d master-eligible "
"shards in the cluster but only found %d" %
(int(opts.min_shards), n_shards))

if downgraded:
msg = ("Missing some shards")

# Assertion: You have as many master-eligible indices in the
# cluster as you think you ought to.
downgraded = False

if opts.min_indices is not None:
if n_indices < int(opts.min_indices):
downgraded |= self.downgrade_health(YELLOW)
detail.append("Expected to find %d master-eligible "
"indices in the cluster but only found %d" %
(int(opts.min_indices), n_indices))

if downgraded:
msg = ("Missing some indices")

# Assertion: Replicas are not stored in the same failure domain
# as their primary.
downgraded = False
Expand Down