forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_hadoop_namenode_safemode.pl
executable file
·74 lines (54 loc) · 1.47 KB
/
check_hadoop_namenode_safemode.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: 2013-11-08 18:34:41 +0000 (Fri, 08 Nov 2013)
#
# http://github.com/harisekhon
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check if a Hadoop NameNode is in Safe Mode via JMX
Raises warning status if the NameNode is in Safe Mode.
Written and tested on Hortonworks HDP 2.1";
$VERSION = "0.1";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use Data::Dumper;
use JSON::XS;
use LWP::Simple '$ua';
$ua->agent("Hari Sekhon $progname version $main::VERSION");
set_port_default(50070);
env_creds(["HADOOP_NAMENODE", "HADOOP"], "Hadoop NameNode");
%options = (
%hostoptions,
);
get_options();
$host = validate_host($host);
$port = validate_port($port);
vlog2;
set_timeout();
$status = "OK";
my $url = "http://$host:$port/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo";
$json = curl_json $url;
my @beans = get_field_array("beans");
my $found_mbean = 0;
my $Safemode;
foreach(@beans){
next unless get_field2($_, "name") eq "Hadoop:service=NameNode,name=NameNodeInfo";
$found_mbean = 1;
$Safemode = get_field2($_, "Safemode");
last;
}
unless($found_mbean){
quit "UNKNOWN", "failed to find NameNodeInfo mbean. $nagios_plugins_support_msg_api" unless $found_mbean;
}
warning if $Safemode;
$Safemode = ( $Safemode ? "true" : "false");
$msg = "NameNode safe mode = $Safemode";
quit $status, $msg;