forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_elasticsearch_index_replicas.pl
executable file
·74 lines (57 loc) · 2.09 KB
/
check_elasticsearch_index_replicas.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
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2015-03-21 16:53:17 +0000 (Sat, 21 Mar 2015)
#
# https://github.com/harisekhon/nagios-plugins
#
# License: see accompanying Hari Sekhon LICENSE file
#
# vim:ts=4:sts=4:sw=4:et
$DESCRIPTION = "Nagios Plugin to check the number of replicas of a given Elasticsearch index
Tested on Elasticsearch 1.2.1, 1.4.0, 1.4.4";
$VERSION = "0.7";
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 $expected_replicas = "1,0";
set_threshold_defaults(1,0);
%options = (
%hostoptions,
%elasticsearch_index,
#"R|replicas=s" => [ \$expected_replicas, "Expected replicas (default: w,c = 1,0)" ],
%thresholdoptions,
);
get_options();
$host = validate_host($host);
$port = validate_port($port);
$index = validate_elasticsearch_index($index);
#$expected_replicas = validate_int($expected_replicas, "expected replicas", 0, 1000000) if defined($expected_replicas);
#validate_thresholds(0, 0, { 'simple' => 'lower', 'positive' => 1, 'integer' => 1}, "expected replicas", $expected_replicas);
validate_thresholds(0, 0, { 'simple' => 'lower', 'positive' => 1, 'integer' => 1});
vlog2;
set_timeout();
$status = "OK";
list_elasticsearch_indices();
curl_elasticsearch "/$index/_settings?flat_settings&name=index.number_of_replicas";
# escape any dots in index name to not separate
( my $index2 = $index ) =~ s/\./\\./g;
$msg = "index '$index'";
# switched to flat settings, must escape dots inside the setting now
#my $replicas = get_field_int("$index2.settings.index.number_of_replicas");
my $replicas = get_field_int("$index2.settings.index\\.number_of_replicas");
$msg .= " replicas=$replicas";
#check_string($replicas, $expected_replicas) if defined($expected_replicas);
#check_thresholds($replicas, 0, "expected replicas");
check_thresholds($replicas);
$msg .= " | replicas=$replicas";
#msg_perf_thresholds(0, 'lower', 'expected replicas');
msg_perf_thresholds(0, 'lower');
quit $status, $msg;