Ejemplo n.º 1
0
function register_mibs($device, $mibs, $included_by)
{
    if (!is_mib_poller_enabled($device)) {
        return;
    }
    echo "MIB: registering\n";
    foreach ($mibs as $name => $module) {
        $translated = snmp_translate($name, $module);
        if ($translated) {
            $mod = $translated[0];
            $nam = $translated[1];
            echo "     {$mod}::{$nam}\n";
            if (snmp_mib_load($nam, $mod, $included_by) > 0) {
                // NOTE: `last_modified` omitted due to being automatically maintained by MySQL
                $columns = array('device_id', 'module', 'mib', 'included_by');
                $rows = array();
                $rows[] = array('device_id' => $device['device_id'], 'module' => $mod, 'mib' => $nam, 'included_by' => $included_by);
                update_db_table('device_mibs', $columns, 3, $rows);
            } else {
                echo "MIB: Could not load definition for {$mod}::{$nam}\n";
            }
        } else {
            echo "MIB: Could not find {$module}::{$name}\n";
        }
    }
    echo "\n";
}
Ejemplo n.º 2
0
        $mibs = $mib;
    }
}
$oids = snmpwalk_cache_twopart_oid($device, "pingCtlEntry", array(), $mibs, NULL, $flags);
//print_vars($oids);
if ($GLOBALS['snmp_status'] === FALSE) {
    return;
}
$mib_lower = strtolower($mib);
foreach ($oids as $sla_owner => $entry2) {
    foreach ($entry2 as $sla_name => $entry) {
        if (!isset($entry['pingCtlAdminStatus']) || $sla_owner == 'imclinktopologypleaseignore') {
            continue;
        }
        // Get full index
        $sla_index = snmp_translate('pingCtlRowStatus."' . $sla_owner . '"."' . $sla_name . '"', $mib);
        $sla_index = str_replace('.1.3.6.1.2.1.80.1.2.1.23.', '', $sla_index);
        $data = array('device_id' => $device['device_id'], 'sla_mib' => $mib, 'sla_index' => $sla_name, 'sla_owner' => $sla_owner, 'sla_tag' => $entry['pingCtlTargetAddress'], 'sla_status' => $entry['pingCtlRowStatus'], 'sla_graph' => 'jitter', 'deleted' => 0);
        if ($entry['pingCtlAdminStatus'] == 'disabled') {
            // If SLA administarively disabled, exclude from polling
            $data['deleted'] = 1;
        }
        // Type conversions
        // Standart types: pingIcmpEcho, pingUdpEcho, pingSnmpQuery, pingTcpConnectionAttempt
        // Juniper types:  jnxPingIcmpTimeStamp, jnxPingHttpGet, jnxPingHttpGetMetadata, jnxPingDnsQuery, jnxPingNtpQuery, jnxPingUdpTimestamp
        // HH3C types:
        $data['rtt_type'] = str_replace(array('ping', 'jnxPing', 'hh3cNqa'), '', $entry['pingCtlType']);
        // Tag / Target
        if (isHexString($entry['pingCtlTargetAddress']) || stripos($data['rtt_type'], 'Echo') !== FALSE) {
            $data['sla_tag'] = hex2ip($data['sla_tag']);
        }
Ejemplo n.º 3
0
function snmpwalk_cache_oid_num2($device, $oid, $array, $mib = NULL, $mibdir = NULL, $set_cache = FALSE)
{
    global $cache;
    if (!(is_array($cache['snmp'][$device['device_id']]) && array_key_exists($oid, $cache['snmp'][$device['device_id']]))) {
        $data = snmp_walk($device, $oid, '-OQUn', $mib, $mibdir);
        $translate = snmp_translate($oid, $mib, $mibdir);
        $pattern = '/^' . str_replace('.', '\\.', $translate) . '\\./';
        foreach (explode("\n", $data) as $entry) {
            list($oid_num, $value) = explode("=", $entry, 2);
            $oid_num = trim($oid_num);
            $value = trim($value);
            $index = preg_replace($pattern, '', $oid_num);
            if (!strstr($value, "at this OID") && isset($oid) && isset($index)) {
                $array[$index][$oid] = $value;
            }
        }
        if ($set_cache) {
            $cache['snmp'][$device['device_id']][$oid] = $array;
        } else {
            return $array;
        }
    }
    return $cache['snmp'][$device['device_id']][$oid];
}
Ejemplo n.º 4
0
 * @subpackage poller
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
//AIRESPACE-SWITCHING-MIB::agentInventorySysDescription.0 = STRING: Cisco Controller
//AIRESPACE-SWITCHING-MIB::agentInventoryMachineModel.0 = STRING: AIR-CT5508-K9
//AIRESPACE-SWITCHING-MIB::agentInventorySerialNumber.0 = STRING: FCW1546L0D6
//AIRESPACE-SWITCHING-MIB::agentInventoryProductName.0 = STRING: Cisco Controller
//AIRESPACE-SWITCHING-MIB::agentInventoryProductVersion.0 = STRING: 7.6.100.0
$data = snmp_get_multi($device, 'agentInventoryMachineModel.0 agentInventoryProductVersion.0 agentInventorySerialNumber.0', '-OQUs', 'AIRESPACE-SWITCHING-MIB');
if (is_array($data[0])) {
    $hardware = $data[0]['agentInventoryMachineModel'];
    $version = $data[0]['agentInventoryProductVersion'];
    $serial = $data[0]['agentInventorySerialNumber'];
} else {
    if ($entPhysical['entPhysicalModelName']) {
        $hardware = $entPhysical['entPhysicalModelName'];
        $version = $entPhysical['entPhysicalSoftwareRev'];
        $serial = $entPhysical['entPhysicalSerialNum'];
    }
}
if (empty($hardware) && $poll_device['sysObjectID']) {
    // Try translate instead duplicate get sysObjectID
    $hardware = snmp_translate($poll_device['sysObjectID'], 'SNMPv2-MIB:CISCO-PRODUCTS-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB');
}
if (empty($hardware)) {
    // If translate false, try get sysObjectID again
    $hardware = snmp_get($device, 'sysObjectID.0', '-Osqv', 'SNMPv2-MIB:CISCO-PRODUCTS-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB');
}
unset($data);
// EOF
Ejemplo n.º 5
0
function poll_mibs($list, $device, &$graphs)
{
    if (!is_dev_attrib_enabled($device, "poll_mib")) {
        d_echo("MIB module disabled for " . $device['hostname'] . "\n");
        return;
    }
    $mibdefs = array();
    echo "MIB-based polling:";
    d_echo("\n");
    foreach ($list as $name => $module) {
        $translated = snmp_translate($name, $module);
        if ($translated) {
            echo " {$module}::{$name}";
            d_echo("\n");
            $mod = $translated[0];
            $nam = $translated[1];
            $mibdefs[$nam] = snmp_mib_load($nam, $mod);
            $oids = snmpwalk_cache_oid($device, $nam, array(), $mod, null, "-OQUsb");
            d_print_r($oids);
            save_mibs($device, $nam, $oids, $mibdefs[$nam], $graphs);
        } else {
            d_echo("MIB: no match for {$module}::{$name}\n");
        }
    }
    d_echo("Done MIB-based polling");
    echo "\n";
}
Ejemplo n.º 6
0
         }
     }
     // Idle
     $idle = isset($entry['idle']) && $entry['idle'] ? 1 : 0;
     // Precision (scale)
     $precision = 1;
     if (isset($entry['scale']) && is_numeric($entry['scale']) && $entry['scale'] != 1) {
         // FIXME, currently we support only int precision, need convert all to float scale!
         $precision = round(1 / $entry['scale'], 0);
     }
     $usage = snmp_get($device, $entry['oid'], '-OQUvs', $mib);
     $usage = snmp_fix_numeric($usage);
     if (is_numeric($usage)) {
         if (empty($entry['oid_num'])) {
             // Use snmptranslate if oid_num not set
             $entry['oid_num'] = snmp_translate($entry['oid'], $mib);
         }
         if (isset($entry['rename_rrd'])) {
             $old_rrd = 'processor-' . $entry['rename_rrd'];
             $new_rrd = 'processor-' . $entry_name . '-' . $index;
             rename_rrd($device, $old_rrd, $new_rrd);
             unset($old_rrd, $new_rrd);
         }
         discover_processor($valid['processor'], $device, $entry['oid_num'], $index, $entry_name, $descr, $precision, $usage, NULL, NULL, $idle);
         $entry['found'] = TRUE;
     }
 }
 unset($processors_array, $processor, $dot_index, $descr, $i);
 // Clean up
 if (isset($entry['stop_if_found']) && $entry['stop_if_found'] && $entry['found']) {
     break;
Ejemplo n.º 7
0
$pws = snmpwalk_cache_threepart_oid($device, 'jnxVpnRemotePeIdAddress', $pws, 'JUNIPER-VPN-MIB', NULL, $flags);
// pwPeerAddr
//$pws = snmpwalk_cache_oid($device, 'pwLocalIfMtu',     $pws, 'JUNIPER-VPN-MIB');
//$pws = snmpwalk_cache_oid($device, 'pwRemoteIfMtu',    $pws, 'JUNIPER-VPN-MIB');
$pws = snmpwalk_cache_threepart_oid($device, 'jnxVpnPwRemoteSiteId', $pws, 'JUNIPER-VPN-MIB', NULL, $flags);
// pwMplsPeerLdpID
if (OBS_DEBUG > 1) {
    echo 'PWS_WALK: ' . count($pws) . "\n";
    print_vars($pws);
}
foreach ($pws as $pw_type => $entry) {
    foreach ($entry as $pw_name => $entry2) {
        foreach ($entry2 as $pw_ifIndex => $pw) {
            //if (strlen($pw['jnxVpnPwRowStatus']) && $pw['jnxVpnPwRowStatus'] != 'active') { continue; } // Skip inactive (active, notinService, notReady, createAndGo, createAndWait, destroy)
            // Get full index
            $pw_index = snmp_translate('jnxVpnPwRowStatus.' . $pw_type . '."' . $pw_name . '".' . $pw_ifIndex, 'JUNIPER-VPN-MIB');
            $pw_index = str_replace('.1.3.6.1.4.1.2636.3.26.1.4.1.4.', '', $pw_index);
            $peer_addr = hex2ip($pw['jnxVpnRemotePeIdAddress']);
            $peer_addr_version = get_ip_version($peer_addr);
            $peer_addr_type = $pw['jnxVpnRemotePeIdAddrType'];
            if ($peer_addr_version) {
                $peer_addr_type = 'ipv' . $peer_addr_version;
                // Override address type, because snmp sometime return incorrect
                $peer_rdns = gethostbyaddr6($peer_addr);
                // PTR name
                if ($peer_addr_type == 'ipv6') {
                    $peer_addr = Net_IPv6::uncompress($peer_addr, TRUE);
                }
                // FIXME. Retarded way
                $remote_device = dbFetchCell('SELECT `device_id` FROM `' . $peer_addr_type . '_addresses`
                                        LEFT JOIN `ports` USING(`port_id`)
Ejemplo n.º 8
0
function snmpwalk_cache_oid_num2($device, $oid, $array, $mib = NULL, $mibdir = NULL, $flags = OBS_SNMP_ALL_NUMERIC)
{
    $output = 'QUn';
    // This function always use OBS_SNMP_NUMERIC
    //if (is_flag_set(OBS_SNMP_NUMERIC_INDEX, $flags)) { $output .= 'b'; }
    //if (is_flag_set(OBS_SNMP_NUMERIC,       $flags)) { $output .= 'n'; }
    if (is_flag_set(OBS_SNMP_ENUM, $flags)) {
        $output .= 'e';
    }
    if (is_flag_set(OBS_SNMP_HEX, $flags)) {
        $output .= 'x';
    }
    $data = snmp_walk($device, $oid, "-O{$output}", $mib, $mibdir, $flags);
    $oid_base = snmp_translate($oid, $mib, $mibdir);
    $pattern = '/^' . str_replace('.', '\\.', $oid_base) . '\\./';
    foreach (explode("\n", $data) as $entry) {
        list($oid_num, $value) = explode('=', $entry, 2);
        $oid_num = trim($oid_num);
        $value = trim_quotes($value, $flags);
        $index = preg_replace($pattern, '', $oid_num);
        if (isset($oid) && isset($index[0]) && is_valid_snmp_value($value)) {
            $array[$index][$oid] = $value;
        }
    }
    return $array;
}
Ejemplo n.º 9
0
        if (!empty($entPhysical['entPhysicalSerialNum'])) {
            $serial = $entPhysical['entPhysicalSerialNum'];
        }
    }
}
// NOTE. In CISCO-PRODUCTS-MIB uses weird hardware names (entPhysicalName uses human readable names)
// Examples:
// sysObjectID [.1.3.6.1.4.1.9.1.658]: cisco7604
// entPhysicalModelName:               CISCO7604
// sysObjectID [.1.3.6.1.4.1.9.1.927]: cat296048TCS
// entPhysicalModelName:               WS-C2960-48TC-S
// sysObjectID [.1.3.6.1.4.1.9.1.1208]: cat29xxStack
// entPhysicalModelName:               WS-C2960S-F48TS-L
if (empty($hardware) && $poll_device['sysObjectID']) {
    // Try translate instead duplicate get sysObjectID
    $hardware = snmp_translate($poll_device['sysObjectID'], "SNMPv2-MIB:CISCO-PRODUCTS-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB", mib_dirs(array("cisco")));
}
if (empty($hardware)) {
    // If translate false, try get sysObjectID again
    $hardware = snmp_get($device, "sysObjectID.0", "-Osqv", "SNMPv2-MIB:CISCO-PRODUCTS-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB", mib_dirs(array("cisco")));
}
// Additional checks for IOS devices
if ($device['os'] == 'ios') {
    if (stristr($hardware, 'AIRAP') || substr($hardware, 0, 4) == 'AIR-') {
        $ios_type = 'wireless';
    }
    // Set type to a predefined type for the OS if it's not already set
    if (isset($ios_type) && $device['type'] != $ios_type) {
        $type = $ios_type;
    }
    unset($ios_type);
Ejemplo n.º 10
0
function snmpwalk_cache_oid_num2($device, $oid, $array, $mib = NULL, $mibdir = NULL)
{
    $data = snmp_walk($device, $oid, '-OQUn', $mib, $mibdir);
    $translate = snmp_translate($oid, $mib, $mibdir);
    $pattern = '/^' . str_replace('.', '\\.', $translate) . '\\./';
    foreach (explode("\n", $data) as $entry) {
        list($oid_num, $value) = explode("=", $entry, 2);
        $oid_num = trim($oid_num);
        $value = trim($value);
        $index = preg_replace($pattern, '', $oid_num);
        if (!strstr($value, "at this OID") && isset($oid) && isset($index)) {
            $array[$index][$oid] = $value;
        }
    }
    return $array;
}
Ejemplo n.º 11
0
            print_cli('] ');
        }
        print_cli(PHP_EOL);
    }
}
// Detect Status by simple MIB-based discovery :
foreach (get_device_mibs($device) as $mib) {
    if (is_array($config['mibs'][$mib]['status'])) {
        print_cli_data_field($mib);
        foreach ($config['mibs'][$mib]['status'] as $oid => $oid_data) {
            print_cli($oid . ' [');
            foreach ($oid_data['indexes'] as $index => $entry) {
                $entry['oid'] = $oid;
                if (empty($entry['oid_num'])) {
                    // Use snmptranslate if oid_num not set
                    $entry['oid_num'] = snmp_translate($oid . '.' . $index, $mib);
                }
                $value = snmp_get($device, $entry['oid_num'], '-OQUvsn');
                if (is_numeric($value)) {
                    // Fetch description from oid if specified
                    if (isset($entry['oid_descr'])) {
                        $entry['descr'] = snmp_get($device, $entry['oid_descr'], '-OQUvs');
                    }
                    rename_rrd($device, "status-" . $entry['type'] . '-' . $index, "status-" . $entry['type'] . '-' . "{$oid}.{$index}");
                    discover_status($device, $entry['oid_num'], "{$oid}.{$index}", $entry['type'], $entry['descr'], $value, array('entPhysicalClass' => $entry['measured']));
                }
            }
            print_cli('] ');
        }
        print_cli('] ');
    }