forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_elasticsearch_cluster_status.pl
executable file
·67 lines (50 loc) · 1.56 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
#!/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, 1.2.1, 1.4.0, 1.4.4";
$VERSION = "0.2";
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,
"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);
$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;