Exemplo n.º 1
0
while (($host = current($Hosts)) !== false) {
    try {
        $P2000 = new P2000($host, $User, $Password);
        $P2000->Login();
        $connected = true;
    } catch (\Exception $ex) {
    }
    next($Hosts);
}
if (!$connected) {
    exitWithError($ex->getMessage());
}
if (@$Options['m'] == 'discovery') {
    echo $P2000->Discovery($Class);
} elseif (@$Options['m'] == 'query') {
    echo $P2000->SingleValue($Class, $Select, $What, $Field);
} elseif (@$Options['m'] == 'zbxsender') {
    $data = $P2000->dataToZbxSender($Class);
    if (@isset($Options['d'])) {
        var_dump($data);
        exit;
    }
    $cmd = "zabbix_sender -z 127.0.0.1 -vv -s {$ZabbixHost} -i -";
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    $proc = proc_open($cmd, $descriptorspec, $pipes);
    fwrite($pipes[0], $data);
    fclose($pipes[0]);
    $stdout = stream_get_contents($pipes[1]);
    $stderr = stream_get_contents($pipes[2]);
    fclose($pipes[1]);
    $return = proc_close($proc);