Example #1
0
function process_port_label(&$this_port, $device)
{
    global $config;
    // OS Specific rewrites (get your shit together, vendors)
    if ($device['os'] == 'zxr10') {
        $this_port['ifAlias'] = preg_replace("/^" . str_replace("/", "\\/", $this_port['ifName']) . "\\s*/", '', $this_port['ifDescr']);
    }
    if ($device['os'] == 'ciscosb' && $this_port['ifType'] == 'propVirtual' && is_numeric($this_port['ifDescr'])) {
        $this_port['ifName'] = 'Vl' . $this_port['ifDescr'];
    }
    $this_port['ifAlias'] = snmp_fix_string($this_port['ifAlias']);
    // Fix ord chars
    // Added for Brocade NOS. Will copy ifDescr -> ifAlias if ifDescr != ifName
    // ifAlias can be passed over SW-MIB
    if ($config['os'][$device['os']]['ifDescr_ifAlias'] && $this_port['ifAlias'] == '' && $this_port['ifDescr'] != $this_port['ifName']) {
        $this_port['ifAlias'] = $this_port['ifDescr'];
    }
    // Write port_label, port_label_base and port_label_num
    // Here definition override for ifDescr, because Calix switch ifDescr <> ifName since fw 2.2
    // Note, only for 'calix' os now
    if ($device['os'] == 'calix') {
        unset($config['os'][$device['os']]['ifname']);
        $version_parts = explode('.', $device['version']);
        if ($version_parts[0] > 2 || $version_parts[0] == 2 && $version_parts[1] > 1) {
            if ($this_port['ifName'] == '') {
                $this_port['port_label'] = $this_port['ifDescr'];
            } else {
                $this_port['port_label'] = $this_port['ifName'];
            }
        }
    }
    if ($this_port['ifDescr'] === '' && $config['os'][$device['os']]['ifType_ifDescr'] && $this_port['ifIndex']) {
        // This happen on some liebert UPS devices
        $type = rewrite_iftype($this_port['ifType']);
        if ($type) {
            $this_port['ifDescr'] = $type . ' ' . $this_port['ifIndex'];
            print_debug("Port 'ifDescr' rewritten: '' -> '" . $this_port['ifDescr'] . "'");
        }
    }
    if (isset($config['os'][$device['os']]['ifname'])) {
        if ($this_port['ifName'] == '') {
            $this_port['port_label'] = $this_port['ifDescr'];
        } else {
            $this_port['port_label'] = $this_port['ifName'];
        }
    } else {
        if (isset($config['os'][$device['os']]['ifalias'])) {
            $this_port['port_label'] = $this_port['ifAlias'];
        } else {
            $this_port['port_label'] = $this_port['ifDescr'];
            if (isset($config['os'][$device['os']]['ifindex'])) {
                $this_port['port_label'] .= ' ' . $this_port['ifIndex'];
            }
        }
    }
    if ($device['os'] == "speedtouch") {
        list($this_port['port_label']) = explode("thomson", $this_port['port_label']);
    }
    // Process label by os definition rewrites
    $oid = 'port_label';
    if (isset($config['os'][$device['os']][$oid])) {
        $oid_base = $oid . '_base';
        $oid_num = $oid . '_num';
        foreach ($config['os'][$device['os']][$oid] as $pattern) {
            if (preg_match($pattern, $this_port[$oid], $matches)) {
                print_debug("Port '{$oid}' rewritten: '" . $this_port[$oid] . "' -> '" . $matches[1] . "'");
                $this_port[$oid] = $matches[1];
                if (isset($matches[$oid_base])) {
                    $this_port[$oid_base] = $matches[$oid_base];
                }
                if (isset($matches[$oid_num])) {
                    $this_port[$oid_num] = $matches[$oid_num];
                }
                break;
            }
        }
    }
    // Extract bracket part from port label and remove it
    $label_bracket = '';
    if (preg_match('/\\s*(\\([^\\)]+\\))$/', $this_port['port_label'], $matches)) {
        // GigaVUE-212 Port  8/48 (Network Port)
        // rtif(172.20.30.46/28)
        $label_bracket = $matches[0];
        list($this_port['port_label']) = explode($matches[0], $this_port['port_label'], 2);
    }
    // Detect port_label_base and port_label_num
    if (isset($this_port['port_label_base'])) {
    } else {
        if (preg_match('/\\d+(?:(?:[\\/:](?:[a-z])?[\\d\\.:]+)+[a-z\\d\\.\\:]*(?:[\\-\\_][\\w\\.\\:]+)*|\\/\\w+$)/i', $this_port['port_label'], $matches)) {
            // Multipart numeric
            /*
            1/1/1
            e1-0/0/1.0
            e1-0/2/0:13.0
            dwdm0/1/0/6
            DTI1/1/0
            Cable8/1/4-upstream2
            Cable8/1/4
            16GigabitEthernet1/2/1
            cau4-0/2/0
            dot11radio0/0
            Dialer0/0.1
            Downstream 0/2/0
            1000BaseTX Port 8/48 Name
            Backplane-GigabitEthernet0/3
            Ethernet1/10
            FC port 0/19
            GigabitEthernet0/0/0/1
            GigabitEthernet0/1.ServiceInstance.206
            Integrated-Cable7/0/0:0
            Logical Upstream Channel 1/0.0/0
            Slot0/1
            sonet_12/1
            GigaVUE-212 Port  8/48 (Network Port)
            Stacking Port 1/StackA
            1:38
            1/4/x24, mx480-xe-0-0-0
            1/4/x24
            */
            $this_port['port_label_num'] = $matches[0];
            list($this_port['port_label_base']) = explode($matches[0], $this_port['port_label'], 2);
            $this_port['port_label'] = $this_port['port_label_base'] . $this_port['port_label_num'];
            // Remove additional part (after port number)
        } else {
            if (preg_match('/(?<port_label_num>(?:\\d+[a-z])?\\d[\\d\\.\\:]*(?:[\\-\\_]\\w+)?)(?: [a-z()\\[\\] ]+)?$/i', $this_port['port_label'], $matches)) {
                // Simple numeric
                /*
                GigaVUE-212 Port  1 (Network Port)
                MMC-A s3 SW Port
                Atm0_Physical_Interface
                wan1_phys
                fwbr101i0
                Nortel Ethernet Switch 325-24G Module - Port 1
                lo0.32768
                vlan.818
                jsrv.1
                Bundle-Ether1.1701
                Ethernet1
                ethernet_13
                eth0
                eth0.101
                BVI900
                A/1
                e1
                CATV-MAC 1
                16
                */
                $this_port['port_label_num'] = $matches['port_label_num'];
                $this_port['port_label_base'] = substr($this_port['port_label'], 0, 0 - strlen($matches[0]));
                $this_port['port_label'] = $this_port['port_label_base'] . $this_port['port_label_num'];
                // Remove additional part (after port number)
            } else {
                // All other (non-numeric)
                /*
                UniPing Server Solution v3/SMS Enet Port
                MMC-A s2 SW Port
                Control Plane
                */
                $this_port['port_label_base'] = $this_port['port_label'];
            }
        }
    }
    // When not empty label brackets and empty numeric part, re-add brackets to label
    if (!empty($label_bracket) && $this_port['port_label_num'] == '') {
        // rtif(172.20.30.46/28)
        $this_port['port_label'] .= $label_bracket;
    }
    $this_port['port_label_short'] = short_ifname($this_port['port_label']);
    // Set entity variables for use by code which uses entities
    // Base label part: TenGigabitEthernet3/3 -> TenGigabitEthernet, GigabitEthernet4/8.722 -> GigabitEthernet, Vlan2603 -> Vlan
    //$port['port_label_base'] = preg_replace('/^([A-Za-z ]*).*/', '$1', $port['port_label']);
    //$port['port_label_num']  = substr($port['port_label'], strlen($port['port_label_base'])); // Second label part
    //
    //  // Index example for TenGigabitEthernet3/10.324:
    //  //  $ports_links['Ethernet'][] = array('label_base' => 'TenGigabitEthernet', 'label_num0' => '3', 'label_num1' => '10', 'label_num2' => '324')
    //  $label_num  = preg_replace('![^\d\.\/]!', '', substr($data['port_label'], strlen($data['port_label_base']))); // Remove base part and all not-numeric chars
    //  preg_match('!^(\d+)(?:\/(\d+)(?:\.(\d+))*)*!', $label_num, $label_nums); // Split by slash and point (1/1.324)
    //  $ports_links[$data['human_type']][$data['ifIndex']] = array(
    //    'label'      => $data['port_label'],
    //    'label_base' => $data['port_label_base'],
    //    'label_num0' => $label_nums[0],
    //    'label_num1' => $label_nums[1],
    //    'label_num2' => $label_nums[2],
    //    'link'       => generate_port_link($data, $data['port_label_short'])
    //  );
    return TRUE;
}
Example #2
0
print_cli_data("Serial", $serial ?: "%b<empty>%n");
print_cli_data("Asset", $asset_tag ?: "%b<empty>%n");
echo PHP_EOL;
foreach ($os_additional_info as $header => $entries) {
    print_cli_heading($header, 3);
    foreach ($entries as $field => $entry) {
        print_cli_data($field, $entry, 3);
    }
    echo PHP_EOL;
}
// Fields notified in event log
$update_fields = array('version', 'features', 'hardware', 'serial', 'kernel', 'distro', 'distro_ver', 'arch', 'asset_tag');
// Log changed variables
foreach ($update_fields as $field) {
    if (isset(${$field})) {
        ${$field} = snmp_fix_string(${$field});
    }
    // Fix unprintable chars
    if ((isset(${$field}) || strlen($device[$field])) && ${$field} != $device[$field]) {
        $update_array[$field] = ${$field};
        log_event(nicecase($field) . " -> " . $update_array[$field], $device, 'device', $device['device_id']);
    }
}
// Here additional fields, change only if not set already
foreach (array('type', 'icon') as $field) {
    if (isset(${$field}) && ($device[$field] == "unknown" || $device[$field] == '' || !isset($device[$field]) || !strlen($device[$field]))) {
        $update_array[$field] = ${$field};
        log_event(nicecase($field) . " -> " . $update_array[$field], $device, 'device', $device['device_id']);
    }
}
unset($entPhysical, $oids, $hw, $os_additional_info);
Example #3
0
}
// Check if snmpEngineID changed
if (strlen($poll_device['snmpEngineID'] . $device['snmpEngineID']) && $poll_device['snmpEngineID'] != $device['snmpEngineID']) {
    $update_array['snmpEngineID'] = $poll_device['snmpEngineID'];
    if ($device['snmpEngineID']) {
        // snmpEngineID changed frome one to other
        log_event('snmpEngineID changed: ' . $device['snmpEngineID'] . ' -> ' . $poll_device['snmpEngineID'] . ' (probably the device was replaced). The device will be rediscovered.', $device, 'device', $device['device_id'], 4);
        // Reset device discover time for full re-discovery
        dbUpdate(array('last_discovered' => array('NULL')), 'devices', '`device_id` = ?', array($device['device_id']));
    } else {
        log_event('snmpEngineID -> ' . $poll_device['snmpEngineID'], $device, 'device', $device['device_id']);
    }
}
$oids = array('sysObjectID', 'sysContact', 'sysName', 'sysDescr');
foreach ($oids as $oid) {
    $poll_device[$oid] = snmp_fix_string($poll_device[$oid]);
    //print_vars($poll_device[$oid]);
    if ($poll_device[$oid] != $device[$oid]) {
        $update_array[$oid] = $poll_device[$oid] ? $poll_device[$oid] : array('NULL');
        log_event("{$oid} -> '" . $poll_device[$oid] . "'", $device, 'device', $device['device_id']);
    }
}
print_cli_data('sysObjectID', $poll_device['sysObjectID'], 2);
print_cli_data('snmpEngineID', $poll_device['snmpEngineID'], 2);
print_cli_data('sysDescr', $poll_device['sysDescr'], 2);
print_cli_data('sysName', $poll_device['sysName'], 2);
print_cli_data('Location', $poll_device['sysLocation'], 2);
$geo_detect = FALSE;
if ($device['location'] != $poll_device['sysLocation']) {
    // Reset geolocation when location changes - triggers re-geolocation
    $geo_detect = TRUE;