forked from inuits/monitoring-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_elasticsearch_6.pl
89 lines (75 loc) · 2.89 KB
/
check_elasticsearch_6.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
#!/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 a given Elasticsearch node
Checks:
- node is online and returning json with ok 200 status
- optionally check node is a member of the expected cluster
- optionally checks node's Elasticsearch / Lucene versions
- in verbose mode also prints out the generated Marvel node name
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");
my $cluster;
my $es_version_regex;
my $lc_version_regex;
%options = (
%hostoptions,
%useroptions,
%ssloptions,
"C|cluster=s" => [ \$cluster, "Cluster to expect membership of (optional, available from 1.3" ],
"es-version=s" => [ \$es_version_regex, "Elasticsearch version regex to expect (optional)" ],
"lucene-version=s" => [ \$lc_version_regex, "Lucene version regex to expect (optional)" ],
);
splice @usage_order, 6, 0, qw/cluster es-version lucene-version/;
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 $cluster;
$es_version_regex = validate_regex($es_version_regex, "elasticsearch version") if defined($es_version_regex);
$lc_version_regex = validate_regex($lc_version_regex, "lucene version") if defined($lc_version_regex);
vlog2;
set_timeout();
$status = "OK";
$json = curl_elasticsearch "/";
my $elasticsearch_status = get_field("status", "noquit");
if(defined($elasticsearch_status)){
$msg .= "status: '$elasticsearch_status', ";
check_string($elasticsearch_status, 200);
}
my $cluster_name = get_field("cluster_name", 1);
if($cluster_name){
$msg .= "cluster: '$cluster_name', ";
check_string($cluster_name, $cluster) if $cluster;
}
my $node_name = get_field("name", 1);
$msg .= "node name: '$node_name', " if($node_name and $verbose);
my $es_version = get_field2(get_field("version"), "number");
my $lc_version = get_field2(get_field("version"), "lucene_version");
isVersion($es_version) or quit "UNKNOWN", "invalid version returned for elasticsearch";
isVersion($lc_version) or quit "UNKNOWN", "invalid version returned for lucene";
$msg .= "elasticsearch version: $es_version";
check_regex($es_version, $es_version_regex) if $es_version_regex;
$msg .= ", lucene version: $lc_version";
check_regex($lc_version, $lc_version_regex) if $lc_version_regex;
vlog2;
quit $status, $msg;