forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_elasticsearch_cluster.pl
executable file
·117 lines (95 loc) · 4.81 KB
/
check_elasticsearch_cluster.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2013-06-03 21:43:25 +0100 (Mon, 03 Jun 2013)
#
# http://github.com/harisekhon
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check ElasticSearch cluster status, node and shard counts
Tested on ElasticSearch 0.90.1 and 1.2.1";
$VERSION = "0.1";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use HariSekhon::ElasticSearch;
my $cluster_name_regex;
my $node_thresholds;
my $data_node_thresholds;
my $active_primary_shard_thresholds;
my $active_shard_thresholds;
my $relocating_shard_thresholds;
my $initializing_shard_thresholds;
my $unassigned_shard_thresholds = "0,1";
%options = (
%hostoptions,
"C|cluster-name=s" => [ \$cluster_name_regex, "Cluster name to expect (optional). Cluster name is used for auto-discovery and should be unique to each cluster in a single network" ],
"n|nodes=s" => [ \$node_thresholds, "Node thresholds (inclusive, optional)" ],
"d|data-nodes=s" => [ \$data_node_thresholds, "Data Node thresholds (inclusive, optional)" ],
"active-primary-shards=s" => [ \$active_primary_shard_thresholds, "Active Primary Shards thresholds (inclusive, optional)" ],
"active-shards=s" => [ \$active_shard_thresholds, "Active Shards thresholds (inclusive, optional)" ],
"relocating-shards=s" => [ \$relocating_shard_thresholds, "Relocating Shards thresholds (inclusive, optional)" ],
"initializing-shards=s" => [ \$initializing_shard_thresholds, "Initializing Shards thresholds (inclusive, optional)" ],
"unassigned-shards=s" => [ \$unassigned_shard_thresholds, "Unassigned Shards thresholds (inclusive, default w,c: 0,1)" ],
);
splice @usage_order, 4, 0, qw/cluster-name nodes data-nodes active-primary-shards active-shards relocating-shards initializing-shards unassigned-shards/;
get_options();
$host = validate_host($host);
$port = validate_port($port);
$cluster_name_regex = validate_regex($cluster_name_regex, "cluster name") if defined($cluster_name_regex);
my $options_upper = { "simple" => "upper", "integer" => 1, "positive" => 1 };
my $options_lower = { "simple" => "lower", "integer" => 1, "positive" => 1 };
validate_thresholds(undef, undef, $options_lower, "nodes", $node_thresholds);
validate_thresholds(undef, undef, $options_lower, "data nodes", $data_node_thresholds);
validate_thresholds(undef, undef, $options_upper, "active primary shards", $active_primary_shard_thresholds);
validate_thresholds(undef, undef, $options_upper, "active shards", $active_shard_thresholds);
validate_thresholds(undef, undef, $options_upper, "relocating shards", $relocating_shard_thresholds);
validate_thresholds(undef, undef, $options_upper, "initializing shards", $initializing_shard_thresholds);
validate_thresholds(undef, 1, $options_upper, "unassigned shards", $unassigned_shard_thresholds);
vlog2;
set_timeout();
$status = "OK";
$json = curl_elasticsearch "/_cluster/health";
my $cluster_name = get_field("cluster_name");
$msg .= "cluster name: '$cluster_name'";
check_regex($cluster_name, $cluster_name_regex);
my $elasticsearch_status = get_field("status");
$msg .= ", status: '$elasticsearch_status'";
if($elasticsearch_status eq "yellow"){
warning;
$msg .= " (expected: 'green')";
} else {
check_string($elasticsearch_status, "green");
}
my $timed_out = get_field("timed_out");
$timed_out = ( $timed_out ? "true" : "false" );
$msg .= ", timed out: $timed_out";
check_string($timed_out, "false");
my $nodes = get_field_int("number_of_nodes");
$msg .= ", nodes: $nodes";
check_thresholds($nodes, 0, "nodes");
my $data_nodes = get_field_int("number_of_data_nodes");
$msg .= ", data nodes: $data_nodes";
check_thresholds($data_nodes, 0, "data nodes");
my $active_primary_shards = get_field_int("active_primary_shards");
$msg .= ", active primary shards: $active_primary_shards";
check_thresholds($active_primary_shards, 0, "active primary shards");
my $active_shards = get_field_int("active_shards");
$msg .= ", active shards: $active_shards";
check_thresholds($active_shards, 0, "active shards");
my $relocating_shards = get_field_int("relocating_shards");
$msg .= ", relocating shards: $relocating_shards";
check_thresholds($relocating_shards, 0, "relocating shards");
my $initializing_shards = get_field_int("initializing_shards");
$msg .= ", inititializing shards: $initializing_shards";
check_thresholds($initializing_shards, 0, "initializing shards");
my $unassigned_shards = get_field_int("unassigned_shards");
$msg .= ", unassigned shards: $unassigned_shards";
check_thresholds($unassigned_shards, 0, "unassigned shards");
quit $status, $msg;