示例#1
0
function humanize_port(&$port)
{
    global $config, $cache;
    // Exit if already humanized
    if ($port['humanized']) {
        return;
    }
    // If we can get the device data from the global cache, do it, else pull it from the db (mostly for external scripts)
    if (is_array($GLOBALS['cache']['devices']['id'][$port['device_id']])) {
        $device =& $GLOBALS['cache']['devices']['id'][$port['device_id']];
    } else {
        $device = device_by_id_cache($port['device_id']);
    }
    // Workaround for devices/ports who long time not updated and have empty port_label
    if (empty($port['port_label']) || strlen($port['port_label_base'] . $port['port_label_num']) == 0) {
        process_port_label($port, $device);
    }
    // Set humanised values for use in UI
    $port['human_speed'] = humanspeed($port['ifSpeed']);
    $port['human_type'] = rewrite_iftype($port['ifType']);
    $port['html_class'] = port_html_class($port['ifOperStatus'], $port['ifAdminStatus'], $port['encrypted']);
    $port['human_mac'] = format_mac($port['ifPhysAddress']);
    // Set entity_* values for code which expects them.
    $port['entity_name'] = $port['port_label'];
    $port['entity_shortname'] = $port['port_label_short'];
    $port['entity_descr'] = $port['ifAlias'];
    $port['table_tab_colour'] = "#aaaaaa";
    $port['row_class'] = "";
    $port['icon'] = 'port-ignored';
    // Default
    $port['admin_status'] = $port['ifAdminStatus'];
    if ($port['ifAdminStatus'] == "down") {
        $port['admin_status'] = 'disabled';
        $port['row_class'] = "disabled";
        $port['icon'] = 'port-disabled';
    } elseif ($port['ifAdminStatus'] == "up") {
        $port['admin_status'] = 'enabled';
        switch ($port['ifOperStatus']) {
            case 'up':
                $port['table_tab_colour'] = "#194B7F";
                $port['row_class'] = "up";
                $port['icon'] = 'port-up';
                break;
            case 'monitoring':
                // This is monitoring ([e|r]span) ports
                $port['table_tab_colour'] = "#008C00";
                $port['row_class'] = "success";
                $port['icon'] = 'port-up';
                break;
            case 'down':
                $port['table_tab_colour'] = "#cc0000";
                $port['row_class'] = "error";
                $port['icon'] = 'port-down';
                break;
            case 'lowerLayerDown':
                $port['table_tab_colour'] = "#ff6600";
                $port['row_class'] = "warning";
                $port['icon'] = 'port-down';
                break;
            case 'testing':
            case 'unknown':
            case 'dormant':
            case 'notPresent':
                $port['table_tab_colour'] = "#85004b";
                $port['row_class'] = "info";
                $port['icon'] = 'port-ignored';
                break;
        }
    }
    // If the device is down, colour the row/tab as 'warning' meaning that the entity is down because of something below it.
    if ($device['status'] == '0') {
        $port['table_tab_colour'] = "#ff6600";
        $port['row_class'] = "warning";
        $port['icon'] = 'port-ignored';
    }
    $port['in_rate'] = $port['ifInOctets_rate'] * 8;
    $port['out_rate'] = $port['ifOutOctets_rate'] * 8;
    // Colour in bps based on speed if > 50, else by UI convention.
    if ($port['ifSpeed'] > 0) {
        $in_perc = round($port['in_rate'] / $port['ifSpeed'] * 100);
        $out_perc = round($port['out_rate'] / $port['ifSpeed'] * 100);
    } else {
        // exclude division by zero error
        $in_perc = 0;
        $out_perc = 0;
    }
    if ($port['in_rate'] == 0) {
        $port['bps_in_style'] = '';
    } elseif ($in_perc < '50') {
        $port['bps_in_style'] = 'color: #008C00;';
    } else {
        $port['bps_in_style'] = 'color: ' . percent_colour($in_perc) . '; ';
    }
    // Colour out bps based on speed if > 50, else by UI convention.
    if ($port['out_rate'] == 0) {
        $port['bps_out_style'] = '';
    } elseif ($out_perc < '50') {
        $port['bps_out_style'] = 'color: #394182;';
    } else {
        $port['bps_out_style'] = 'color: ' . percent_colour($out_perc) . '; ';
    }
    // Colour in and out pps based on UI convention
    $port['pps_in_style'] = $port['ifInUcastPkts_rate'] == 0 ? '' : 'color: #740074;';
    $port['pps_out_style'] = $port['ifOutUcastPkts_rate'] == 0 ? '' : 'color: #FF7400;';
    $port['humanized'] = TRUE;
    /// Set this so we can check it later.
}
示例#2
0
        <th style="width: 150px;">Device</th>
        <th style="width: 100px;">Interface</th>
        <th style="width: 100px;">Speed</th>
        <th style="width: 100px;">Circuit</th>
        <th>Notes</th>
      </tr>
  </thead>

<?php 
foreach (dbFetchRows("SELECT * FROM `ports` WHERE `port_descr_type` = 'cust' GROUP BY `port_descr_descr` ORDER BY `port_descr_descr`") as $customer) {
    $customer_name = $customer['port_descr_descr'];
    foreach (dbFetchRows("SELECT * FROM `ports` WHERE `port_descr_type` = 'cust' AND `port_descr_descr` = ?", array($customer['port_descr_descr'])) as $port) {
        $device = device_by_id_cache($port['device_id']);
        unset($class);
        $ifname = rewrite_ifname($device['ifDescr']);
        $ifclass = port_html_class($port['ifOperStatus'], $port['ifAdminStatus'], $port['encrypted']);
        if ($device['os'] == "ios") {
            if ($port['ifTrunk']) {
                $vlan = "<span class=small><span class=red>" . $port['ifTrunk'] . "</span></span>";
            } elseif ($port['ifVlan']) {
                $vlan = "<span class=small><span class=blue>VLAN " . $port['ifVlan'] . "</span></span>";
            } else {
                $vlan = "";
            }
        }
        echo '
           <tr>
             <td style="width: 250px;"><span style="font-weight: bold;" class="interface">' . $customer_name . '</span></td>
             <td style="width: 150px;">' . generate_device_link($device) . '</td>
             <td style="width: 100px;">' . generate_port_link($port, short_ifname($port['ifDescr'])) . '</td>
             <td style="width: 100px;">' . $port['port_descr_speed'] . '</td>
 /**
  * @dataProvider providerIfclass
  */
 public function testIfclass($ifOperStatus, $ifAdminStatus, $result)
 {
     $this->assertSame($result, port_html_class($ifOperStatus, $ifAdminStatus));
 }