示例#1
0
 $permissions = permissions_cache($_SESSION['user_id']);
 include $config['html_dir'] . "/includes/cache-data.inc.php";
 // Need for check permissions
 $use_rss = $_GET['v'] == 'rss' ? TRUE : FALSE;
 // In most cases used ATOM feed
 $param = array('short' => TRUE, 'pagesize' => 25);
 if (is_numeric($_GET['size'])) {
     $param['pagesize'] = $_GET['size'];
 }
 // base feed info
 $base_url = rtrim($GLOBALS['config']['base_url'], '/');
 $feed_generator = OBSERVIUM_PRODUCT . ' ' . OBSERVIUM_VERSION;
 $feed_title = 'Observium [' . $_SERVER["SERVER_NAME"] . '] :: Eventlog Feed';
 $feed_description = "最新的事件日志, 通过Observium 来自 {$base_url}";
 $feed_link = $base_url . '/eventlog/';
 $events = get_events_array($param);
 if ($use_rss) {
     // create rss
     // See format options here: http://validator.w3.org/feed/docs/rss2.html
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"></rss>');
     $xml->addChild('channel');
     $xml->channel->addChild('title', $feed_title);
     $xml->channel->addChild('description', $feed_description);
     $xml->channel->addChild('link', $feed_link);
     $xml->channel->addChild('language', 'en-us');
     $xml->channel->addChild('generator', $feed_generator);
     $xml->channel->addChild('pubDate', date(DATE_RSS, strtotime($events['updated'])));
     $xml->channel->addChild('ttl', '5');
     // a number of minutes that indicates how long a channel can be cached before refreshing
 } else {
     // create atom
示例#2
0
/**
 * Display events.
 *
 * Display pages with device/port/system events on some formats.
 * Examples:
 * print_events() - display last 10 events from all devices
 * print_events(array('pagesize' => 99)) - display last 99 events from all device
 * print_events(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 events from page 3 with pagination header
 * print_events(array('pagesize' => 10, 'device' = 4)) - display last 10 events for device_id 4
 * print_events(array('short' => TRUE)) - show small block with last events
 *
 * @param array $vars
 * @return none
 *
 */
function print_events($vars)
{
    // Get events array
    $events = get_events_array($vars);
    if (!$events['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No eventlog entries found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'port' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'eventlog') {
            $list['device'] = TRUE;
        }
        if ($events['short'] || !isset($vars['port']) || empty($vars['port'])) {
            $list['port'] = TRUE;
        }
        $string = '<table class="table table-bordered table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$events['short']) {
            $string .= '  <thead>' . PHP_EOL;
            $string .= '    <tr>' . PHP_EOL;
            $string .= '      <th>Date</th>' . PHP_EOL;
            if ($list['device']) {
                $string .= '      <th>Device</th>' . PHP_EOL;
            }
            if ($list['port']) {
                $string .= '      <th>Entity</th>' . PHP_EOL;
            }
            $string .= '      <th>Message</th>' . PHP_EOL;
            $string .= '    </tr>' . PHP_EOL;
            $string .= '  </thead>' . PHP_EOL;
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($events['entries'] as $entry) {
            $icon = geteventicon($entry['message']);
            if ($icon) {
                $icon = '<img src="images/16/' . $icon . '" />';
            }
            $string .= '  <tr>' . PHP_EOL;
            if ($events['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= overlib_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td style="width: 160px">';
                $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' => 'eventlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['port']) {
                if ($entry['type'] == 'port') {
                    $this_if = get_port_by_id_cache($entry['reference']);
                    $entry['link'] = '<span class="entity">' . generate_port_link($this_if, short_ifname($this_if['label'])) . '</span>';
                } else {
                    $entry['link'] = ucfirst($entry['type']);
                }
                if (!$events['short']) {
                    $string .= '    <td>' . $entry['link'] . '</td>' . PHP_EOL;
                }
            }
            if ($events['short']) {
                $string .= '    <td class="syslog">' . $entry['link'] . ' ';
            } else {
                $string .= '    <td>';
            }
            $string .= htmlspecialchars($entry['message']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        // Print pagination header
        if ($events['pagination_html']) {
            $string = $events['pagination_html'] . $string . $events['pagination_html'];
        }
        // Print events
        echo $string;
    }
}
/**
 * Display events.
 *
 * Display pages with device/port/system events on some formats.
 * Examples:
 * print_events() - display last 10 events from all devices
 * print_events(array('pagesize' => 99)) - display last 99 events from all device
 * print_events(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 events from page 3 with pagination header
 * print_events(array('pagesize' => 10, 'device' = 4)) - display last 10 events for device_id 4
 * print_events(array('short' => TRUE)) - show small block with last events
 *
 * @param array $vars
 * @return none
 *
 */
function print_events($vars)
{
    global $config;
    // Get events array
    $events = get_events_array($vars);
    if (!$events['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>没有发现事件内容!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'port' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'eventlog') {
            $list['device'] = TRUE;
        }
        if ($events['short'] || !isset($vars['port']) || empty($vars['port'])) {
            $list['entity'] = TRUE;
        }
        $string = '<table class="table table-bordered table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$events['short']) {
            $string .= '  <thead>' . PHP_EOL;
            $string .= '    <tr>' . PHP_EOL;
            $string .= '      <th class="state-marker"></th>' . PHP_EOL;
            $string .= '      <th>日期</th>' . PHP_EOL;
            if ($list['device']) {
                $string .= '      <th>设备</th>' . PHP_EOL;
            }
            if ($list['entity']) {
                $string .= '      <th>单位</th>' . PHP_EOL;
            }
            $string .= '      <th>信息</th>' . PHP_EOL;
            $string .= '    </tr>' . PHP_EOL;
            $string .= '  </thead>' . PHP_EOL;
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($events['entries'] as $entry) {
            #$icon = geteventicon($entry['message']);
            #if ($icon) { $icon = '<img src="images/16/' . $icon . '" />'; }
            switch ($entry['severity']) {
                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 ($events['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= overlib_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td style="width: 160px">';
                $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' => 'eventlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['entity']) {
                if ($entry['entity_type'] == 'device' && !$entry['entity_id']) {
                    $entry['entity_id'] = $entry['device_id'];
                }
                if ($entry['entity_type'] == 'port') {
                    $this_if = get_port_by_id_cache($entry['entity_id']);
                    $entry['link'] = '<span class="entity"><i class="' . $config['entities']['port']['icon'] . '"></i> ' . generate_port_link($this_if, short_ifname($this_if['label'])) . '</span>';
                } else {
                    if (!empty($config['entities'][$entry['entity_type']]['icon'])) {
                        $entry['link'] = '<i class="' . $config['entities'][$entry['entity_type']]['icon'] . '"></i> ' . generate_entity_link($entry['entity_type'], $entry['entity_id']);
                    } else {
                        $entry['link'] = nicecase($entry['entity_type']);
                    }
                }
                if (!$events['short']) {
                    $string .= '    <td>' . $entry['link'] . '</td>' . PHP_EOL;
                }
            }
            if ($events['short']) {
                $string .= '    <td class="syslog">';
                if (strpos($entry['message'], $entry['link']) !== 0) {
                    $string .= $entry['link'] . ' ';
                }
            } else {
                $string .= '    <td>';
            }
            $string .= escape_html($entry['message']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        // Print pagination header
        if ($events['pagination_html']) {
            $string = $events['pagination_html'] . $string . $events['pagination_html'];
        }
        // Print events
        echo $string;
    }
}