forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_hadoop_wandisco_node_status.pl
executable file
·118 lines (94 loc) · 3.25 KB
/
check_hadoop_wandisco_node_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
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
118
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2014-03-05 21:45:08 +0000 (Wed, 05 Mar 2014)
#
# http://github.com/harisekhon
#
# License: see accompanying LICENSE file
#
# http://docs.wandisco.com/bigdata/nsnn/1.9h/api.html
$DESCRIPTION = "Nagios Plugin to check the status of a given WANdisco Non-Stop Hadoop node via DConE REST API
Written and tested on Hortonworks HDP 2.1 and WANdisco Non-Stop Hadoop 1.9.8";
$VERSION = "0.1";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use Data::Dumper;
use LWP::Simple '$ua';
use POSIX 'floor';
use XML::Simple;
$ua->agent("Hari Sekhon $progname version $main::VERSION");
set_port_default(50070);
env_creds(["HADOOP_NAMENODE", "HADOOP"], "Hadoop NameNode");
my $node;
%options = (
%hostoptions,
"N|node=s" => [ \$node, "Node to check (must match the WANdisco node name precisely or will get a 404 not found error)" ],
);
get_options();
$host = validate_host($host);
$port = validate_port($port);
# In WANdisco nodes can be called things that wouldn't pass FQDN / IP address tests
usage "node not defined" unless $node;
#$node = validate_host($node, "node");
vlog2;
set_timeout();
$status = "OK";
my $url = "http://$host:$port/dcone/node/$node";
# TODO: add 404 error handler to state WANdisco is not installed or node name is invalid
my $content = curl $url, "NameNode";
# Test sample
#my $content = '<node>
#<nodeIdentity>hdp9</nodeIdentity>
#<locationIdentity>rack5</locationIdentity>
#<isLocal>false</isLocal>
#<isUp>true</isUp>
#<isStopped>false</isStopped>
#<lastStatusChange>1394745414752</lastStatusChange>
#<attributes>
#<entry>
#<key>eco.system.membership</key>
#<value>ECO-MEMBERSHIP-cc35d900-aaf4-11e3-a3d4-0a925d65298e</value>
#</entry>
#<entry>
#<key>eco.system.dsm.identity</key>
#<value>ECO-DSM-6eb95b07-aaf4-11e3-8faf-0ec3ae3656de</value>
#</entry>
#</attributes>
#</node>';
my $xml = XMLin($content, forcearray => 0, keyattr => [] );
my $nodeIdentity = get_field2($xml, "nodeIdentity");
my $locationIdentity = get_field2($xml, "locationIdentity");
my $isLocal = get_field2($xml, "isLocal");
my $isUp = get_field2($xml, "isUp");
my $isStopped = get_field2($xml, "isStopped");
my $lastStatusChange = get_field2_float($xml, "lastStatusChange");
$isUp = ( $isUp and $isUp eq "true" ? "true" : "FALSE" );
$isStopped = ( $isStopped and $isStopped ne "false" ? "TRUE" : "false" );
$isLocal = ( $isLocal and $isLocal eq "true" ? "true" : "false" );
if ($isStopped eq "true" or $isUp ne "true"){
critical;
}
my $last_status_change = floor(time - ($lastStatusChange / 1000));
# TODO: move to library and polish up
my $human_time;
if($last_status_change > 86400){
$human_time = sprintf("%.1f days", $last_status_change / 86400);
} elsif($last_status_change > 3600){
$human_time = sprintf("%.1f hours", $last_status_change / 3600);
} else {
$human_time = "$last_status_change secs";
}
$msg .= "node '$nodeIdentity' location '$locationIdentity' up='$isUp' stopped='$isStopped' local='$isLocal' last status change = $human_time ago ($last_status_change secs)";
if($last_status_change < 0){
warning;
$msg .= " (in future, NTP issue?)";
}
vlog2;
quit $status, $msg;