예제 #1
0
/**
 * Display neighbours.
 *
 * Display pages with device neighbours in some formats.
 * Examples:
 * print_neighbours() - display all neighbours from all devices
 * print_neighbours(array('pagesize' => 99)) - display 99 neighbours from all device
 * print_neighbours(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 neighbours from page 3 with pagination header
 * print_neighbours(array('pagesize' => 10, 'device' = 4)) - display 10 neighbours for device_id 4
 *
 * @param array $vars
 * @return none
 *
 */
function print_neighbours($vars)
{
    // Get neighbours array
    $neighbours = get_neighbours_array($vars);
    if (!$neighbours['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No neighbours found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE);
        if ($vars['page'] != 'device') {
            $list['device'] = TRUE;
        }
        if (in_array($vars['graph'], array('bits', 'upkts', 'nupkts', 'pktsize', 'percent', 'errors', 'etherlike', 'fdb_count'))) {
            $graph_types = array($vars['graph']);
        } else {
            $graph_types = array('bits', 'upkts', 'errors');
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
        $cols = array(array(NULL, 'class="state-marker"'), 'device_a' => 'Local Device', 'port_a' => 'Local Port', 'NONE' => NULL, 'device_b' => 'Remote Device', 'port_b' => 'Remote Port', 'protocol' => 'Protocol');
        if (!$list['device']) {
            unset($cols[0], $cols['device_a']);
        }
        $string .= get_table_header($cols, $vars);
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($neighbours['entries'] as $entry) {
            $string .= '  <tr class="' . $entry['row_class'] . '">' . PHP_EOL;
            if ($list['device']) {
                $string .= '   <td class="state-marker"></td>';
                $string .= '    <td class="entity">' . generate_device_link($entry, NULL, array('tab' => 'ports', 'view' => 'neighbours')) . '</td>' . PHP_EOL;
            }
            $string .= '    <td><span class="entity">' . generate_port_link($entry) . '</span><br />' . $entry['ifAlias'] . '</td>' . PHP_EOL;
            $string .= '    <td><i class="icon-resize-horizontal text-success"></i></td>' . PHP_EOL;
            if (is_numeric($entry['remote_port_id']) && $entry['remote_port_id']) {
                $remote_port = get_port_by_id_cache($entry['remote_port_id']);
                $remote_device = device_by_id_cache($remote_port['device_id']);
                $string .= '    <td><span class="entity">' . generate_device_link($remote_device) . '</span><br />' . $remote_device['hardware'] . '</td>' . PHP_EOL;
                $string .= '    <td><span class="entity">' . generate_port_link($remote_port) . '</span><br />' . $remote_port['ifAlias'] . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td><span class="entity">' . $entry['remote_hostname'] . '</span><br />' . $entry['remote_platform'] . '</td>' . PHP_EOL;
                $string .= '    <td><span class="entity">' . $entry['remote_port'] . '</span></td>' . PHP_EOL;
            }
            $string .= '    <td>' . strtoupper($entry['protocol']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Print pagination header
        if ($neighbours['pagination_html']) {
            $string = $neighbours['pagination_html'] . $string . $neighbours['pagination_html'];
        }
        // Print
        echo $string;
    }
}
예제 #2
0
function print_mempool_table($vars)
{
    global $cache;
    $sql = build_mempool_query($vars);
    $mempools = array();
    foreach (dbFetchRows($sql) as $mempool) {
        if (isset($cache['devices']['id'][$mempool['device_id']])) {
            $mempool['hostname'] = $cache['devices']['id'][$mempool['device_id']]['hostname'];
            $mempool['html_row_class'] = $cache['devices']['id'][$mempool['device_id']]['html_row_class'];
            $mempools[] = $mempool;
        }
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'usage':
            $mempools = array_sort_by($mempools, 'mempool_perc', $sort_neg, SORT_NUMERIC);
            break;
        case 'used':
            $mempools = array_sort_by($mempools, 'mempool_' . $vars['sort'], $sort_neg, SORT_NUMERIC);
            break;
        default:
            $mempools = array_sort_by($mempools, 'hostname', $sort_order, SORT_STRING, 'mempool_descr', $sort_order, SORT_STRING);
            break;
    }
    $mempools_count = count($mempools);
    // Pagination
    $pagination_html = pagination($vars, $mempools_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $mempools = array_chunk($mempools, $vars['pagesize']);
        $mempools = $mempools[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_mempool_table_header($vars);
    foreach ($mempools as $mempool) {
        print_mempool_row($mempool, $vars);
    }
    echo "</tbody></table>";
    echo generate_box_close();
    echo $pagination_html;
}
예제 #3
0
/**
 * Display authentication log.
 *
 * @param array $vars
 * @return none
 *
 */
function print_authlog($vars)
{
    $authlog = get_authlog_array($vars);
    if (!$authlog['count']) {
        // There have been no entries returned. Print the warning. Shouldn't happen, how did you get here without auth?!
        print_warning('<h4>No authentication entries found!</h4>');
    } else {
        $string = generate_box_open($vars['header']);
        // Entries have been returned. Print the table.
        $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED_MORE . '">' . PHP_EOL;
        $cols = array('date' => array('Date', 'style="width: 150px;"'), 'user' => 'User', 'from' => 'From', 'ua' => array('User-Agent', 'style="width: 200px;"'), 'NONE' => 'Action');
        if ($vars['page'] == 'preferences') {
            unset($cols['user']);
        }
        $string .= get_table_header($cols);
        //, $vars); // Currently sorting is not available
        $string .= '<tbody>' . PHP_EOL;
        foreach ($authlog['entries'] as $entry) {
            if (strlen($entry['user_agent']) > 1) {
                $entry['detect_browser'] = detect_browser($entry['user_agent']);
                //r($entry['detect_browser']);
                $entry['user_agent'] = '<i class="' . $entry['detect_browser']['icon'] . '"></i>&nbsp;' . $entry['detect_browser']['browser_full'];
                if ($entry['detect_browser']['platform']) {
                    $entry['user_agent'] .= ' (' . $entry['detect_browser']['platform'] . ')';
                }
            }
            if (strstr(strtolower($entry['result']), 'fail', true)) {
                $class = " class=\"error\"";
            } else {
                $class = "";
            }
            $string .= '
      <tr' . $class . '>
        <td>' . $entry['datetime'] . '</td>';
            if (isset($cols['user'])) {
                $string .= '
        <td>' . escape_html($entry['user']) . '</td>';
            }
            $string .= '
        <td>' . ($_SESSION['userlevel'] > 5 ? generate_popup_link('ip', $entry['address']) : preg_replace('/^\\d+/', '*', $entry['address'])) . '</td>
        <td>' . $entry['user_agent'] . '</td>
        <td>' . $entry['result'] . '</td>
      </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Add pagination header
        if ($authlog['pagination_html']) {
            $string = $authlog['pagination_html'] . $string . $authlog['pagination_html'];
        }
        // Print authlog
        echo $string;
    }
}
예제 #4
0
function print_printersupplies_table($vars)
{
    $supplies = array();
    foreach (dbFetchRows(build_printersupplies_query($vars)) as $supply) {
        global $cache;
        if (isset($cache['devices']['id'][$supply['device_id']])) {
            $supply['hostname'] = $cache['devices']['id'][$supply['device_id']]['hostname'];
            $supply['html_row_class'] = $cache['devices']['id'][$supply['device_id']]['html_row_class'];
            $supplies[] = $supply;
        }
    }
    $supplies = array_sort_by($supplies, 'hostname', SORT_ASC, SORT_STRING, 'supply_descr', SORT_ASC, SORT_STRING);
    $supplies_count = count($supplies);
    echo generate_box_open();
    // Pagination
    $pagination_html = pagination($vars, $supplies_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $supplies = array_chunk($supplies, $vars['pagesize']);
        $supplies = $supplies[$vars['pageno'] - 1];
    }
    // End Pagination
    if ($vars['view'] == "graphs") {
        $stripe_class = "table-striped-two";
    } else {
        $stripe_class = "table-striped";
    }
    // Allow the table to be printed headerless for use in some places.
    if ($vars['headerless'] != TRUE) {
        echo '<table class="table ' . $stripe_class . '  table-condensed">';
        echo '  <thead>';
        echo '<tr class="strong">';
        echo '<th class="state-marker"></th>';
        echo '<th></th>';
        if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
            echo '      <th style="width: 250px;">Device</th>';
        }
        echo '<th>Toner</th>';
        if (!isset($vars['supply'])) {
            echo '<th>Type</th>';
        }
        echo '<th></th>';
        echo '<th>Level</th>';
        echo '<th>Remaining</th>';
        echo '</tr>';
        echo '</thead>';
    }
    foreach ($supplies as $supply) {
        print_printersupplies_row($supply, $vars);
    }
    echo "</table>";
    echo generate_box_close();
    echo $pagination_html;
}
예제 #5
0
function print_p2pradio_table($vars)
{
    if ($vars['view'] == "graphs" || isset($vars['graph'])) {
        $stripe_class = "table-striped-two";
    } else {
        $stripe_class = "table-striped";
    }
    echo generate_box_open();
    echo '<table class="table table-hover ' . $stripe_class . '  table-condensed">';
    print_p2pradio_table_header($vars);
    $sql = generate_p2pradio_query($vars);
    $radios = dbFetchRows($sql);
    foreach ($radios as $radio) {
        print_p2pradio_row($radio, $vars);
    }
    echo '</table>';
    echo generate_box_close();
}
예제 #6
0
         $device = device_by_id_cache($port['device_id']);
         echo '<tr><td style="width: 1px;"></td>
             <td style="width: 200px; overflow: hidden;"><i class="' . $config['entities']['device']['icon'] . '"></i> ' . generate_entity_link('device', $device) . '</td>
             <td style="overflow: hidden;"><i class="' . $config['entities']['port']['icon'] . '"></i> ' . generate_entity_link('port', $port) . '
             <small>' . $port['ifDescr'] . '</small></td>
           </tr>';
     }
     echo '</table>' . PHP_EOL;
 } else {
     echo '<p class="text-center text-warning bg-warning" style="padding: 10px; margin: 0px;"><strong>This user currently has no permitted ports</strong></p>';
     //print_warning('This user currently has no permitted ports');
 }
 echo generate_box_close();
 // End port permissions
 // Start sensor permissions
 echo generate_box_open(array('header-border' => TRUE, 'title' => 'Sensor Permissions'));
 if (count($user_permissions['sensor'])) {
     echo '<table class="' . OBS_CLASS_TABLE . '">' . PHP_EOL;
     foreach (array_keys($user_permissions['sensor']) as $entity_id) {
         $sensor = get_entity_by_id_cache('sensor', $entity_id);
         $device = device_by_id_cache($sensor['device_id']);
         echo '<tr><td style="width: 1px;"></td>
               <td style="width: 200px; overflow: hidden;"><i class="' . $config['entities']['device']['icon'] . '"></i> ' . generate_entity_link('device', $device) . '</td>
               <td style="overflow: hidden;"><i class="' . $config['entities']['sensor']['icon'] . '"></i> ' . generate_entity_link('sensor', $sensor) . '
               <td width="25">
             </tr>';
     }
     echo '</table>' . PHP_EOL;
 } else {
     echo '<p class="text-center text-warning bg-warning" style="padding: 10px; margin: 0px;"><strong>This user currently has no permitted sensors</strong></p>';
     //print_warning('This user currently has no permitted sensors');
예제 #7
0
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
register_html_title("Poller/Discovery Timing");
$rrd_file = $config['rrd_dir'] . '/poller-wrapper.rrd';
if (is_file($rrd_file) && $_SESSION['userlevel'] >= 7) {
    echo generate_box_open(array('header-border' => TRUE, 'title' => 'Poller Wrapper History'));
    $graph_array = array('type' => 'poller_wrapper_threads', 'width' => 1158, 'height' => 100, 'from' => $config['time']['week'], 'to' => $config['time']['now']);
    echo generate_graph_tag($graph_array);
    //echo "<h3>Poller wrapper Total time</h3>";
    $graph_array = array('type' => 'poller_wrapper_times', 'width' => 1158, 'height' => 100, 'from' => $config['time']['week'], 'to' => $config['time']['now']);
    echo generate_graph_tag($graph_array);
    echo generate_box_close(array('footer_content' => '<b>Please note:</b> The total time for the poller wrapper is not the same as the timings below. Total poller wrapper time is real polling time for all devices and all threads.'));
}
echo generate_box_open(array('header-border' => TRUE, 'title' => 'Poller/Discovery Timing'));
echo '<table class="' . OBS_CLASS_TABLE_STRIPED_MORE . '">' . PHP_EOL;
?>

  <thead>
    <tr>
      <th class="state-marker"></th>
      <th>Device</th>
      <th colspan="3">Last Polled</th>
      <th></th>
      <th colspan="3">Last Discovered</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
<?php 
예제 #8
0
<?php 
$form = array('type' => 'horizontal', 'id' => 'logalert_rule', 'title' => 'New Syslog Rule Details', 'icon' => 'oicon-gear');
$form['row'][1]['name'] = array('type' => 'text', 'name' => 'Rule Name', 'placeholder' => TRUE, 'width' => '250px', 'value' => $vars['name']);
$form['row'][2]['descr'] = array('type' => 'textarea', 'name' => 'Message', 'placeholder' => TRUE, 'class' => 'col-md-11 col-xs-11', 'rows' => 4, 'value' => $vars['descr']);
$form['row'][3]['regex'] = array('type' => 'textarea', 'name' => 'Regular Expression', 'placeholder' => TRUE, 'class' => 'col-md-11 col-xs-11', 'rows' => 4, 'value' => $vars['regex']);
$form['row'][7]['submit'] = array('type' => 'submit', 'name' => 'Add Rule', 'icon' => 'icon-plus icon-white', 'class' => 'btn-success', 'value' => 'add_alertlog_rule');
print_form($form);
unset($form);
?>

  </div>
  <div class="col-md-4">

<?php 
$box_args = array('title' => 'Syslog Regular Expressions', 'header-border' => TRUE, 'padding' => TRUE);
echo generate_box_open($box_args);
echo <<<SYSLOG_RULES
    <p><strong>Syslog Rules</strong> are built using standard PCRE regular expressions.</p>
    <p>There are many online resources to help you learn and test regular expressions.
       Good resources include <a href="https://regex101.com/">regex101.com</a>,
       <a href="https://www.debuggex.com/cheatsheet/regex/pcre">Debuggex Cheatsheet</a>,
       <a href="http://regexr.com/">regexr.com</a> and <a href="http://www.tutorialspoint.com/php/php_regular_expression.htm">Tutorials Point</a>.
       There are many other sites with examples which can be found online.
    <p>A simple rule to match the word "error" could look like:</p>
    <code>/error/</code>
    <p>A more complex rule to match SSH authentication failures from PAM for the users root or adama might look like:</p>
    <code>/pam.+\\(sshd:auth\\).+failure.+user\\=(root|adama)/</code>
SYSLOG_RULES;
echo generate_box_close();
?>
예제 #9
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
$cbqos_array = dbFetchRows('SELECT * FROM `ports_cbqos` WHERE `port_id` = ?', array($port['port_id']));
foreach ($cbqos_array as $cbqos) {
    echo generate_box_open(array('title' => $cbqos['policy_name'] . ' / ' . $cbqos['object_name'] . ' (' . $cbqos['direction'] . ')'));
    echo '<table class="table table-hover table-condensed  table-striped">';
    $graph_array['id'] = $cbqos['cbqos_id'];
    echo '<tr><td>';
    echo '<h3>Packets</h3>';
    $graph_array['type'] = 'cbqos_pkts';
    print_graph_row($graph_array);
    echo '<h3>Bits</h3>';
    $graph_array['type'] = 'cbqos_bits';
    print_graph_row($graph_array);
    echo '</td></tr>';
    echo '</table>';
    echo generate_box_close();
}
// EOF
예제 #10
0
/**
 * Display IPv4/IPv6 addresses.
 *
 * Display pages with IP addresses from device Interfaces.
 *
 * @param array $vars
 * @return none
 *
 */
function print_addresses($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    if (in_array($vars['search'], array('6', 'v6', 'ipv6')) || in_array($vars['view'], array('6', 'v6', 'ipv6'))) {
        $address_type = 'ipv6';
    } else {
        $address_type = 'ipv4';
    }
    $ip_array = array();
    $param = array();
    $where = ' WHERE 1 ';
    $param_netscaler = array();
    $where_netscaler = " WHERE `vsvr_ip` != '0.0.0.0' AND `vsvr_ip` != '' ";
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'I.device_id');
                    $where_netscaler .= generate_query_values($value, 'N.device_id');
                    break;
                case 'interface':
                    $where .= generate_query_values($value, 'I.ifDescr', 'LIKE%');
                    break;
                case 'network':
                    list($net, $mask) = explode('/', $value);
                    if (is_numeric(stripos($net, ':abcdef'))) {
                        $address_type = 'ipv6';
                    }
                    $where .= generate_query_values($value, 'N.ip_network', 'LIKE%');
                    break;
                case 'address':
                    list($addr, $mask) = explode('/', $value);
                    if (is_numeric(stripos($addr, ':abcdef'))) {
                        $address_type = 'ipv6';
                    }
                    switch ($address_type) {
                        case 'ipv6':
                            $ip_valid = Net_IPv6::checkIPv6($addr);
                            break;
                        case 'ipv4':
                            $ip_valid = Net_IPv4::validateIP($addr);
                            break;
                    }
                    if ($ip_valid) {
                        // If address valid -> seek occurrence in network
                        if (!$mask) {
                            $mask = $address_type === 'ipv4' ? '32' : '128';
                        }
                        $where_netscaler .= generate_query_values($addr, 'N.vsvr_ip');
                    } else {
                        // If address not valid -> seek LIKE
                        $where .= generate_query_values($addr, 'A.ip_address', '%LIKE%');
                        $where_netscaler .= generate_query_values($addr, 'N.vsvr_ip', '%LIKE%');
                    }
                    break;
            }
        }
    }
    $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D'));
    $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    // Also search netscaler Vserver IPs
    $query_netscaler = 'FROM `netscaler_vservers` AS N ';
    $query_netscaler .= 'LEFT JOIN `devices` AS D ON N.`device_id` = D.`device_id` ';
    $query_netscaler .= $where_netscaler . $query_device_permitted;
    //$query_netscaler_count = 'SELECT COUNT(`vsvr_id`) ' . $query_netscaler;
    $query_netscaler = 'SELECT * ' . $query_netscaler;
    $query_netscaler .= ' ORDER BY N.`vsvr_ip`';
    // Override by address type
    if ($address_type == 'ipv6') {
        $query_netscaler = str_replace(array('vsvr_ip', '0.0.0.0'), array('vsvr_ipv6', '0:0:0:0:0:0:0:0'), $query_netscaler);
        //$query_netscaler_count = str_replace(array('vsvr_ip', '0.0.0.0'), array('vsvr_ipv6', '0:0:0:0:0:0:0:0'), $query_netscaler_count);
    }
    $entries = dbFetchRows($query_netscaler, $param_netscaler);
    // Rewrite netscaler addresses
    foreach ($entries as $entry) {
        $ip_address = $address_type == 'ipv4' ? $entry['vsvr_ip'] : $entry['vsvr_' . $address_type];
        $ip_network = $address_type == 'ipv4' ? $entry['vsvr_ip'] . '/32' : $entry['vsvr_' . $address_type] . '/128';
        $ip_array[] = array('type' => 'netscaler_vsvr', 'device_id' => $entry['device_id'], 'hostname' => $entry['hostname'], 'vsvr_id' => $entry['vsvr_id'], 'vsvr_label' => $entry['vsvr_label'], 'ifAlias' => 'Netscaler: ' . $entry['vsvr_type'] . '/' . $entry['vsvr_entitytype'], $address_type . '_address' => $ip_address, $address_type . '_network' => $ip_network);
    }
    //print_message($query_netscaler_count);
    $query = 'FROM `ip_addresses` AS A ';
    $query .= 'LEFT JOIN `ports`   AS I ON I.`port_id`   = A.`port_id` ';
    $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` ';
    $query .= 'LEFT JOIN `ip_networks` AS N ON N.`ip_network_id` = A.`ip_network_id` ';
    $query .= $where . $query_port_permitted;
    //$query_count = 'SELECT COUNT(`ip_address_id`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY A.`ip_address`';
    if ($ip_valid) {
        $pagination = FALSE;
    }
    // Override by address type
    $query = str_replace(array('ip_address', 'ip_network'), array($address_type . '_address', $address_type . '_network'), $query);
    //$query_count = str_replace(array('ip_address', 'ip_network'), array($address_type.'_address', $address_type.'_network'), $query_count);
    // Query addresses
    $entries = dbFetchRows($query, $param);
    $ip_array = array_merge($ip_array, $entries);
    $ip_array = array_sort($ip_array, $address_type . '_address');
    // Query address count
    //if ($pagination) { $count = dbFetchCell($query_count, $param); }
    if ($pagination) {
        $count = count($ip_array);
        $ip_array = array_slice($ip_array, $start, $pagesize);
    }
    $list = array('device' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    $string = generate_box_open($vars['header']);
    $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED . '">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        $string .= '      <th>Interface</th>' . PHP_EOL;
        $string .= '      <th>Address</th>' . PHP_EOL;
        $string .= '      <th>Description</th>' . PHP_EOL;
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($ip_array as $entry) {
        $address_show = TRUE;
        if ($ip_valid) {
            // If address not in specified network, don't show entry.
            if ($address_type === 'ipv4') {
                $address_show = Net_IPv4::ipInNetwork($entry[$address_type . '_address'], $addr . '/' . $mask);
            } else {
                $address_show = Net_IPv6::isInNetmask($entry[$address_type . '_address'], $addr, $mask);
            }
        }
        if ($address_show) {
            list($prefix, $length) = explode('/', $entry[$address_type . '_network']);
            if (port_permitted($entry['port_id']) || $entry['type'] == 'netscaler_vsvr') {
                if ($entry['type'] == 'netscaler_vsvr') {
                    $entity_link = generate_entity_link($entry['type'], $entry);
                } else {
                    humanize_port($entry);
                    if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                        $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
                    }
                    $entity_link = generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error;
                }
                $device_link = generate_device_link($entry);
                $string .= '  <tr>' . PHP_EOL;
                if ($list['device']) {
                    $string .= '    <td class="entity" style="white-space: nowrap">' . $device_link . '</td>' . PHP_EOL;
                }
                $string .= '    <td class="entity">' . $entity_link . '</td>' . PHP_EOL;
                if ($address_type === 'ipv6') {
                    $entry[$address_type . '_address'] = Net_IPv6::compress($entry[$address_type . '_address']);
                }
                $string .= '    <td>' . generate_popup_link('ip', $entry[$address_type . '_address'] . '/' . $length) . '</td>' . PHP_EOL;
                $string .= '    <td>' . $entry['ifAlias'] . '</td>' . PHP_EOL;
                $string .= '  </tr>' . PHP_EOL;
            }
        }
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print addresses
    echo $string;
}
예제 #11
0
/**
 * Display alert_table entries.
 *
 * @param array $vars
 * @return none
 *
 */
function print_alert_table($vars)
{
    global $alert_rules;
    global $config;
    // This should be set outside, but do it here if it isn't
    if (!is_array($alert_rules)) {
        $alert_rules = cache_alert_rules();
    }
    /// WARN HERE
    if (isset($vars['device']) && !isset($vars['device_id'])) {
        $vars['device_id'] = $vars['device'];
    }
    if (isset($vars['entity']) && !isset($vars['entity_id'])) {
        $vars['entity_id'] = $vars['entity'];
    }
    // Short? (no pagination, small out)
    $short = isset($vars['short']) && $vars['short'];
    list($query, $param, $query_count) = build_alert_table_query($vars);
    // Fetch alerts
    $count = dbFetchCell($query_count, $param);
    $alerts = dbFetchRows($query, $param);
    // Set which columns we're going to show.
    // We hide the columns that have been given as search options via $vars
    $list = array('device_id' => FALSE, 'entity_id' => FALSE, 'entity_type' => FALSE, 'alert_test_id' => FALSE);
    foreach ($list as $argument => $nope) {
        if (!isset($vars[$argument]) || empty($vars[$argument]) || $vars[$argument] == "all") {
            $list[$argument] = TRUE;
        }
    }
    if ($vars['format'] != "condensed") {
        $list['checked'] = TRUE;
        $list['changed'] = TRUE;
        $list['alerted'] = TRUE;
    }
    if ($vars['short'] == TRUE) {
        $list['checked'] = FALSE;
        $list['alerted'] = FALSE;
    }
    // Hide device if we know entity_id
    if (isset($vars['entity_id'])) {
        $list['device_id'] = FALSE;
    }
    // Hide entity_type if we know the alert_test_id
    if (isset($vars['alert_test_id']) || TRUE) {
        $list['entity_type'] = FALSE;
    }
    // Hide entity types in favour of icons to save space
    if ($vars['pagination'] && !$short) {
        $pagination_html = pagination($vars, $count);
        echo $pagination_html;
    }
    echo generate_box_open($vars['header']);
    echo '<table class="table table-condensed  table-striped  table-hover">';
    if ($vars['no_header'] == FALSE) {
        echo '
  <thead>
    <tr>
      <th class="state-marker"></th>
      <th style="width: 1px;"></th>';
        if ($list['device_id']) {
            echo '      <th style="width: 15%">Device</th>';
        }
        if ($list['entity_type']) {
            echo '      <th style="width: 10%">Type</th>';
        }
        if ($list['entity_id']) {
            echo '      <th style="">Entity</th>';
        }
        if ($list['alert_test_id']) {
            echo '      <th style="min-width: 15%;">Alert</th>';
        }
        echo '
      <th style="width: 100px;">Status</th>';
        if ($list['checked']) {
            echo '      <th style="width: 95px;">Checked</th>';
        }
        if ($list['changed']) {
            echo '      <th style="width: 95px;">Changed</th>';
        }
        if ($list['alerted']) {
            echo '      <th style="width: 95px;">Alerted</th>';
        }
        echo '    <th style="width: 45px;"></th>
    </tr>
  </thead>';
    }
    echo '<tbody>' . PHP_EOL;
    foreach ($alerts as $alert) {
        // Process the alert entry, generating colours and classes from the data
        humanize_alert_entry($alert);
        // Get the entity array using the cache
        $entity = get_entity_by_id_cache($alert['entity_type'], $alert['entity_id']);
        // Get the device array using the cache
        $device = device_by_id_cache($alert['device_id']);
        // Get the entity_name.
        ### FIXME - This is probably duplicated effort from above. We should pass it $entity
        $entity_name = entity_name($alert['entity_type'], $entity);
        // Set the alert_rule from the prebuilt cache array
        $alert_rule = $alert_rules[$alert['alert_test_id']];
        echo '<tr class="' . $alert['html_row_class'] . '" style="cursor: pointer;" onclick="openLink(\'' . generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $alert['alert_table_id'])) . '\')">';
        echo '<td class="state-marker"></td>';
        echo '<td style="width: 1px;"></td>';
        // If we know the device, don't show the device
        if ($list['device_id']) {
            echo '<td><span class="entity-title">' . generate_device_link($device) . '</span></td>';
        }
        // If we're showing all entity types, print the entity type here
        if ($list['entity_type']) {
            echo '<td>' . nicecase($alert['entity_type']) . '</td>';
        }
        // Print a link to the entity
        if ($list['entity_id']) {
            echo '<td><span class="entity-title"><i class="' . $config['entities'][$alert['entity_type']]['icon'] . '"></i> ' . generate_entity_link($alert['entity_type'], $alert['entity_id']) . '</span></td>';
        }
        // Print link to the alert rule page
        if ($list['alert_test_id']) {
            echo '<td class="entity"><a href="', generate_url(array('page' => 'alert_check', 'alert_test_id' => $alert_rule['alert_test_id'])), '">', escape_html($alert_rule['alert_name']), '</a></td>';
        }
        echo '<td>';
        echo '<span class="label label-' . ($alert['html_row_class'] != 'up' ? $alert['html_row_class'] : 'success') . '">' . generate_tooltip_link('', $alert['status'], '<div class="small" style="max-width: 500px;"><strong>' . $alert['last_message'] . '</strong></div>', $alert['alert_class']) . '</span>';
        echo '</td>';
        // echo('<td class="'.$alert['class'].'">'.$alert['last_message'].'</td>');
        if ($list['checked']) {
            echo '<td>' . generate_tooltip_link('', $alert['checked'], format_unixtime($alert['last_checked'], 'r')) . '</td>';
        }
        if ($list['changed']) {
            echo '<td>' . generate_tooltip_link('', $alert['changed'], format_unixtime($alert['last_changed'], 'r')) . '</td>';
        }
        if ($list['alerted']) {
            echo '<td>' . generate_tooltip_link('', $alert['alerted'], format_unixtime($alert['last_alerted'], 'r')) . '</td>';
        }
        echo '<td>';
        // This stuff should go in an external entity popup in the future.
        $state = json_decode($alert['state'], true);
        $alert['state_popup'] = '';
        if (count($state['failed'])) {
            $alert['state_popup'] .= generate_box_open(array('title' => 'Failed Tests'));
            //'<h4>Failed Tests</h4>';
            $alert['state_popup'] .= '<table style="min-width: 400px;" class="table   table-striped table-condensed">';
            $alert['state_popup'] .= '<thead><tr><th>Metric</th><th>Cond</th><th>Value</th><th>Measured</th></tr></thead>';
            foreach ($state['failed'] as $test) {
                $alert['state_popup'] .= '<tr><td><strong>' . $test['metric'] . '</strong></td><td>' . $test['condition'] . '</td><td>' . $test['value'] . '</td><td><i class="red">' . $state['metrics'][$test['metric']] . '</i></td></tr>';
            }
            $alert['state_popup'] .= '</table>';
            $alert['state_popup'] .= generate_box_close();
        }
        $alert['state_popup'] .= generate_entity_popup_graphs($alert, array('entity_type' => 'alert_entry'));
        // Print (i) icon with popup of state.
        echo overlib_link("", '<i class="icon-info-sign text-primary"></i>', $alert['state_popup'], NULL);
        echo '&nbsp;&nbsp;<a href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $alert['alert_table_id'])) . '"><i class="icon-cog text-muted"></i></a>';
        echo '</td>';
        echo '</tr>';
    }
    echo '  </tbody>' . PHP_EOL;
    echo '</table>' . PHP_EOL;
    echo generate_box_close();
    if ($vars['pagination'] && !$short) {
        echo $pagination_html;
    }
}
예제 #12
0
<?php
*/
/// End options navbar
echo generate_graph_js_state($graph_array);
echo generate_box_open();
echo generate_graph_tag($graph_array);
echo generate_box_close();
if (!empty($graph_return['descr'])) {
    echo generate_box_open(array('title' => 'Description', 'padding' => TRUE));
    echo $graph_return['descr'];
    echo generate_box_close();
}
#print_vars($graph_return);
if (isset($vars['showcommand'])) {
    echo generate_box_open(array('title' => 'Performance &amp; Output', 'padding' => TRUE));
    echo "RRDTool Output: " . $graph_return['output'] . "<br />\n          RRDtool Runtime: " . number_format($graph_return['runtime'], 3) . "s |\n          Total time: " . number_format($graph_return['total'], 3) . "s";
    echo generate_box_close();
    echo generate_box_open(array('title' => 'RRDTool Command', 'padding' => TRUE));
    echo $graph_return['command'];
    echo generate_box_close();
    echo generate_box_open(array('title' => 'RRDTool Files Used', 'padding' => TRUE));
    if (is_array($graph_return['rrds'])) {
        foreach ($graph_return['rrds'] as $rrd) {
            echo "{$rrd} <br />";
        }
    } else {
        echo "No RRD information returned. This may be because the graph module doesn't yet return this data. <br />";
    }
    echo generate_box_close();
}
// EOF
예제 #13
0
/**
 * Pretty print for xml string
 *
 * @param string $xml An xml string
 * @param boolean $formatted Convert or not output to human formatted xml
 */
function print_xml($xml, $formatted = TRUE)
{
    if ($formatted) {
        $xml = format_xml($xml);
    }
    if (is_cli()) {
        echo $xml;
    } else {
        echo generate_box_open(array('title' => 'Output', 'padding' => TRUE));
        echo '
    <pre class="prettyprint lang-xml small">' . escape_html($xml) . '</pre>
    <span><em>NOTE: XML values are always escaped, that\'s why you can see this <mark>' . escape_html(escape_html('< > & " \'')) . '</mark> instead of this <mark>' . escape_html('< > & " \'') . '</mark>. <u>Leave them as is</u>.</em></span>
    <script type="text/javascript">window.prettyPrint && prettyPrint();</script>' . PHP_EOL;
        echo generate_box_close();
    }
}
예제 #14
0
     unset($as);
     unset($astext);
     unset($asn);
 }
 $name = format_mac($acc['mac']);
 if (!isset($vars['graph'])) {
     $vars['graph'] = "bits";
 }
 $graph_type = "macaccounting_" . $vars['graph'];
 if ($vars['subview'] == "minigraphs") {
     if (!$asn) {
         $asn = "No Session";
     }
     $graph_array = array('id' => $acc['ma_id'], 'type' => $graph_type, 'from' => $config['time']['twoday'], 'to' => $config['time']['now'], 'width' => '215', 'height' => '100');
     echo '<div class="col-md-3">';
     echo generate_box_open(array('title' => $name, 'header-border' => TRUE));
     print_graph_popup($graph_array);
     echo generate_box_close(array());
     echo '</div>';
 } else {
     echo "\n        <tr>\n          <td width=20></td>\n          <td width=200><bold>" . format_mac($acc['mac']) . "</bold></td>\n          <td width=200>" . implode($ips, "<br />") . "</td>\n          <td width=500>" . $name . " " . $arp_name . "</td>\n          <td width=100>" . formatRates($acc['bytes_input_rate'] / 8) . "</td>\n          <td width=100>" . formatRates($acc['bytes_output_rate'] / 8) . "</td>\n          <td width=100>" . format_number($acc['pkts_input_rate'] / 8) . "pps</td>\n          <td width=100>" . format_number($acc['pkts_output_rate'] / 8) . "pps</td>\n        </tr>\n    ";
     $peer_info['astext'];
     if ($vars['subview'] == "graphs") {
         $graph_array['type'] = $graph_type;
         $graph_array['id'] = $acc['ma_id'];
         $graph_array['height'] = "100";
         $graph_array['to'] = $config['time']['now'];
         echo '<tr><td colspan="8">';
         print_graph_row($graph_array);
         echo "</td></tr>";
         $i++;
예제 #15
0
/**
 * Display syslog messages.
 *
 * Display pages with device syslog messages.
 * Examples:
 * print_syslogs() - display last 10 syslog messages from all devices
 * print_syslogs(array('pagesize' => 99)) - display last 99 syslog messages from all device
 * print_syslogs(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 syslog messages from page 3 with pagination header
 * print_syslogs(array('pagesize' => 10, 'device' = 4)) - display last 10 syslog messages for device_id 4
 * print_syslogs(array('short' => TRUE)) - show small block with last syslog messages
 *
 * @param array $vars
 * @return none
 *
 */
function print_syslogs($vars)
{
    // Short events? (no pagination, small out)
    $short = isset($vars['short']) && $vars['short'];
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $priorities = $GLOBALS['config']['syslog']['priorities'];
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            $cond = array();
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'priority':
                    if (!is_array($value)) {
                        $value = explode(',', $value);
                    }
                    foreach ($value as $k => $v) {
                        // Rewrite priority strings to numbers
                        $value[$k] = priority_string_to_numeric($v);
                    }
                    // Do not break here, it's true!
                // Do not break here, it's true!
                case 'program':
                    $where .= generate_query_values($value, $var);
                    break;
                case 'message':
                    $where .= generate_query_values($value, 'msg', '%LIKE%');
                    break;
                case 'timestamp_from':
                    $where .= ' AND `timestamp` > ?';
                    $param[] = $value;
                    break;
                case 'timestamp_to':
                    $where .= ' AND `timestamp` < ?';
                    $param[] = $value;
                    break;
            }
        }
    }
    // Show events only for permitted devices
    $query_permitted = generate_query_permitted();
    $query = 'FROM `syslog` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY `seq` DESC ';
    $query .= "LIMIT {$start},{$pagesize}";
    // Query syslog messages
    $entries = dbFetchRows($query, $param);
    // Query syslog count
    if ($pagination && !$short) {
        $count = dbFetchCell($query_count, $param);
    } else {
        $count = count($entries);
    }
    if (!$count) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No syslog entries found!</h4>
Check that the syslog daemon and Observium configuration options are set correctly, that your devices are configured to send syslog to Observium and that there are no firewalls blocking the messages.

See <a href="' . OBSERVIUM_URL . '/wiki/Category:Documentation" target="_blank">documentation</a> and <a href="' . OBSERVIUM_URL . '/wiki/Configuration_Options#Syslog_Settings" target="_blank">configuration options</a> for more information.');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'priority' => TRUE);
        // For now (temporarily) priority always displayed
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'syslog') {
            $list['device'] = TRUE;
        }
        if ($short || !isset($vars['priority']) || empty($vars['priority'])) {
            $list['priority'] = TRUE;
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED_MORE . '">' . PHP_EOL;
        if (!$short) {
            $string .= '  <thead>' . PHP_EOL;
            $string .= '    <tr>' . PHP_EOL;
            $string .= '      <th class="state-marker"></th>' . PHP_EOL;
            #    $string .= '      <th></th>' . PHP_EOL;
            $string .= '      <th>Date</th>' . PHP_EOL;
            if ($list['device']) {
                $string .= '      <th>Device</th>' . PHP_EOL;
            }
            if ($list['priority']) {
                $string .= '      <th>Priority</th>' . PHP_EOL;
            }
            $string .= '      <th>Message</th>' . PHP_EOL;
            $string .= '    </tr>' . PHP_EOL;
            $string .= '  </thead>' . PHP_EOL;
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($entries as $entry) {
            switch ($entry['priority']) {
                case "0":
                    // Emergency
                // Emergency
                case "1":
                    // Alert
                // Alert
                case "2":
                    // Critical
                // Critical
                case "3":
                    // Error
                    $entry['html_row_class'] = "error";
                    break;
                case "4":
                    // Warning
                    $entry['html_row_class'] = "warning";
                    break;
                case "5":
                    // Notification
                    $entry['html_row_class'] = "recovery";
                    break;
                case "6":
                    // Informational
                    $entry['html_row_class'] = "up";
                    break;
                case "7":
                    // Debugging
                    $entry['html_row_class'] = "suppressed";
                    break;
                default:
            }
            $string .= '  <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL;
            $string .= '<td class="state-marker"></td>' . PHP_EOL;
            if ($short) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= generate_tooltip_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td width="130">';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'syslog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['priority']) {
                if (!$short) {
                    $string .= '    <td style="color: ' . $priorities[$entry['priority']]['color'] . '; white-space: nowrap; width: 95px;"><span class="label label-' . $priorities[$entry['priority']]['label-class'] . '">' . nicecase($priorities[$entry['priority']]['name']) . ' (' . $entry['priority'] . ')</span></td>' . PHP_EOL;
                }
            }
            $entry['program'] = empty($entry['program']) ? '[[EMPTY]]' : $entry['program'];
            if ($short) {
                $string .= '    <td class="syslog">';
                $string .= '<span class="label label-' . $priorities[$entry['priority']]['label-class'] . '"><strong>' . $entry['program'] . '</strong></span> ';
            } else {
                $string .= '    <td>';
                $string .= '<span class="label label-' . $priorities[$entry['priority']]['label-class'] . '">' . $entry['program'] . '</span>';
            }
            $string .= escape_html($entry['msg']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>' . PHP_EOL;
        $string .= generate_box_close();
        // Print pagination header
        if ($pagination && !$short) {
            $string = pagination($vars, $count) . $string . pagination($vars, $count);
        }
        // Print syslog
        echo $string;
    }
}
예제 #16
0
function generate_entity_popup_header($entity, $vars)
{
    $translate = entity_type_translate_array($vars['entity_type']);
    $vars['popup'] = TRUE;
    $vars['entity_icon'] = TRUE;
    switch ($vars['entity_type']) {
        case "sensor":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_sensor_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "toner":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_toner_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "bgp_peer":
            if ($entity['peer_device_id']) {
                $peer_dev = device_by_id_cache($entity['peer_device_id']);
                $peer_name = '<br /><a class="entity" style="font-weight: bold;">' . $peer_dev['hostname'] . '</a>';
            } else {
                if ($entity['reverse_dns']) {
                    $peer_name = '<br /><span style="font-weight: bold;">' . $entity['reverse_dns'] . '</span>';
                }
            }
            $astext = '<span>AS' . $entity['bgpPeerRemoteAs'];
            if ($entity['astext']) {
                $astext .= '<br />' . $entity['astext'] . '</span>';
            }
            $astext .= '</span>';
            $contents .= generate_box_open();
            $contents .= '
      <table class="' . OBS_CLASS_TABLE . '">
        <tr class="' . $entity['row_class'] . ' vertical-align" style="font-size: 10pt;">
          <td class="state-marker"></td>
          <td style="width: 10px;"></td>
          <td style="width: 10px;"><i class="' . $translate['icon'] . '"></i></td>
          <td><a class="entity-popup" style="font-size: 15px; font-weight: bold;">' . $entity['entity_shortname'] . '</a>' . $peer_name . '</td>
          <td class="text-nowrap" style="width: 20%;">' . $astext . '</td>
          <td></td>
        </tr>
      </table>';
            $contents .= generate_box_close();
            break;
        case "sla":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_sla_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "processor":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_processor_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "mempool":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_mempool_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "p2pradio":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_p2pradio_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "status":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_status_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "storage":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_storage_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "netscalervsvr":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_netscalervsvr_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "netscalersvc":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_netscalersvc_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "netscalersvcgrpmem":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_netscalersvcmem_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        default:
            entity_rewrite($vars['entity_type'], $entity);
            $contents = generate_box_open() . '
      <table class="' . OBS_CLASS_TABLE_STRIPED . '">
        <tr class="' . $entity['row_class'] . '" style="font-size: 10pt;">
          <td class="state-marker"></td>
          <td style="width: 10px;"></td>
          <td width="400"><i class="' . $translate['icon'] . '" style="margin-right: 10px;"></i> <a class="entity-popup" style="font-size: 15px; font-weight: bold;">' . $entity['entity_name'] . '</a></td>
          <td width="100"></td>
          <td></td>
        </tr>
      </table>' . generate_box_close();
    }
    return $contents;
}
예제 #17
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage web
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function print_storage_table($vars)
{
    global $cache, $config;
    $graph_type = "storage_usage";
    $sql = "SELECT *, `storage`.`storage_id` AS `storage_id` FROM `storage`";
    $sql .= " LEFT JOIN `storage-state` USING(`storage_id`)";
    $sql .= ' WHERE 1' . generate_query_permitted(array('device'));
    // Build query
    if (!isset($vars['ignored'])) {
        $vars['ignored'] = 0;
    }
    foreach ($vars as $var => $value) {
        switch ($var) {
            case "group":
            case "group_id":
                $values = get_group_entities($value);
                $sql .= generate_query_values($values, 'storage.storage_id');
                break;
            case "device":
            case "device_id":
                $sql .= generate_query_values($value, 'storage.device_id');
                break;
            case 'ignored':
                $sql .= generate_query_values($value, 'storage.storage_ignore');
                break;
        }
    }
    $storages = array();
    foreach (dbFetchRows($sql) as $storage) {
        if (isset($cache['devices']['id'][$storage['device_id']])) {
            $storage['hostname'] = $cache['devices']['id'][$storage['device_id']]['hostname'];
            $storage['html_row_class'] = $cache['devices']['id'][$storage['device_id']]['html_row_class'];
            $storages[] = $storage;
        }
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'usage':
            $storages = array_sort_by($storages, 'storage_perc', $sort_neg, SORT_NUMERIC);
            break;
        case 'mountpoint':
            $storages = array_sort_by($storages, 'storage_descr', $sort_order, SORT_STRING);
            break;
        case 'size':
        case 'free':
        case 'used':
            $storages = array_sort_by($storages, 'storage_' . $vars['sort'], $sort_neg, SORT_NUMERIC);
            break;
        default:
            $storages = array_sort_by($storages, 'hostname', $sort_order, SORT_STRING, 'storage_descr', $sort_order, SORT_STRING);
            break;
    }
    $storages_count = count($storages);
    // Pagination
    $pagination_html = pagination($vars, $storages_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $storages = array_chunk($storages, $vars['pagesize']);
        $storages = $storages[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_storage_table_header($vars);
    foreach ($storages as $storage) {
        print_storage_row($storage, $vars);
    }
    echo "</tbody></table>";
    echo generate_box_close();
    echo $pagination_html;
}
예제 #18
0
// Pretty inefficient looping everything if section != all, but meh
// This is only done on this page, so there is no performance issue for the rest of Observium
foreach ($config_subsections as $section => $subdata) {
    if (isset($config_sections[$section]['edition']) && $config_sections[$section]['edition'] != OBSERVIUM_EDITION) {
        // Skip sections not allowed for current Observium edition
        continue;
    }
    echo '  <div class="row"> <div class="col-md-12"> <!-- BEGIN SECTION ' . $section . ' -->' . PHP_EOL;
    if ($vars['section'] == 'all' || $vars['section'] == $section) {
        if ($vars['section'] == 'all') {
            // When printing all, also print the section name
            echo generate_box_open(array('title' => $config_sections[$section]['text'], 'header-border' => TRUE));
            echo generate_box_close();
        }
        foreach ($subdata as $subsection => $vardata) {
            echo generate_box_open(array('title' => $subsection, 'header-border' => TRUE));
            echo '  <table class="table table-striped table-condensed" style="">' . PHP_EOL;
            $cols = array(array(NULL, 'class="state-marker"'), array(NULL, 'style="width: 0px;"'), array('Description', 'style="width: 40%;"'), array(NULL, 'style="width: 50px;"'), 'Configuration Value', array('Use DB', 'style="width: 75px;"'));
            echo get_table_header($cols);
            foreach ($vardata as $varname => $variable) {
                if (isset($variable['edition']) && $variable['edition'] != OBSERVIUM_EDITION) {
                    // Skip variables not allowed for current Observium edition
                    continue;
                }
                $linetype = '';
                // Check if this variable is set in SQL
                if (sql_to_array($varname, $database_config) !== FALSE) {
                    $sqlset = 1;
                    $linetype = '';
                    $content = sql_to_array($varname, $database_config, FALSE);
                } else {
예제 #19
0
/**
 * Display events.
 *
 * Display pages with alert logs in multiple formats.
 * Examples:
 * print_alert_log() - display last 10 events from all devices
 * print_alert_log(array('pagesize' => 99)) - display last 99 events from all device
 * print_alert_log(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 events from page 3 with pagination header
 * print_alert_log(array('pagesize' => 10, 'device' = 4)) - display last 10 events for device_id 4
 * print_alert_log(array('short' => TRUE)) - show small block with last events
 *
 * @param array $vars
 * @return none
 *
 */
function print_alert_log($vars)
{
    global $alert_rules, $config;
    // This should be set outside, but do it here if it isn't
    if (!is_array($alert_rules)) {
        $alert_rules = cache_alert_rules();
    }
    // Get events array
    $events = get_alert_log($vars);
    if (!$events['count']) {
        if (!$vars['no_empty_message']) {
            // There have been no entries returned. Print the warning.
            print_message('<h4>No alert log entries found!</h4>', FALSE);
        }
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'entity' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'alert_log') {
            $list['device'] = TRUE;
        }
        if ($events['short'] || !isset($vars['entity']) || empty($vars['entity'])) {
            $list['entity'] = TRUE;
        }
        if (!isset($vars['alert_test_id']) || empty($vars['alert_test_id']) || $vars['page'] == 'alert_check' || TRUE) {
            $list['alert_test_id'] = TRUE;
        }
        if (!isset($vars['entity_type']) || empty($vars['entity_type']) || $vars['page'] == 'alert_check' || TRUE) {
            $list['entity_type'] = TRUE;
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="table table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$events['short']) {
            $cols = array();
            $cols[] = array(NULL, 'class="state-marker"');
            $cols['date'] = array('Date', 'style="width: 160px"');
            if ($list['device']) {
                $cols['device'] = 'Device';
            }
            if ($list['alert_test_id']) {
                $cols['alert_test_id'] = 'Alert Check';
            }
            if ($list['entity']) {
                $cols['entity'] = 'Entity';
            }
            $cols[] = 'Message';
            $cols['status'] = 'Status';
            $cols['notified'] = array('Notified', 'style="width: 40px"');
            $string .= get_table_header($cols);
            // , $vars); // Actually sorting is disabled now
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($events['entries'] as $entry) {
            $alert_rule = $alert_rules[$entry['alert_test_id']];
            // Functionize?
            // Set colours and classes based on the status of the alert
            if ($entry['log_type'] == 'OK') {
                $entry['class'] = "green";
                $entry['html_row_class'] = "success";
            } else {
                if ($entry['log_type'] == 'RECOVER_NOTIFY') {
                    $entry['class'] = "green";
                    $entry['html_row_class'] = "info";
                } else {
                    if ($entry['log_type'] == 'ALERT_NOTIFY') {
                        $entry['class'] = "red";
                        $entry['html_row_class'] = "error";
                    } elseif ($entry['log_type'] == 'FAIL') {
                        $entry['class'] = "red";
                        $entry['html_row_class'] = "error";
                    } elseif ($entry['log_type'] == 'FAIL_DELAYED') {
                        $entry['class'] = "purple";
                        $entry['html_row_class'] = "warning";
                    } elseif ($entry['log_type'] == 'FAIL_SUPPRESSED') {
                        $entry['class'] = "purple";
                        $entry['html_row_class'] = "suppressed";
                    } elseif ($entry['log_type'] == 'RECOVER_SUPPRESSED') {
                        $entry['class'] = "purple";
                        $entry['html_row_class'] = "suppressed";
                    } else {
                        // Anything else set the colour to grey and the class to disabled.
                        $entry['class'] = "gray";
                        $entry['html_row_class'] = "disabled";
                    }
                }
            }
            $string .= '  <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL;
            $string .= '<td class="state-marker"></td>' . PHP_EOL;
            if ($events['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= generate_tooltip_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td>';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'alertlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['alert_test_id']) {
                $string .= '     <td class="entity"><a href="' . generate_url(array('page' => 'alert_check', 'alert_test_id' => $alert_rule['alert_test_id'])) . '">' . escape_html($alert_rule['alert_name']) . '</a></td>';
            }
            if ($list['entity']) {
                $string .= '    <td class="entity">';
                if ($list['entity_type']) {
                    $string .= '<i class="' . $config['entities'][$entry['entity_type']]['icon'] . '"></i> ';
                }
                if ($events['short']) {
                    $string .= '    ' . generate_entity_link($entry['entity_type'], $entry['entity_id'], NULL, NULL, NULL, TRUE) . '</td>' . PHP_EOL;
                } else {
                    $string .= '    ' . generate_entity_link($entry['entity_type'], $entry['entity_id']) . '</td>' . PHP_EOL;
                }
            }
            $string .= '<td>' . escape_html($entry['message']) . '</td>' . PHP_EOL;
            if (!$vars['short']) {
                $string .= '<td>' . escape_html($entry['log_type']) . '</td>' . PHP_EOL;
                $string .= '<td style="text-align: right">' . ($entry['notified'] ? '<span class="label label-success">YES</span>' : '<span class="label">NO</span>') . '</td>' . PHP_EOL;
            }
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Print pagination header
        if ($events['pagination_html']) {
            $string = $events['pagination_html'] . $string . $events['pagination_html'];
        }
        // Print events
        echo $string;
    }
}
예제 #20
0
function print_sla_table($vars)
{
    $sql = generate_sla_query($vars);
    $slas = array();
    foreach (dbFetchRows($sql) as $sla) {
        if (isset($GLOBALS['cache']['devices']['id'][$sla['device_id']])) {
            $sla['hostname'] = $GLOBALS['cache']['devices']['id'][$sla['device_id']]['hostname'];
            $slas[] = $sla;
        }
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'device':
            $slas = array_sort_by($slas, 'hostname', $sort_order, SORT_STRING);
            break;
        case 'descr':
            $slas = array_sort_by($slas, 'sla_index', $sort_order, SORT_STRING, 'sla_tag', $sort_order, SORT_STRING);
            break;
        case 'owner':
            $slas = array_sort_by($slas, 'sla_owner', $sort_order, SORT_STRING);
            break;
        case 'type':
            $slas = array_sort_by($slas, 'rtt_type', $sort_order, SORT_STRING);
            break;
        case 'event':
            $slas = array_sort_by($slas, 'rtt_event', $sort_order, SORT_STRING);
            break;
        case 'sense':
            $slas = array_sort_by($slas, 'rtt_sense', $sort_order, SORT_STRING);
            break;
        case 'last_change':
            $slas = array_sort_by($slas, 'rtt_last_change', $sort_neg, SORT_NUMERIC);
            break;
        case 'rtt':
            $slas = array_sort_by($slas, 'rtt_value', $sort_order, SORT_NUMERIC);
            break;
        default:
            // Not sorted
    }
    $slas_count = count($slas);
    // Pagination
    $pagination_html = pagination($vars, $slas_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $slas = array_chunk($slas, $vars['pagesize']);
        $slas = $slas[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_sla_table_header($vars);
    foreach ($slas as $sla) {
        print_sla_row($sla, $vars);
    }
    echo '</tbody></table>';
    echo generate_box_close();
    echo $pagination_html;
}
예제 #21
0
function print_vm_table($vars)
{
    $sql = generate_vm_query($vars);
    $vms = array();
    foreach (dbFetchRows($sql) as $vm) {
        if (isset($GLOBALS['cache']['devices']['id'][$vm['device_id']])) {
            $vm['hostname'] = $GLOBALS['cache']['devices']['id'][$vm['device_id']]['hostname'];
            $vms[] = $vm;
        }
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'name':
            $vms = array_sort_by($vms, 'vm_name', $sort_order, SORT_STRING);
            break;
        case 'os':
            $vms = array_sort_by($vms, 'vm_os', $sort_order, SORT_STRING);
            break;
        case 'state':
            $vms = array_sort_by($vms, 'vm_state', $sort_order, SORT_STRING);
            break;
        case 'memory':
            $vms = array_sort_by($vms, 'vm_memory', $sort_order, SORT_NUMERIC);
            break;
        case 'cpu':
            $vms = array_sort_by($vms, 'vm_cpucount', $sort_order, SORT_NUMERIC);
            break;
        default:
            // Not sorted
    }
    $vms_count = count($vms);
    // Pagination
    $pagination_html = pagination($vars, $vms_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $vms = array_chunk($vms, $vars['pagesize']);
        $vms = $vms[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_vm_table_header($vars);
    foreach ($vms as $vm) {
        print_vm_row($vm, $vars);
    }
    echo '</tbody></table>';
    echo generate_box_close();
    echo $pagination_html;
}
예제 #22
0
            }
            if ($vars['app_section'] == $app_section) {
                $navbar['options'][$app_section]['class'] = "active";
            }
            $navbar['options'][$app_section]['url'] = generate_url($vars, array('app_section' => $app_section));
            $navbar['options'][$app_section]['text'] = $text;
        }
        print_navbar($navbar);
        unset($navbar);
    } else {
        // It appears this app doesn't have multiple sections. We set app_section to default here.
        $vars['app_section'] = 'default';
    }
    // If a matching app_section array exists within app_graphs, print the graphs.
    if (isset($app_graphs[$vars['app_section']]) && is_array($app_graphs[$vars['app_section']])) {
        echo generate_box_open();
        echo '<table class="table table-striped table-hover  table-condensed">';
        foreach ($app_graphs[$vars['app_section']] as $key => $text) {
            $graph_type = $key;
            $graph_array['to'] = $config['time']['now'];
            $graph_array['id'] = $app['app_id'];
            $graph_array['type'] = "application_" . $key;
            echo '<tr><td>';
            echo '<h3>', $text, '</h4>';
            print_graph_row($graph_array);
            echo '</td></tr>';
        }
        echo '</table>';
        generate_box_close();
    }
}
예제 #23
0
/**
 * Display ARP/NDP table addresses.
 *
 * Display pages with ARP/NDP tables addresses from devices.
 *
 * @param array $vars
 * @return none
 *
 */
function print_arptable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= generate_query_values($value, 'I.port_id');
                    break;
                case 'ip_version':
                    $where .= generate_query_values($value, 'ip_version');
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $value = trim($value);
                        if (strpos($value, ':') !== FALSE) {
                            if (Net_IPv6::checkIPv6($value)) {
                                $value = Net_IPv6::uncompress($value, TRUE);
                            } else {
                                // FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike
                            }
                        }
                        $where .= generate_query_values($value, 'ip_address', '%LIKE%');
                    } else {
                        // MAC Addresses
                        $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                        $where .= generate_query_values($value, 'mac_address', '%LIKE%');
                    }
                    break;
            }
        }
    }
    if (isset($vars['sort'])) {
        switch ($vars['sort']) {
            case "port":
                $sort = " ORDER BY `I`.`port_label`";
                break;
            case "ip_version":
                $sort = " ORDER BY `ip_version`";
                break;
            case "ip":
            case "address":
                $sort = " ORDER BY `ip_address`";
                break;
            case "mac":
            default:
                $sort = " ORDER BY `mac_address`";
        }
    }
    // Show ARP tables only for permitted ports
    $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    $query = 'FROM `ip_mac` AS M ';
    $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = M.`port_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`mac_id`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= $sort;
    $query .= " LIMIT {$start},{$pagesize}";
    // Query ARP/NDP table addresses
    $entries = dbFetchRows($query, $param);
    // Query ARP/NDP table address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    $cols = array('mac' => 'MAC Address', 'ip' => 'IP Address', 'device' => 'Device', 'port' => 'Port', '!remote_device' => 'Remote Device', '!remote_port' => 'Remote Port');
    if (!$list['device']) {
        unset($cols['device']);
    }
    if (!$list['port']) {
        unset($cols['port']);
    }
    if (!$short) {
        $string .= get_table_header($cols, $vars);
        // Currently sorting is not available
    }
    foreach ($entries as $entry) {
        humanize_port($entry);
        $ip_version = $entry['ip_version'];
        $ip_address = $ip_version == 6 ? Net_IPv6::compress($entry['ip_address']) : $entry['ip_address'];
        $arp_host = dbFetchRow('SELECT * FROM `ipv' . $ip_version . '_addresses` AS A
                           LEFT JOIN `ports` AS I ON A.`port_id` = I.`port_id`
                           LEFT JOIN `devices` AS D ON D.`device_id` = I.`device_id`
                           WHERE A.`ipv' . $ip_version . '_address` = ?', array($ip_address));
        $arp_name = $arp_host ? generate_device_link($arp_host) : '';
        $arp_if = $arp_host ? generate_port_link($arp_host) : '';
        if ($arp_host['device_id'] == $entry['device_id']) {
            $arp_name = 'Self Device';
        }
        if ($arp_host['port_id'] == $entry['port_id']) {
            $arp_if = 'Self Port';
        }
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 160px;" class="entity">' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $ip_address) . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
            }
            $string .= '    <td class="entity">' . generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error . '</td>' . PHP_EOL;
        }
        $string .= '    <td class="entity" style="width: 200px;">' . $arp_name . '</td>' . PHP_EOL;
        $string .= '    <td class="entity">' . $arp_if . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print ARP/NDP table
    echo $string;
}
예제 #24
0
function generate_device_popup_header($device, $vars = array())
{
    global $config;
    humanize_device($device);
    if ($device['os'] == "ios") {
        formatCiscoHardware($device, TRUE);
    }
    // FIXME or generic function for more than just IOS? [and/or do this at poll time]
    $contents = generate_box_open() . '
<table class="table table-striped table-rounded table-condensed">
  <tr class="' . $device['html_row_class'] . '" style="font-size: 10pt;">
    <td class="state-marker"></td>
    <td class="vertical-align" style="width: 64px; text-align: center;">' . get_device_icon($device) . '</td>
    <td width="200px"><a href="#" class="' . device_link_class($device) . '" style="font-size: 15px; font-weight: bold;">' . escape_html($device['hostname']) . '</a><br />' . escape_html(truncate($device['location'], 64, '')) . '</td>
    <td>' . escape_html($device['hardware']) . ' <br /> ' . $device['os_text'] . ' ' . escape_html($device['version']) . '</td>
    <td>' . deviceUptime($device, 'short') . '<br />' . escape_html($device['sysName']) . '
  </tr>
</table>
' . generate_box_close();
    return $contents;
}
예제 #25
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage web
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function print_logalert_log($vars)
{
    global $config;
    foreach (dbFetchRows("SELECT * FROM `syslog_rules` ORDER BY `la_name`") as $la) {
        $syslog_rules[$la['la_id']] = $la;
    }
    $entries = get_logalert_log($vars);
    if (!$entries['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No logging alert entries found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'alert_log') {
            $list['device'] = TRUE;
        }
        if (!isset($vars['la_id']) || empty($vars['la_id'])) {
            $list['la_id'] = TRUE;
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="table table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$entries['short']) {
            $cols = array();
            $cols[] = array(NULL, 'class="state-marker"');
            $cols['date'] = array('Date', 'style="width: 140px"');
            if ($list['device']) {
                $cols['device'] = array('Device', 'style="width: 150px;"');
            }
            if ($list['la_id']) {
                $cols['la_id'] = array('Alert Rule', 'style="width: 150px;"');
            }
            $cols[] = array('Program', 'style="width: 80px"');
            $cols[] = 'Message';
            $cols[] = array('Notified', 'style="width: 40px"');
            $string .= get_table_header($cols);
            // , $vars); // Actually sorting is disabled now
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($entries['entries'] as $entry) {
            $string .= '  <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL;
            $string .= '<td class="state-marker"></td>' . PHP_EOL;
            if ($entries['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= generate_tooltip_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td>';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'alertlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['la_id']) {
                $string .= '<td><strong><a href="' . generate_url(array('page' => 'syslog_rules', 'la_id' => $entry['la_id'])) . '">' . (is_array($syslog_rules[$entry['la_id']]) ? $syslog_rules[$entry['la_id']]['la_name'] : 'Rule Deleted') . '</td>' . PHP_EOL;
            }
            $string .= '<td>' . (strlen($entry['program']) ? '<span class="label">' . $entry['program'] . '</span> ' : '') . '</td>' . PHP_EOL;
            $string .= '<td>' . escape_html($entry['message']) . '</td>' . PHP_EOL;
            if (!$vars['short']) {
                //$string .= '<td>' . escape_html($entry['log_type']) . '</td>' . PHP_EOL;
                $string .= '<td style="text-align: right">' . ($entry['notified'] == '1' ? '<span class="label label-success">YES</span>' : ($entry['notified'] == '-1' ? '<span class="label label-suppressed">NO</span>' : '<span class="label">NO</span>')) . '</td>' . PHP_EOL;
            }
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
    }
    // Print pagination header
    if ($entries['pagination_html']) {
        $string = $entries['pagination_html'] . $string . $entries['pagination_html'];
    }
    // Print events
    echo $string;
}
예제 #26
0
/**
 * Display dot1x sessions
 *
 * @param array $vars
 * @return none
 *
 */
function print_dot1xtable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $value = trim($value);
                        $where .= generate_query_values($value, 'ipv4_addr', '%LIKE%');
                    } else {
                        if (isset($vars['searchby']) && $vars['searchby'] == 'mac') {
                            $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                            $where .= generate_query_values($value, 'M.mac_addr', '%LIKE%');
                        } else {
                            $value = trim($value);
                            $where .= generate_query_values($value, 'username', '%LIKE%');
                        }
                    }
                    break;
            }
        }
    }
    // Check permissions
    $query_permitted = generate_query_permitted(array('device'), array('device_table' => 'M'));
    $query = 'FROM `wifi_sessions` AS M ';
    $query .= 'LEFT JOIN `wifi_radios` AS I ON I.`wifi_radio_id` = M.`radio_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`wifi_session_id`) ' . $query;
    $query = 'SELECT *, M.`mac_addr` AS `session_mac` ' . $query;
    $query .= ' ORDER BY M.`timestamp` DESC';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query wireless  sessions table
    $entries = dbFetchRows($query, $param);
    // Query wireless  sessions table count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $aps_db = dbFetchRows("SELECT `wifi_accesspoint_id`, `name`, `ap_number`  FROM `wifi_accesspoints`");
    foreach ($aps_db as $ap_db) {
        $aps_sorted_db[$ap_db['wifi_accesspoint_id']] = $ap_db;
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    // A radio is like a port
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        $string .= '      <th>MAC Address</th>' . PHP_EOL;
        $string .= '      <th>IP Address</th>' . PHP_EOL;
        $string .= '      <th>Username</th>' . PHP_EOL;
        $string .= '      <th>SSID/VLAN</th>' . PHP_EOL;
        $string .= '      <th>Last Seen</th>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '      <th>Interface/AP</th>' . PHP_EOL;
        }
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        $ap_id = $entry['accesspoint_id'];
        $interface = $aps_sorted_db[$ap_id]['name'];
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('mac', format_mac($entry['session_mac'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $entry['ipv4_addr']) . '</td>' . PHP_EOL;
        $string .= '    <td style="white-space: nowrap;">' . $entry['username'] . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . $entry['ssid'] . '</td>' . PHP_EOL;
        $string .= '    <td style="white-space: nowrap;">' . $entry['timestamp'] . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '    <td class="entity"><a href="' . generate_url(array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'wifi', 'view' => 'accesspoint', 'accesspoint' => $ap_id)) . '">' . $interface . '</a></td>' . PHP_EOL;
        }
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print wireless sessions
    echo $string;
}
예제 #27
0
function print_form_box($data, $return = FALSE)
{
    $form_id = isset($data['id']) ? $data['id'] : 'form-' . strgen();
    $form_class = 'form form-horizontal';
    if (isset($data['style'])) {
        $form_style = ' style="' . $data['style'] . '"';
    } else {
        $form_style = ' style="margin-bottom:0;"';
    }
    $base_class = array_key_exists('class', $data) ? $data['class'] : 'box';
    $base_space = $data['space'] ? $data['space'] : '15px';
    $used_vars = array();
    // Cache permissions to session var
    permissions_cache_session();
    //r($_SESSION['cache']);
    if ($data['submit_by_key']) {
        $action = '';
        if ($data['url']) {
            $action .= 'this.form.prop(\'action\', form_to_path(\'' . $form_id . '\'));';
        }
        register_html_resource('script', '$(function(){$(\'form#' . $form_id . '\').each(function(){$(this).find(\'input\').keypress(function(e){if(e.which==10||e.which==13){' . $action . 'this.form.submit();}});});});');
    }
    $header = '';
    if (isset($data['title'])) {
        $header .= '  <h2>' . $data['title'] . '</h2>' . PHP_EOL;
    }
    // Form elements
    $div_begin = '<div class="row">' . PHP_EOL;
    $div_end = '</div>' . PHP_EOL;
    if ($data['type'] == 'horizontal') {
        $row_style = '';
        $fieldset = array();
        foreach ($data['row'] as $k => $row) {
            $row_group = $k;
            $row_elements = '';
            $row_label = '';
            $row_control_group = FALSE;
            $i = 0;
            foreach ($row as $id => $element) {
                $used_vars[] = $id;
                $element['id'] = $id;
                if ($element['fieldset']) {
                    $row_group = $element['fieldset'];
                    // Add this element to group
                }
                // Additional element options for horizontal specific form
                switch ($element['type']) {
                    case 'hidden':
                        $div_class = '';
                        $div_style = '';
                        break;
                    case 'submit':
                        $div_class = 'form-actions';
                        $div_style = ' style="margin: 0px;"';
                        break;
                    case 'text':
                    case 'input':
                    case 'password':
                    case 'textarea':
                    default:
                        $row_control_group = TRUE;
                        // In horizontal, name always placed at left
                        if (!isset($element['placeholder'])) {
                            $element['placeholder'] = TRUE;
                        }
                        if ($i < 1) {
                            // Add laber for first element in row
                            $row_label = '    <label class="control-label" for="' . $element['id'] . '">' . $element['name'] . '</label>' . PHP_EOL;
                            $row_control_id = $element['id'] . '_div';
                        }
                        $div_class = 'controls';
                        $div_style = '';
                        break;
                }
                if (!isset($element['div_class'])) {
                    $element['div_class'] = $div_class;
                }
                //if ($element['right'])
                //{
                //  $element['div_class'] .= ' pull-right';
                //}
                if ($id == 'search' && $data['url']) {
                    // Add form_id here, for generate onclick action in submit button
                    $element['form_id'] = $form_id;
                }
                $row_elements .= generate_form_element($element);
                $i++;
            }
            if ($element['div_class']) {
                // no additional divs if empty div class (hidden element for example)
                $row_elements = $row_label . PHP_EOL . '    <div class="' . $element['div_class'] . '"' . $div_style . '>' . PHP_EOL . $row_elements . '    </div>' . PHP_EOL;
            } else {
                $row_label = str_replace(' class="control-label"', '', $row_label);
                $row_elements = $row_label . PHP_EOL . $row_elements;
            }
            if ($row_control_group) {
                $fieldset[$row_group] .= '  <div id="' . $row_control_id . '" class="control-group"> <!-- START row-' . $k . ' -->' . PHP_EOL;
                $fieldset[$row_group] .= $row_elements;
                $fieldset[$row_group] .= '  </div> <!-- END row-' . $k . ' -->' . PHP_EOL;
            } else {
                // Do not add control group for submit/hidden
                $fieldset[$row_group] .= $row_elements;
            }
            //$row_style = 'style="margin-top: '.$base_space.';"'; // Add space between rows
        }
        $divs = array();
        $fieldset_tooltip = '';
        foreach ($data['fieldset'] as $group => $entry) {
            if (isset($fieldset[$group])) {
                if (!is_array($entry)) {
                    $entry = array('title' => $entry);
                }
                // Custom style
                if (!isset($entry['style'])) {
                    $entry['style'] = 'padding-bottom: 0px !important;';
                    // Remove last additional padding space
                }
                // Combinate fieldsets into common rows
                if ($entry['div']) {
                    $divs[$entry['div']][] = $group;
                } else {
                    $divs['row'][] = $group;
                }
                $box_args = array('header-border' => TRUE, 'padding' => TRUE, 'id' => $group);
                if (isset($entry['style'])) {
                    $box_args['body-style'] = $entry['style'];
                }
                if (isset($entry['title'])) {
                    $box_args['title'] = $entry['title'];
                    if ($entry['icon']) {
                        // $box_args['icon'] => $entry['icon'];
                    }
                }
                if (isset($entry['tooltip'])) {
                    $box_args['header-controls'] = array('controls' => array('tooltip' => array('icon' => 'icon-info text-primary', 'anchor' => TRUE, 'class' => 'tooltip-from-element', 'data' => 'data-tooltip-id="tooltip-' . $group . '"')));
                    $fieldset_tooltip .= '<div id="tooltip-' . $group . '" style="display: none;">' . PHP_EOL;
                    $fieldset_tooltip .= $entry['tooltip'] . '</div>' . PHP_EOL;
                }
                if (isset($entry['tooltip'])) {
                    $box_args['style'] = $entry['style'];
                }
                $fieldset_begin = generate_box_open($box_args);
                $fieldset_end = generate_box_close();
                // Additional div class if set
                if (isset($entry['class'])) {
                    $fieldset_begin = '<div class="' . $entry['class'] . '">' . PHP_EOL . $fieldset_begin;
                    $fieldset_end .= '</div>' . PHP_EOL;
                }
                $row_elements = $fieldset_begin . '
          <fieldset> <!-- START fieldset-' . $group . ' -->';
                $row_elements .= PHP_EOL . $fieldset[$group] . '
          </fieldset> <!-- END fieldset-' . $group . ' -->' . PHP_EOL;
                $fieldset[$group] = $row_elements . $fieldset_end;
            }
        }
        // Combinate fieldsets into common rows
        foreach ($divs as $entry) {
            $row_elements = $div_begin;
            foreach ($entry as $i => $group) {
                $row_elements .= $fieldset[$group];
                if ($i > 0) {
                    // unset all fieldsets except first one for replace later
                    unset($fieldset[$group]);
                }
            }
            $row_elements .= $div_end;
            // now replace first fieldset in group
            $fieldset[array_shift($entry)] = $row_elements;
        }
        // Final combining elements
        $string_elements = implode('', $fieldset);
    }
    // Remove old vars from url
    if ($data['url']) {
        foreach ($used_vars as $var) {
            $data['url'] = preg_replace('/' . $var . '=[^\\/]+\\/?/', '', $data['url']);
        }
    }
    // Form header
    $string = PHP_EOL . "<!-- START {$form_id} -->" . PHP_EOL;
    $string .= $header;
    $string .= '<form method="POST" id="' . $form_id . '" name="' . $form_id . '" action="' . $data['url'] . '" class="' . $form_class . '"' . $form_style . '>' . PHP_EOL;
    // Form elements
    $string .= $string_elements;
    // Form footer
    $string .= '</form>' . PHP_EOL;
    $string .= $fieldset_tooltip;
    $string .= "<!-- END {$form_id} -->" . PHP_EOL;
    if ($return) {
        // Save generation time for profiling
        $GLOBALS['form_time'] += utime() - $form_start;
        // Return form as string
        return $string;
    } else {
        // Print form
        echo $string;
        // Save generation time for profiling (after echo)
        $GLOBALS['form_time'] += utime() - $form_start;
    }
}
예제 #28
0
function print_status_table($vars)
{
    $sql = generate_status_query($vars);
    $status_list = array();
    foreach (dbFetchRows($sql) as $status) {
        if (isset($GLOBALS['cache']['devices']['id'][$status['device_id']])) {
            $status['hostname'] = $GLOBALS['cache']['devices']['id'][$status['device_id']]['hostname'];
            $status_list[] = $status;
        }
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'device':
            $status_list = array_sort_by($status_list, 'hostname', $sort_order, SORT_STRING);
            break;
        case 'descr':
            $status_list = array_sort_by($status_list, 'status_descr', $sort_order, SORT_STRING);
            break;
        case 'class':
            $status_list = array_sort_by($status_list, 'entPhysicalClass', $sort_order, SORT_STRING);
            break;
        case 'event':
            $status_list = array_sort_by($status_list, 'status_event', $sort_order, SORT_STRING);
            break;
        case 'status':
            $status_list = array_sort_by($status_list, 'status_name', $sort_order, SORT_STRING);
            break;
        case 'last_change':
            $status_list = array_sort_by($status_list, 'status_last_change', $sort_neg, SORT_NUMERIC);
            break;
        default:
            $status_list = array_sort_by($status_list, 'hostname', $sort_order, SORT_STRING, 'status_descr', $sort_order, SORT_STRING);
    }
    $status_count = count($status_list);
    // Pagination
    $pagination_html = pagination($vars, $status_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $status_list = array_chunk($status_list, $vars['pagesize']);
        $status_list = $status_list[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_status_table_header($vars);
    foreach ($status_list as $status) {
        print_status_row($status, $vars);
    }
    echo "</tbody></table>";
    echo generate_box_close();
    echo $pagination_html;
}
예제 #29
0
function show_portpercent($config)
{
    if ($config['frontpage']['portpercent'] != '') {
        echo generate_box_open(array('title' => 'Port Utilization by Type', 'url' => '/groups/entity_type=port/', 'header-border' => TRUE));
        echo '<img src="portpercent-graph.php">';
        echo generate_box_close();
    }
}
예제 #30
0
/**
 * Display bgp peers.
 *
 * Display pages with BGP Peers.
 * Examples:
 * print_bgp() - display all bgp peers from all devices
 * print_bgp(array('pagesize' => 99)) - display 99 bgp peers from all device
 * print_bgp(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 bgp peers from page 3 with pagination header
 * print_bgp(array('pagesize' => 10, 'device' = 4)) - display 10 bgp peers for device_id 4
 *
 * @param array $vars
 * @return none
 *
 */
function print_bgp_table($vars)
{
    // Get bgp peers array
    $entries = get_bgp_array($vars);
    //r($entries);
    if (!$entries['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No BGP peers found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE);
        if ($vars['page'] != 'device') {
            $list['device'] = TRUE;
        }
        switch ($vars['graph']) {
            case 'prefixes_ipv4unicast':
            case 'prefixes_ipv4multicast':
            case 'prefixes_ipv4vpn':
            case 'prefixes_ipv6unicast':
            case 'prefixes_ipv6multicast':
            case 'macaccounting_bits':
            case 'macaccounting_pkts':
            case 'updates':
                $table_class = 'table-striped-two';
                $list['graph'] = TRUE;
                break;
            default:
                $table_class = 'table-striped';
                $list['graph'] = FALSE;
        }
        $string = generate_box_open();
        $string .= '<table class="table  ' . $table_class . ' table-hover table-condensed ">' . PHP_EOL;
        $cols = array(array(NULL, 'class="state-marker"'), array(NULL, 'style="width: 1px;"'), 'device' => array('Local address', 'style="width: 150px;"'), array(NULL, 'style="width: 20px;"'), 'peer_ip' => array('Peer address', 'style="width: 150px;"'), 'type' => array('Type', 'style="width: 50px;"'), array('Family', 'style="width: 50px;"'), 'peer_as' => 'Remote AS', 'state' => 'State', 'Uptime / Updates');
        //if (!$list['device']) { unset($cols['device']); }
        $string .= get_table_header($cols, $vars);
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($entries['entries'] as $peer) {
            $local_dev = device_by_id_cache($peer['device_id']);
            $local_as = $list['device'] ? ' (AS' . $peer['bgpLocalAs'] . ')' : '';
            $local_name = generate_device_link($local_dev, short_hostname($local_dev['hostname'], 18), array('tab' => 'routing', 'proto' => 'bgp'));
            $local_ip = generate_device_link($local_dev, $peer['human_localip'] . $local_as, array('tab' => 'routing', 'proto' => 'bgp'));
            $peer_as = 'AS' . $peer['bgpPeerRemoteAs'];
            if ($peer['peer_device_id']) {
                $peer_dev = device_by_id_cache($peer['peer_device_id']);
                $peer_name = generate_device_link($peer_dev, short_hostname($peer_dev['hostname'], 18), array('tab' => 'routing', 'proto' => 'bgp'));
            } else {
                $peer_name = $peer['reverse_dns'];
            }
            $peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']);
            $peer_afis =& $entries['afisafi'][$peer['device_id']][$peer['bgpPeerRemoteAddr']];
            $peer_afis_html = array();
            foreach ($peer_afis as $peer_afi) {
                $peer_afi_html = '<span class="label-group">';
                switch ($peer_afi['afi']) {
                    case 'ipv4':
                    case 'ipv4z':
                        $afi_class = 'success';
                        break;
                    case 'ipv6':
                    case 'ipv6z':
                        $afi_class = 'primary';
                        break;
                    default:
                        $afi_class = 'default';
                }
                switch ($peer_afi['safi']) {
                    case 'unicast':
                        $safi_class = 'delayed';
                        break;
                    case 'multicast':
                        $safi_class = 'warning';
                        break;
                    case 'vpn':
                        $safi_class = 'suppressed';
                        break;
                    default:
                        $safi_class = 'default';
                }
                $peer_afi_html .= '<span class="label label-' . $afi_class . '">' . $peer_afi['afi'] . '</span>';
                $peer_afi_html .= '<span class="label label-' . $safi_class . '">' . $peer_afi['safi'] . '</span>';
                $peer_afi_html .= '</span>';
                $peer_afis_html[] = $peer_afi_html;
            }
            $string .= '  <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL;
            $string .= '     <td class="state-marker"></td>' . PHP_EOL;
            $string .= '     <td></td>' . PHP_EOL;
            $string .= '     <td style="white-space: nowrap" class="entity">' . $local_ip . '<br />' . $local_name . '</td>' . PHP_EOL;
            $string .= '     <td><span class="text-success"><i class="glyphicon glyphicon-arrow-right"></i></span></td>' . PHP_EOL;
            $string .= '     <td style="white-space: nowrap" class="entity">' . $peer_ip . '<br />' . $peer_name . '</td>' . PHP_EOL;
            $string .= '     <td><span class="label label-' . $peer['peer_type_class'] . '">' . $peer['peer_type'] . '</span></td>' . PHP_EOL;
            $string .= '     <td>' . implode('<br />', $peer_afis_html) . '</td>' . PHP_EOL;
            $string .= '     <td><strong>' . $peer_as . '</strong><br />' . $peer['astext'] . '</td>' . PHP_EOL;
            $string .= '     <td><strong><span class=" label label-' . $peer['admin_class'] . '">' . $peer['bgpPeerAdminStatus'] . '</span><br /><span class="label label-' . $peer['state_class'] . '">' . $peer['bgpPeerState'] . '</span></strong></td>' . PHP_EOL;
            $string .= '     <td style="white-space: nowrap">' . formatUptime($peer['bgpPeerFsmEstablishedTime']) . '<br />
                Updates: <i class="icon-circle-arrow-down text-success"></i> ' . format_si($peer['bgpPeerInUpdates']) . ' <i class="icon-circle-arrow-up text-primary"></i> ' . format_si($peer['bgpPeerOutUpdates']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
            // Graphs
            $peer_graph = FALSE;
            switch ($vars['graph']) {
                case 'prefixes_ipv4unicast':
                case 'prefixes_ipv4multicast':
                case 'prefixes_ipv4vpn':
                case 'prefixes_ipv6unicast':
                case 'prefixes_ipv6multicast':
                    $afisafi = preg_replace('/prefixes_(ipv[46])(\\w+)/', '$1.$2', $vars['graph']);
                    // prefixes_ipv6unicast ->> ipv6.unicast
                    if (isset($peer_afis[$afisafi]) && $peer['bgpPeer_id']) {
                        $graph_array['type'] = 'bgp_' . $vars['graph'];
                        $graph_array['id'] = $peer['bgpPeer_id'];
                        $peer_graph = TRUE;
                    }
                    break;
                case 'updates':
                    if ($peer['bgpPeer_id']) {
                        $graph_array['type'] = 'bgp_updates';
                        $graph_array['id'] = $peer['bgpPeer_id'];
                        $peer_graph = TRUE;
                    }
                    break;
                case 'macaccounting_bits':
                case 'macaccounting_pkts':
                    //FIXME. I really still not know it works or not? -- mike
                    // This part copy-pasted from old code as is
                    $acc = dbFetchRow("SELECT * FROM `mac_accounting` AS M\n                            LEFT JOIN `ip_mac` AS I ON M.mac = I.mac_address\n                            LEFT JOIN `ports` AS P ON P.port_id = M.port_id\n                            LEFT JOIN `devices` AS D ON D.device_id = P.device_id\n                            WHERE I.ip_address = ?", array($peer['bgpPeerRemoteAddr']));
                    $database = get_rrd_path($device, "cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd");
                    if (is_array($acc) && is_file($database)) {
                        $peer_graph = TRUE;
                        $graph_array['id'] = $acc['ma_id'];
                        $graph_array['type'] = $vars['graph'];
                    }
                    break;
            }
            if ($peer_graph) {
                $graph_array['to'] = $config['time']['now'];
                $string .= '  <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL;
                $string .= '    <td class="state-marker"></td><td colspan="10" style="white-space: nowrap">' . PHP_EOL;
                $string .= generate_graph_row($graph_array);
                $string .= '    </td>' . PHP_EOL . '  </tr>' . PHP_EOL;
            } else {
                if ($list['graph']) {
                    // Empty row for correct view class table-striped-two
                    $string .= '  <tr class="' . $peer['html_row_class'] . '"><td class="state-marker"></td><td colspan="10"></td></tr>' . PHP_EOL;
                }
            }
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Print pagination header
        if ($entries['pagination_html']) {
            $string = $entries['pagination_html'] . $string . $entries['pagination_html'];
        }
        // Print
        echo $string;
    }
}