|
@@ -22,7 +22,9 @@
|
|
* check_jmx -H hostaddress -p port -w 1 -c 1
|
|
* check_jmx -H hostaddress -p port -w 1 -c 1
|
|
*/
|
|
*/
|
|
|
|
|
|
- $options = getopt ("h:p:w:c:");
|
|
|
|
|
|
+ include "hdp_nagios_init.php";
|
|
|
|
+
|
|
|
|
+ $options = getopt ("h:p:w:c:e:k:r:t:s:");
|
|
if (!array_key_exists('h', $options) || !array_key_exists('p', $options) || !array_key_exists('w', $options)
|
|
if (!array_key_exists('h', $options) || !array_key_exists('p', $options) || !array_key_exists('w', $options)
|
|
|| !array_key_exists('c', $options)) {
|
|
|| !array_key_exists('c', $options)) {
|
|
usage();
|
|
usage();
|
|
@@ -33,15 +35,51 @@
|
|
$port=$options['p'];
|
|
$port=$options['p'];
|
|
$warn=$options['w']; $warn = preg_replace('/%$/', '', $warn);
|
|
$warn=$options['w']; $warn = preg_replace('/%$/', '', $warn);
|
|
$crit=$options['c']; $crit = preg_replace('/%$/', '', $crit);
|
|
$crit=$options['c']; $crit = preg_replace('/%$/', '', $crit);
|
|
|
|
+ $keytab_path=$options['k'];
|
|
|
|
+ $principal_name=$options['r'];
|
|
|
|
+ $kinit_path_local=$options['t'];
|
|
|
|
+ $security_enabled=$options['s'];
|
|
|
|
+ $ssl_enabled=$options['e'];
|
|
|
|
+
|
|
|
|
+ /* Kinit if security enabled */
|
|
|
|
+ $status = kinit_if_needed($security_enabled, $kinit_path_local, $keytab_path, $principal_name);
|
|
|
|
+ $retcode = $status[0];
|
|
|
|
+ $output = $status[1];
|
|
|
|
+
|
|
|
|
+ if ($output != 0) {
|
|
|
|
+ echo "CRITICAL: Error doing kinit for nagios. $output";
|
|
|
|
+ exit (2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $protocol = ($ssl_enabled == "true" ? "https" : "http");
|
|
|
|
+
|
|
|
|
|
|
foreach (preg_split('/,/', $hosts) as $host) {
|
|
foreach (preg_split('/,/', $hosts) as $host) {
|
|
/* Get the json document */
|
|
/* Get the json document */
|
|
- $json_string = file_get_contents("http://".$host.":".$port."/jmx?qry=Hadoop:service=NameNode,name=FSNamesystemState");
|
|
|
|
|
|
+ $ch = curl_init();
|
|
|
|
+ $username = rtrim(`id -un`, "\n");
|
|
|
|
+ curl_setopt_array($ch, array( CURLOPT_URL => $protocol."://".$host.":".$port."/jmx?qry=Hadoop:service=NameNode,name=FSNamesystemState",
|
|
|
|
+ CURLOPT_RETURNTRANSFER => true,
|
|
|
|
+ CURLOPT_HTTPAUTH => CURLAUTH_ANY,
|
|
|
|
+ CURLOPT_USERPWD => "$username:",
|
|
|
|
+ CURLOPT_SSL_VERIFYPEER => FALSE ));
|
|
|
|
+ $json_string = curl_exec($ch);
|
|
|
|
+ $info = curl_getinfo($ch);
|
|
|
|
+ if (intval($info['http_code']) == 401){
|
|
|
|
+ logout();
|
|
|
|
+ $json_string = curl_exec($ch);
|
|
|
|
+ }
|
|
|
|
+ $info = curl_getinfo($ch);
|
|
|
|
+ curl_close($ch);
|
|
$json_array = json_decode($json_string, true);
|
|
$json_array = json_decode($json_string, true);
|
|
$percent = 0;
|
|
$percent = 0;
|
|
$object = $json_array['beans'][0];
|
|
$object = $json_array['beans'][0];
|
|
$CapacityUsed = $object['CapacityUsed'];
|
|
$CapacityUsed = $object['CapacityUsed'];
|
|
$CapacityRemaining = $object['CapacityRemaining'];
|
|
$CapacityRemaining = $object['CapacityRemaining'];
|
|
|
|
+ if (count($object) == 0) {
|
|
|
|
+ echo "CRITICAL: Data inaccessible, Status code = ". $info['http_code'] ."\n";
|
|
|
|
+ exit(2);
|
|
|
|
+ }
|
|
$CapacityTotal = $CapacityUsed + $CapacityRemaining;
|
|
$CapacityTotal = $CapacityUsed + $CapacityRemaining;
|
|
if($CapacityTotal == 0) {
|
|
if($CapacityTotal == 0) {
|
|
$percent = 0;
|
|
$percent = 0;
|
|
@@ -66,6 +104,6 @@
|
|
|
|
|
|
/* print usage */
|
|
/* print usage */
|
|
function usage () {
|
|
function usage () {
|
|
- echo "Usage: $0 -h <host> -p port -w <warn%> -c <crit%>\n";
|
|
|
|
|
|
+ echo "Usage: $0 -h <host> -p port -w <warn%> -c <crit%> -k keytab path -r principal name -t kinit path -s security enabled -e ssl enabled\n";
|
|
}
|
|
}
|
|
?>
|
|
?>
|