forked from inuits/monitoring-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_elasticsearch_nodes.pl
72 lines (57 loc) · 1.87 KB
/
check_elasticsearch_nodes.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2013-06-03 21:43:25 +0100 (Mon, 03 Jun 2013)
#
# https://github.com/harisekhon/nagios-plugins
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check the number of Elasticsearch nodes available in a cluster
Thresholds apply by default to minimum number of nodes, but also accepts Nagios range thresholds
Tested on Elasticsearch 0.90, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 2.0, 2.1, 2.2, 2.3, 2.4, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6";
$VERSION = "0.4.0";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use HariSekhon::Elasticsearch;
$ua->agent("Hari Sekhon $progname version $main::VERSION");
set_threshold_defaults(2, 1);
my $cluster;
%options = (
%hostoptions,
%useroptions,
%ssloptions,
"C|cluster-name=s" => [ \$cluster, "Cluster name to expect (optional). Cluster name is used for auto-discovery and should be unique to each cluster in a single network" ],
%thresholdoptions,
);
splice @usage_order, 6, 0, qw/cluster-name/;
get_options();
$host = validate_host($host);
$port = validate_port($port);
if($password){
$user = validate_user($user);
$password = validate_password($password);
}
$cluster = validate_elasticsearch_cluster($cluster) if defined($cluster);
validate_thresholds(1, 1, { 'simple' => 'lower', 'positive' => 1, 'integer' => 1});
vlog2;
set_timeout();
$status = "OK";
$json = curl_elasticsearch "/_cluster/health";
my $nodes = get_field_int("number_of_nodes");
plural $nodes;
$msg .= "$nodes node$plural";
check_thresholds($nodes);
my $cluster_name = get_field("cluster_name");
$msg .= " in elasticsearch cluster '$cluster_name'";
check_string($cluster_name, $cluster);
$msg .= " | nodes=$nodes";
msg_perf_thresholds(0, 1);
vlog2;
quit $status, $msg;