function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
{
    global $debug, $config, $runtime_stats, $mibs_loaded;
    if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
        $timeout = $device['timeout'];
    } elseif (isset($config['snmp']['timeout'])) {
        $timeout = $config['snmp']['timeout'];
    }
    if (is_numeric($device['retries']) && $device['retries'] > 0) {
        $retries = $device['retries'];
    } elseif (isset($config['snmp']['retries'])) {
        $retries = $config['snmp']['retries'];
    }
    if (!isset($device['transport'])) {
        $device['transport'] = "udp";
    }
    if (strstr($oid, ' ')) {
        echo report_this_text("snmp_get called for multiple OIDs: {$oid}");
    }
    $cmd = $config['snmpget'];
    $cmd .= snmp_gen_auth($device);
    if ($options) {
        $cmd .= " " . $options;
    }
    if ($mib) {
        $cmd .= " -m " . $mib;
    }
    if ($mibdir) {
        $cmd .= " -M " . $mibdir;
    } else {
        $cmd .= " -M " . $config['mibdir'];
    }
    if (isset($timeout)) {
        $cmd .= " -t " . $timeout;
    }
    if (isset($retries)) {
        $cmd .= " -r " . $retries;
    }
    $cmd .= " " . $device['transport'] . ":" . $device['hostname'] . ":" . $device['port'];
    $cmd .= " " . $oid;
    if (!$debug) {
        $cmd .= " 2>/dev/null";
    }
    $data = trim(external_exec($cmd));
    $runtime_stats['snmpget']++;
    if (is_string($data) && preg_match("/(No Such Instance|No Such Object|No more variables left|Authentication failure)/i", $data)) {
        return false;
    } elseif ($data) {
        return $data;
    } else {
        return false;
    }
}
Beispiel #2
0
function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
{
    global $debug, $config, $runtime_stats, $mibs_loaded;
    $timeout = prep_snmp_setting($device, 'timeout');
    $retries = prep_snmp_setting($device, 'retries');
    if (!isset($device['transport'])) {
        $device['transport'] = 'udp';
    }
    if (strstr($oid, ' ')) {
        echo report_this_text("snmp_get called for multiple OIDs: {$oid}");
    }
    $cmd = $config['snmpget'];
    $cmd .= snmp_gen_auth($device);
    if ($options) {
        $cmd .= ' ' . $options;
    }
    if ($mib) {
        $cmd .= ' -m ' . $mib;
    }
    $cmd .= mibdir($mibdir);
    $cmd .= isset($timeout) ? ' -t ' . $timeout : '';
    $cmd .= isset($retries) ? ' -r ' . $retries : '';
    $cmd .= ' ' . $device['transport'] . ':' . $device['hostname'] . ':' . $device['port'];
    $cmd .= ' ' . $oid;
    if (!$debug) {
        $cmd .= ' 2>/dev/null';
    }
    $data = trim(external_exec($cmd));
    $runtime_stats['snmpget']++;
    if (is_string($data) && preg_match('/(No Such Instance|No Such Object|No more variables left|Authentication failure)/i', $data)) {
        return false;
    } else {
        if ($data) {
            return $data;
        } else {
            return false;
        }
    }
}
Beispiel #3
0
function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
{
    $time_start = microtime(true);
    if (strstr($oid, ' ')) {
        echo report_this_text("snmp_get called for multiple OIDs: {$oid}");
    }
    $cmd = gen_snmpget_cmd($device, $oid, $options, $mib, $mibdir);
    $data = trim(external_exec($cmd));
    recordSnmpStatistic('snmpget', $time_start);
    if (is_string($data) && preg_match('/(No Such Instance|No Such Object|No more variables left|Authentication failure)/i', $data)) {
        return false;
    } elseif ($data || $data === '0') {
        return $data;
    } else {
        return false;
    }
}