forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_elasticsearch.pl
executable file
·86 lines (69 loc) · 2.67 KB
/
check_elasticsearch.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
#!/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, 1.2.1, 1.3.0, 1.4.0, 1.4.4";
$VERSION = "0.3";
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,
"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);
$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;