Exemplo n.º 1
0
if (array_key_exists('h', $options) || !array_key_exists('H', $options) || !array_key_exists('p', $options) || !array_key_exists('C', $options) || !array_key_exists('P', $options)) {
    usage();
    exit(3);
}
$hosts = explode(',', $options['H']);
$port = $options['p'];
$rm_port = $options['P'];
$cluster = $options['C'];
$protocol = array_key_exists('S', $options) ? 'https' : 'http';
$query = "GET hosts\n";
$query .= "Filter: host_groups >= {$cluster}\n";
$query .= "Filter: host_groups >= yarn_rm\n";
$query .= "Columns: host_name\n";
$resourcemanagers = false;
foreach ($hosts as $host) {
    $resourcemanagers = query_livestatus($host, $port, $query);
    if (!empty($resourcemanagers)) {
        break;
    }
}
$active = array();
foreach ($resourcemanagers as $rm_host) {
    $json_string = do_curl($protocol, $rm_host, $rm_port, '/jmx?qry=Hadoop:service=ResourceManager,name=ClusterMetrics');
    if ($json_string === false || preg_match('/^This is standby RM/', $json_string)) {
        continue;
    }
    $json_array = json_decode($json_string, true);
    $object = $json_array['beans'][0];
    if (count($object) != 0) {
        $active[] = $rm_host;
    }
Exemplo n.º 2
0
if (array_key_exists('h', $options) || !array_key_exists('H', $options) || !array_key_exists('p', $options) || !array_key_exists('C', $options) || !array_key_exists('P', $options)) {
    usage();
    exit(3);
}
$hosts = explode(',', $options['H']);
$port = $options['p'];
$nn_port = $options['P'];
$cluster = $options['C'];
$protocol = array_key_exists('S', $options) ? 'https' : 'http';
$object = false;
$query = "GET hosts\n";
$query .= "Filter: host_groups >= {$cluster}\n";
$query .= "Filter: host_groups >= hdfs_nn\n";
$query .= "Columns: host_name\n";
foreach ($hosts as $host) {
    $namenodes = query_livestatus($host, $port, $query);
    if (!empty($namenodes)) {
        break;
    }
}
$active = array();
foreach ($namenodes as $nn_host) {
    /* Get the json document */
    foreach ($hosts as $host) {
        $object = get_from_jmx($protocol, $nn_host, $nn_port, 'Hadoop:service=NameNode,name=FSNamesystem');
        if (!empty($object)) {
            break;
        }
    }
    if (empty($object)) {
        echo 'CRITICAL: Data inaccessible' . PHP_EOL;
Exemplo n.º 3
0
#!/usr/bin/env php
<?php 
require 'lib.php';
$options = getopt("hH:p:d:f:u");
if (array_key_exists('h', $options) || !array_key_exists('H', $options) || !array_key_exists('p', $options) || !array_key_exists('d', $options)) {
    usage();
    exit(3);
}
$hosts = explode(',', $options['H']);
$port = $options['p'];
$service = $options['d'];
$filters = parseArrOpt($options, 'f');
foreach ($hosts as $host) {
    $res = query_livestatus($host, $port, create_service_request($service, $filters, array('plugin_output')));
    if (!empty($res)) {
        break;
    }
}
if (sizeof($res) == 0) {
    echo "Error: No OUTPUT found";
    exit(2);
} elseif (sizeof($res) > 1 && array_key_exists('u')) {
    echo "ERROR: multiple OUTPUT found";
    exit(2);
} else {
    foreach ($res as $line) {
        echo $line . PHP_EOL;
    }
}
function usage()
{