<?php

$mac_list = array();
// Disabled because we can do this better in poller now without performance hit
if ($device['os_group'] == "cisco" && FALSE) {
    echo "Cisco MAC Accounting : ";
    $datas = snmp_walk($device, "CISCO-IP-STAT-MIB::cipMacSwitchedBytes", "-OUqsX", "NS-ROOT-MIB");
    foreach (explode("\n", $datas) as $data) {
        list(, $ifIndex, $dir, $mac, ) = parse_oid2($data);
        list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(":", $mac);
        $ah_a = zeropad($a_a);
        $ah_b = zeropad($a_b);
        $ah_c = zeropad($a_c);
        $ah_d = zeropad($a_d);
        $ah_e = zeropad($a_e);
        $ah_f = zeropad($a_f);
        $clean_mac = "{$ah_a}{$ah_b}{$ah_c}{$ah_d}{$ah_e}{$ah_f}";
        $mac_list[$ifIndex . '_' . $clean_mac] = array('ifIndex' => $ifIndex, 'mac' => $clean_mac);
    }
    foreach ($mac_list as $mac_entry) {
        $port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? LIMIT 1", array($device['device_id'], $mac_entry['ifIndex']));
        if ($port) {
            echo $port['ifDescr'] . ' (' . $mac_entry['ifIndex'] . ') -> ' . $mac_entry['mac'];
            if (dbFetchCell("SELECT COUNT(*) from `mac_accounting` WHERE `port_id` = ? AND `mac` = ?", array($port['port_id'], $mac_entry['mac']))) {
                echo ".";
            } else {
                $ma_id = dbInsert(array('port_id' => $port['port_id'], 'device_id' => $device['device_id'], 'mac' => $mac_entry['mac']), 'mac_accounting');
                dbInsert(array('ma_id' => $ma_id), 'mac_accounting-state');
                echo "+";
            }
        } else {
function snmp_walk_parser2($device, $oid, $oid_elements, $mib = NULL, $mibdir = NULL)
{
    $data = snmp_walk($device, $oid, "-Oqs", $mib, $mibdir, FALSE);
    foreach (explode("\n", $data) as $text) {
        $ret = parse_oid2($text);
        if (!empty($ret['value'])) {
            // this seems retarded. need a way to just build this automatically.
            switch ($oid_elements) {
                case "1":
                    $array[$ret['oid'][0]] = $ret['value'];
                    break;
                case "2":
                    $array[$ret['oid'][1]][$ret['oid'][0]] = $ret['value'];
                    break;
                case "3":
                    $array[$ret['oid'][1]][$ret['oid'][2]][$ret['oid'][0]] = $ret['value'];
                    break;
                case "4":
                    $array[$ret['oid'][1]][$ret['oid'][2]][$ret['oid'][3]][$ret['oid'][0]] = $ret['value'];
                    break;
            }
        }
    }
    return $array;
}
Example #3
0
        $ma_array[$ifIndex . '-' . $vlan . '-' . $mac]['mac'] = $mac;
        $ma_array[$ifIndex . '-' . $vlan . '-' . $mac][$oid][$dir] = $value;
    }
}
// Cisco MAC Accounting
if (is_device_mib($device, 'CISCO-IP-STAT-MIB')) {
    echo "Cisco ";
    $datas = snmp_walk($device, "CISCO-IP-STAT-MIB::cipMacHCSwitchedBytes", "-OUqsX", "CISCO-IP-STAT-MIB");
    $datas .= "\n" . snmp_walk($device, "CISCO-IP-STAT-MIB::cipMacHCSwitchedPkts", "-OUqsX", "CISCO-IP-STAT-MIB");
    // No 64-bit counters? Try 32-bit. How necessary is this? How lacking is 64-bit support?
    if (strlen($datas) == 0) {
        $datas = snmp_walk($device, "CISCO-IP-STAT-MIB::cipMacSwitchedBytes", "-OUqsX", "CISCO-IP-STAT-MIB");
        $datas .= "\n" . snmp_walk($device, "CISCO-IP-STAT-MIB::cipMacSwitchedPkts", "-OUqsX", "CISCO-IP-STAT-MIB");
    }
    foreach (explode("\n", $datas) as $data) {
        list($oid, $ifIndex, $dir, $mac, $value) = parse_oid2($data);
        list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(":", $mac);
        $ah_a = zeropad($a_a);
        $ah_b = zeropad($a_b);
        $ah_c = zeropad($a_c);
        $ah_d = zeropad($a_d);
        $ah_e = zeropad($a_e);
        $ah_f = zeropad($a_f);
        $mac = "{$ah_a}{$ah_b}{$ah_c}{$ah_d}{$ah_e}{$ah_f}";
        // Cisco isn't per-VLAN.
        $vlan = "0";
        $oid = str_replace(array("cipMacSwitchedBytes", "cipMacSwitchedPkts", "cipMacHCSwitchedBytes", "cipMacHCSwitchedPkts"), array("bytes", "pkts", "bytes", "pkts"), $oid);
        $ma_array[$ifIndex . '-' . $vlan . '-' . $mac]['ifIndex'] = $ifIndex;
        $ma_array[$ifIndex . '-' . $vlan . '-' . $mac]['vlan'] = $vlan;
        $ma_array[$ifIndex . '-' . $vlan . '-' . $mac]['mac'] = $mac;
        $ma_array[$ifIndex . '-' . $vlan . '-' . $mac][$oid][$dir] = $value;