-
Notifications
You must be signed in to change notification settings - Fork 57
/
check_elasticsearch_cluster_status.pl
71 lines (56 loc) · 1.78 KB
/
check_elasticsearch_cluster_status.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
#!/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 Elasticsearch cluster status with explanation of green / warning / red state in verbose mode
Optional check on cluster name is included.
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.3.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");
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" ],
);
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);
vlog2;
set_timeout();
$status = "OK";
$json = curl_elasticsearch "/_cluster/health";
my $cluster_name = get_field("cluster_name");
$msg .= "cluster name: '$cluster_name'";
check_string($cluster_name, $cluster);
$msg .= check_elasticsearch_status(get_field("status"));
my $timed_out = get_field("timed_out");
#$timed_out = ( $timed_out ? "true" : "false" );
if($timed_out){
critical;
$msg .= ", TIMED OUT: TRUE";
#check_string($timed_out, "false");
}
vlog2;
quit $status, $msg;