Created
February 22, 2012 17:29
-
-
Save hcoyote/1886192 to your computer and use it in GitHub Desktop.
Determine if our HDFS is in safemode for some reason.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# This script is managed by puppet. | |
# | |
use strict; | |
use warnings; | |
use File::stat; | |
use Getopt::Long; | |
if (not exists $ENV{SUDO_USER}) { | |
if (scalar getpwuid($>) ne 'hdfs') { | |
# re-exec this as hdfs user as a work around to being called from | |
# nrpe. | |
exec("/usr/bin/sudo -u hdfs $0 @ARGV"); | |
} | |
} | |
my $hadoop_bin = "/usr/bin/hadoop"; | |
if ( not -x "/usr/bin/hadoop" ) { | |
print "Could not find $hadoop_bin\n"; | |
exit 3; | |
} | |
my $safemode = `$hadoop_bin dfsadmin -safemode get 2>&1`; | |
if ($safemode =~ /Safe mode is OFF/) { | |
print "OK: safemode is off and hdfs is functioning correctly\n"; | |
exit; | |
} elsif ($safemode =~ /Safe mode is ON/) { | |
print "CRITICAL: safemode is on - no writes to hdfs can occur!\n"; | |
exit 1; | |
} else { | |
print "UNKNOWN: safemode status cannot be checked. command returns '$safemode'\n"; | |
exit 3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment