/**
  * @dataProvider providerPercentColour
  */
 public function testPercentColour($value, $brightness, $result)
 {
     if ($brightness === NULL) {
         $this->assertSame($result, percent_colour($value));
     } else {
         $this->assertSame($result, percent_colour($value, $brightness));
     }
 }
echo "</td><td width=100>";
if ($port_details) {
    $port['graph_type'] = "port_bits";
    echo generate_port_link($port, "<img src='graph.php?type=port_bits&amp;id=" . $port['port_id'] . "&amp;from=" . $config['time']['day'] . "&amp;to=" . $config['time']['now'] . "&amp;width=100&amp;height=20&amp;legend=no&amp;bg=" . str_replace("#", "", $row_colour) . "'>");
    $port['graph_type'] = "port_upkts";
    echo generate_port_link($port, "<img src='graph.php?type=port_upkts&amp;id=" . $port['port_id'] . "&amp;from=" . $config['time']['day'] . "&amp;to=" . $config['time']['now'] . "&amp;width=100&amp;height=20&amp;legend=no&amp;bg=" . str_replace("#", "", $row_colour) . "'>");
    $port['graph_type'] = "port_errors";
    echo generate_port_link($port, "<img src='graph.php?type=port_errors&amp;id=" . $port['port_id'] . "&amp;from=" . $config['time']['day'] . "&amp;to=" . $config['time']['now'] . "&amp;width=100&amp;height=20&amp;legend=no&amp;bg=" . str_replace("#", "", $row_colour) . "'>");
}
echo "</td><td width=120>";
if ($port['ifOperStatus'] == "up") {
    $port['in_rate'] = $port['ifInOctets_rate'] * 8;
    $port['out_rate'] = $port['ifOutOctets_rate'] * 8;
    $in_perc = @round($port['in_rate'] / $port['ifSpeed'] * 100);
    $out_perc = @round($port['in_rate'] / $port['ifSpeed'] * 100);
    echo "<img src='images/16/arrow_left.png' align=absmiddle> <span style='color: " . percent_colour($in_perc) . "'>" . formatRates($port['in_rate']) . "<br />\n        <img align=absmiddle src='images/16/arrow_out.png'> <span style='color: " . percent_colour($out_perc) . "'>" . formatRates($port['out_rate']) . "<br />\n        <img src='images/icons/arrow_pps_in.png' align=absmiddle> " . format_bi($port['ifInUcastPkts_rate']) . "pps</span><br />\n        <img src='images/icons/arrow_pps_out.png' align=absmiddle> " . format_bi($port['ifOutUcastPkts_rate']) . "pps</span>";
}
echo "</td><td width=75>";
if ($port['ifSpeed']) {
    echo "<span class=box-desc>" . humanspeed($port['ifSpeed']) . "</span>";
}
echo "<br />";
if ($port[ifDuplex] != "unknown") {
    echo "<span class=box-desc>" . $port['ifDuplex'] . "</span>";
} else {
    echo "-";
}
if ($device['os'] == "ios" || $device['os'] == "iosxe") {
    if ($port['ifTrunk']) {
        echo '<p class=box-desc><span class=purple><a title="';
        $vlans = dbFetchRows("SELECT * FROM `ports_vlans` AS PV, vlans AS V WHERE PV.`port_id` ='" . $port['port_id'] . "' and PV.`device_id` = '" . $device['device_id'] . "' AND V.`vlan_vlan` = PV.vlan AND V.device_id = PV.device_id");
Exemple #3
0
function humanize_port(&$port)
{
    global $config, $cache;
    // Exit if already humanized
    if ($port['humanized']) {
        return;
    }
    // Process port data to make it pretty for printing. EVOLUTION, BITCHES.
    // Lots of hacky shit will end up here with if (os);
    // 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']);
    }
    $os = $device['os'];
    $port['human_speed'] = humanspeed($port['ifSpeed']);
    $port['human_type'] = rewrite_iftype($port['ifType']);
    $port['html_class'] = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
    $port['human_mac'] = format_mac($port['ifPhysAddress']);
    // Here definition override for ifDescr, because Calix switch ifDescr <> ifName since fw 2.2
    // Note, only for 'calix' os now
    if ($os == 'calix') {
        unset($config['os'][$os]['ifname']);
        $version_parts = explode('.', $device['version']);
        if ($version_parts[0] > 2 || $version_parts[0] == 2 && $version_parts[1] > 1) {
            $config['os'][$os]['ifname'] = 1;
        }
    }
    if (isset($config['os'][$os]['ifname'])) {
        if ($port['ifName'] == "") {
            $port['label'] = $port['ifDescr'];
        } else {
            $port['label'] = $port['ifName'];
        }
    } elseif (isset($config['os'][$os]['ifalias'])) {
        $port['label'] = $port['ifAlias'];
    } else {
        $port['label'] = $port['ifDescr'];
        if (isset($config['os'][$os]['ifindex'])) {
            $port['label'] .= ' ' . $port['ifIndex'];
        } else {
            $port['label'] = $port['ifDescr'];
        }
    }
    // Set entity variables for use by code which uses entities
    $port['entity_name'] = $port['label'];
    $port['entity_shortname'] = $port['label'];
    $port['entity_descr'] = $port['ifAlias'];
    if ($device['os'] == "speedtouch") {
        list($port['label']) = explode("thomson", $port['label']);
    }
    $port['table_tab_colour'] = "#aaaaaa";
    $port['row_class'] = "";
    // Default
    $port['admin_status'] = $port['ifAdminStatus'];
    if ($port['ifAdminStatus'] == "down") {
        $port['admin_status'] = 'disabled';
        $port['row_class'] = "warning";
        $port['icon'] = 'port-disabled';
    } elseif ($port['ifAdminStatus'] == "up") {
        $port['admin_status'] = 'enabled';
        switch ($port['ifOperStatus']) {
            case 'down':
                $port['table_tab_colour'] = "#cc0000";
                $port['row_class'] = "error";
                $port['icon'] = 'port-down';
                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 'lowerLayerDown':
                $port['table_tab_colour'] = "#ff6600";
                $port['row_class'] = "warning";
                $port['icon'] = 'port-down';
                break;
            case 'testing':
                $port['table_tab_colour'] = "#85004b";
                $port['row_class'] = "info";
                $port['icon'] = 'port-ignored';
                break;
            case 'up':
                $port['table_tab_colour'] = "#194B7F";
                $port['row_class'] = "";
                $port['icon'] = 'port-up';
                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.
    $in_perc = round($port['in_rate'] / $port['ifSpeed'] * 100);
    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.
    $out_perc = round($port['out_rate'] / $port['ifSpeed'] * 100);
    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.
}
Exemple #4
0
	<th></th>
        <th width="100">Current</th>
        <th width="100">Alert</th>
        <th>Notes</th>
      </tr>';
$row = 1;
while ($temp = mysql_fetch_array($query)) {
    if (is_integer($row / 2)) {
        $row_colour = $list_colour_a;
    } else {
        $row_colour = $list_colour_b;
    }
    $weekly_temp = "graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from={$week}&amp;to={$now}&amp;width=500&amp;height=150";
    $temp_popup = "<a onmouseover=\"return overlib('<img src=\\'{$weekly_temp}\\'>', LEFT);\" onmouseout=\"return nd();\">\n        " . (empty($temp['user_descr']) ? $temp['temp_descr'] : $temp['user_descr']) . "</a>";
    $temp_perc = $temp['temp_current'] / $temp['temp_limit'] * 100;
    $temp_colour = percent_colour($temp_perc);
    if ($temp['temp_current'] >= $temp['temp_limit']) {
        $alert = '<img src="images/16/flag_red.png" alt="alert" />';
    } else {
        $alert = "";
    }
    $temp_day = "graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from={$day}&amp;to={$now}&amp;width=300&amp;height=100";
    $temp_week = "graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from={$week}&amp;to={$now}&amp;width=300&amp;height=100";
    $temp_month = "graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from={$month}&amp;to={$now}&amp;width=300&amp;height=100";
    $temp_year = "graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from={$year}&amp;to={$now}&amp;width=300&amp;height=100";
    $temp_minigraph = "<img src='graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from={$day}&amp;to={$now}&amp;width=100&amp;height=20'";
    $temp_minigraph .= " onmouseover=\"return overlib('<div class=list-large>" . $temp['hostname'] . " - " . (empty($temp['user_descr']) ? $temp['temp_descr'] : $temp['user_descr']);
    $temp_minigraph .= "</div><div style=\\'width: 750px\\'><img src=\\'{$temp_day}\\'><img src=\\'{$temp_week}\\'><img src=\\'{$temp_month}\\'><img src=\\'{$temp_year}\\'></div>', RIGHT" . $config['overlib_defaults'] . ");\" onmouseout=\"return nd();\" >";
    echo "<tr bgcolor={$row_colour}>\n          <td class=list-bold>" . generatedevicelink($temp) . "</td>\n          <td>{$temp_popup}</td>\n\t  <td>{$temp_minigraph}</td>\n\t  <td width=100>{$alert}</td>\n          <td style='color: {$temp_colour}; text-align: center; font-weight: bold;'>" . $temp['temp_current'] . " &deg;C</td>\n          <td style='text-align: center'>" . $temp['temp_limit'] . " &deg;C</td>\n          <td>" . (isset($temp['temp_notes']) ? $temp['temp_notes'] : '') . "</td>\n        </tr>\n";
    $row++;
}
Exemple #5
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.
}