function generate_sensor_row($sensor, $vars) { global $config; humanize_sensor($sensor); $table_cols = 4; $graph_array = array(); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $sensor['sensor_id']; $graph_array['type'] = "sensor_graph"; $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; $graph_array['from'] = $config['time']['day']; if ($sensor['sensor_event'] && is_numeric($sensor['sensor_value'])) { $mini_graph = generate_graph_tag($graph_array); } else { // Do not show "Draw Error" minigraph $mini_graph = ''; } $row = ' <tr class="' . $sensor['row_class'] . '"> <td class="state-marker"></td>'; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $row .= ' <td class="entity">' . generate_device_link($sensor) . '</td>' . PHP_EOL; $table_cols++; } if ($vars['entity_icon'] == TRUE) { $row .= ' <td width="20px"><i class="' . $config['sensor_types'][$sensor['sensor_class']]['icon'] . '"></i></td>'; } $row .= ' <td class="entity">' . generate_entity_link("sensor", $sensor) . '</td>'; if ($vars['show_class']) { $row .= ' <td>' . nicecase($sensor['sensor_class']) . '</td>' . PHP_EOL; $table_cols++; } if ($vars['tab'] != 'overview') { $row .= ' <td><span class="label ' . ($sensor['sensor_custom_limit'] ? 'label-warning' : '') . '">' . $sensor['sensor_thresholds'] . '</span></td>' . PHP_EOL; $table_cols++; } $row .= ' <td style="width: 90px; text-align: right;">' . generate_entity_link('sensor', $sensor, $mini_graph, NULL, FALSE) . '</td>'; if ($vars['tab'] != 'overview') { $row .= ' <td style="white-space: nowrap">' . generate_tooltip_link(NULL, formatUptime($config['time']['now'] - $sensor['sensor_last_change'], 'short-2') . ' ago', format_unixtime($sensor['sensor_last_change'])) . '</td>'; $table_cols++; $row .= ' <td style="text-align: right;"><strong><span class="' . $sensor['state_class'] . '">' . $sensor['sensor_event'] . '</span></strong></td>'; $table_cols++; } $row .= ' <td style="width: 80px; text-align: right;"><strong><span class="' . $sensor['state_class'] . '">' . $sensor['human_value'] . $sensor['sensor_symbol'] . '</span></strong> </tr>' . PHP_EOL; if ($vars['view'] == "graphs" || $vars['id'] == $sensor['sensor_id']) { $vars['graph'] = "graph"; } if ($vars['graph']) { $row .= ' <tr class="' . $sensor['row_class'] . '"> <td class="state-marker"></td> <td colspan="' . $table_cols . '">'; $graph_array = array(); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $sensor['sensor_id']; $graph_array['type'] = 'sensor_' . $vars['graph']; $row .= generate_graph_row($graph_array, TRUE); $row .= '</td></tr>'; } # endif graphs return $row; }
function generate_sla_row($sla, $vars) { global $config; humanize_sla($sla); $table_cols = "8"; $graph_array = array(); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $sla['sla_id']; $graph_array['type'] = $sla['graph_type']; $graph_array['legend'] = "no"; $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; $graph_array['from'] = $config['time']['day']; if ($sla['rtt_event'] && $sla['rtt_sense']) { $mini_graph = generate_graph_tag($graph_array); } else { // Do not show "Draw Error" minigraph $mini_graph = ''; } $out = '<tr class="' . $sla['row_class'] . '"><td class="state-marker"></td>'; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $out .= '<td class="entity">' . generate_device_link($sla) . '</td>'; $table_cols++; } $out .= '<td class="entity">' . generate_entity_link('sla', $sla) . '</td>'; $out .= '<td>' . $sla['sla_owner'] . '</td>'; $out .= '<td>' . $sla['rtt_label'] . '</td>'; $out .= '<td>' . generate_entity_link('sla', $sla, $mini_graph, NULL, FALSE) . '</td>'; $out .= '<td style="white-space: nowrap">' . generate_tooltip_link(NULL, formatUptime($config['time']['now'] - $sla['rtt_last_change'], 'short-2') . ' ago', format_unixtime($sla['rtt_last_change'])) . '</td>'; $out .= '<td style="text-align: right;"><strong><span class="' . $sla['rtt_class'] . '">' . $sla['rtt_event'] . '</span></strong></td>'; $out .= '<td style="text-align: right;"><strong><span class="' . $sla['rtt_class'] . '">' . $sla['rtt_sense'] . '</span></strong></td>'; $out .= '<td><span class="' . $sla['sla_class'] . '">' . $sla['human_value'] . $sla['human_unit'] . '</span></td>'; $out .= '</tr>'; if ($vars['graph'] || $vars['view'] == "graphs" || $vars['id'] == $sla['sla_id']) { // If id set in vars, display only specific graphs $graph_array = array(); $graph_array['type'] = $sla['graph_type']; $graph_array['id'] = $sla['sla_id']; $out .= '<tr class="' . $sla['row_class'] . '">'; $out .= ' <td class="state-marker"></td>'; $out .= ' <td colspan="' . $table_cols . '">'; $out .= generate_graph_row($graph_array, TRUE); $out .= ' </td>'; $out .= '</tr>'; } return $out; }
function generate_printersupplies_row($supply, $vars) { $graph_type = "printersupply_usage"; $table_cols = 5; $total = $supply['supply_capacity']; $perc = $supply['supply_value']; $graph_array['type'] = $graph_type; $graph_array['id'] = $supply['supply_id']; $graph_array['from'] = $GLOBALS['config']['time']['day']; $graph_array['to'] = $GLOBALS['config']['time']['now']; $graph_array['height'] = "20"; $graph_array['width'] = "80"; if ($supply['supply_colour'] != '') { $background = toner_to_colour($supply['supply_colour'], $perc); } else { $background = toner_to_colour($supply['supply_descr'], $perc); } /// FIXME - popup for printersupply entity. $output .= '<tr class="' . $supply['html_row_class'] . '">'; $output .= '<td class="state-marker"></td>'; if ($vars['popup'] == TRUE) { $output .= '<td style="width: 40px; text-align: center;"><i class="' . $GLOBALS['config']['entities']['printersupply']['icon'] . '"></i></td>'; } else { $output .= '<td style="width: 1px;"></td>'; } if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $output .= '<td class="entity">' . generate_device_link($supply) . '</td>'; $table_cols++; } $output .= '<td class="entity">' . generate_entity_link('printersupply', $supply) . '</td>'; if (!isset($vars['supply'])) { $output .= '<td>' . nicecase($supply['supply_type']) . '</td>'; } $output .= '<td style="width: 70px;">' . generate_graph_popup($graph_array) . '</td>'; $output .= '<td style="width: 200px;"><a href="' . $link . '">' . print_percentage_bar(400, 20, $perc, $perc . '%', 'ffffff', $background['right'], NULL, "ffffff", $background['left']) . '</a></td>'; $output .= '<td style="width: 50px; text-align: right;"><span class="label">' . $perc . '%</span></td>'; $output .= '</tr>'; if ($vars['view'] == "graphs") { $output .= '<tr class="' . $supply['html_row_class'] . '">'; $output .= '<td class="state-marker"></td>'; $output .= '<td colspan=' . $table_cols . '>'; unset($graph_array['height'], $graph_array['width'], $graph_array['legend']); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $supply['supply_id']; $graph_array['type'] = $graph_type; $output .= generate_graph_row($graph_array, TRUE); $output .= "</td></tr>"; } # endif graphs return $output; }
} 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'); } echo generate_box_close(); // End sensor permissions } ?> </div>
/** * Check all alerts for a device to see if they should be notified or not * * @param array device * @return NULL */ function process_alerts($device) { global $config, $alert_rules, $alert_assoc; echo "Processing alerts for " . $device['hostname'] . PHP_EOL; $alert_table = cache_device_alert_table($device['device_id']); $sql = "SELECT * FROM `alert_table`"; $sql .= " LEFT JOIN `alert_table-state` ON `alert_table`.`alert_table_id` = `alert_table-state`.`alert_table_id`"; $sql .= " WHERE `device_id` = ?"; foreach (dbFetchRows($sql, array($device['device_id'])) as $entry) { echo 'Alert: ' . $entry['alert_table_id'] . ' Status: ' . $entry['alert_status'] . ' '; // If the alerter is now OK and has previously alerted, send an recovery notice. if ($entry['alert_status'] == '1' && $entry['has_alerted'] == '1') { $alert = $alert_rules[$entry['alert_test_id']]; $state = json_decode($entry['state'], TRUE); $conditions = json_decode($alert['conditions'], TRUE); $entity = get_entity_by_id_cache($entry['entity_type'], $entry['entity_id']); $graphs = ""; $metric_text = ""; foreach ($state['metrics'] as $metric => $value) { $metric_text .= $metric . " = " . $value . PHP_EOL . "<br />"; } // FIXME De-dup this shit soon. // - adama $message = ' <head> <title>Observium Alert</title> <style> .observium{ width:100%; max-width: 500px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; border:1px solid #DDDDDD; background-color:#FAFAFA; font-size: 13px; color: #777777; } .header{ font-weight: bold; font-size: 16px; padding: 5px; color: #555555; } .red { color: #cc0000; } #deviceinfo tr:nth-child(odd) { background: #ffffff; } </style> <style type="text/css"></style></head> <body> <table class="observium"> <tbody> <tr> <td> <table class="observium" id="deviceinfo"> <tbody> <tr><td class="header">RECOVERY</td><td><a style="float: right;" href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $entry['alert_table_id'])) . '">Modify</a></td></tr> <tr><td><b>Alert</b></font></td><td class="red">' . $alert['alert_message'] . '</font></td></tr> <tr><td><b>Entity</b></font></td><td>' . generate_entity_link($entry['entity_type'], $entry['entity_id'], $entity['entity_name']) . '</font></td></tr>'; if (strlen($entity['entity_descr']) > 0) { $message .= '<tr><td><b>Descr</b></font></td><td>' . $entity['entity_descr'] . '</font>'; } $message .= ' <tr><td><b>Metrics</b></font></td><td>' . $metric_text . '</font></td></tr> <tr><td><b>Duration</b></font></td><td>' . formatUptime(time() - $entry['last_failed']) . '</font></td></tr> <tr><td colspan="2" class="header">Device</td></tr> <tr><td><b>Device</b></font></td><td>' . generate_device_link($device) . '</font></td></tr> <tr><td><b>Hardware</b></font></td><td>' . $device['hardware'] . '</font></td></tr> <tr><td><b>Operating System</b></font></td><td>' . $device['os_text'] . ' ' . $device['version'] . ' ' . $device['features'] . '</font></td></tr> <tr><td><b>Location</b></font></td><td>' . htmlspecialchars($device['location']) . '</font></td></tr> <tr><td><b>Uptime</b></font></td><td>' . deviceUptime($device) . '</font></td></tr> </tbody></table> </td></tr> <tr><td> <center>' . $graphs . '</center></td></tr> </tbody></table> </body> </html>'; alert_notify($device, "RECOVER: [" . $device['hostname'] . "] [" . $alert['entity_type'] . "] [" . $entity['entity_name'] . "] " . $alert['alert_message'], $message); $update_array['last_recovered'] = time(); $update_array['has_alerted'] = 0; dbUpdate($update_array, 'alert_table-state', '`alert_table_id` = ?', array($entry['alert_table_id'])); } if ($entry['alert_status'] == '0') { echo 'Alert tripped. '; // Has this been alerted more frequently than the alert interval in the config? /// FIXME -- this should be configurable per-entity or per-checker if (time() - $entry['last_alerted'] < $config['alerts']['interval'] && !isset($GLOBALS['spam'])) { $entry['suppress_alert'] = TRUE; } // Check if alert has ignore_until set. if (is_numeric($entry['ignore_until']) && $entry['ignore_until'] > time()) { $entry['suppress_alert'] = TRUE; } if ($entry['suppress_alert'] != TRUE) { echo 'Requires notification. '; $alert = $alert_rules[$entry['alert_test_id']]; $state = json_decode($entry['state'], TRUE); $conditions = json_decode($alert['conditions'], TRUE); $entity = get_entity_by_id_cache($entry['entity_type'], $entry['entity_id']); $condition_text = ""; foreach ($state['failed'] as $failed) { $condition_text .= $failed['metric'] . " " . $failed['condition'] . " " . $failed['value'] . " (" . $state['metrics'][$failed['metric']] . ")<br />"; } $graphs = ""; $metric_text = ""; foreach ($state['metrics'] as $metric => $value) { $metric_text .= $metric . " = " . $value . PHP_EOL . "<br />"; } if (is_array($config['entities'][$entry['entity_type']]['graph'])) { // We can draw a graph for this type/metric pair! $graph_array = $config['entities'][$entry['entity_type']]['graph']; foreach ($graph_array as $key => $val) { // Check to see if we need to do any substitution if (substr($val, 0, 1) == "@") { $nval = substr($val, 1); echo " replaced " . $val . " with " . $entity[$nval] . " from entity. " . PHP_EOL . "<br />"; $graph_array[$key] = $entity[$nval]; } } print_r($graph_array); $image_data_uri = generate_alert_graph($graph_array); print_r(strlen($image_data_uri)); $graphs .= '<img src="' . $image_data_uri . '">' . "<br />"; unset($graph_array); } #$css = data_uri($config['html_dir'].'/css/bootstrap-mini.css' ,'text/css'); $message = ' <head> <title>Observium Alert</title> <style> .observium{ width:100%; max-width: 500px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; border:1px solid #DDDDDD; background-color:#FAFAFA; font-size: 13px; color: #777777; } .header{ font-weight: bold; font-size: 16px; padding: 5px; color: #555555; } .red { color: #cc0000; } #deviceinfo tr:nth-child(odd) { background: #ffffff; } </style> <style type="text/css"></style></head> <body> <table class="observium"> <tbody> <tr> <td> <table class="observium" id="deviceinfo"> <tbody> <tr><td class="header">ALERT</td><td><a style="float: right;" href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $entry['alert_table_id'])) . '">Modify</a></td></tr> <tr><td><b>Alert</b></font></td><td class="red">' . $alert['alert_message'] . '</font></td></tr> <tr><td><b>Entity</b></font></td><td>' . generate_entity_link($entry['entity_type'], $entry['entity_id'], $entity['entity_name']) . '</font></td></tr>'; if (strlen($entity['entity_descr']) > 0) { $message .= '<tr><td><b>Descr</b></font></td><td>' . $entity['entity_descr'] . '</font>'; } $message .= ' <tr><td><b>Conditions</b></font></td><td>' . $condition_text . '</font></td></tr> <tr><td><b>Metrics</b></font></td><td>' . $metric_text . '</font></td></tr> <tr><td><b>Duration</b></font></td><td>' . formatUptime(time() - $entry['last_failed']) . '</font></td></tr> <tr><td colspan="2" class="header">Device</td></tr> <tr><td><b>Device</b></font></td><td>' . generate_device_link($device) . '</font></td></tr> <tr><td><b>Hardware</b></font></td><td>' . $device['hardware'] . '</font></td></tr> <tr><td><b>Operating System</b></font></td><td>' . $device['os_text'] . ' ' . $device['version'] . ' ' . $device['features'] . '</font></td></tr> <tr><td><b>Location</b></font></td><td>' . htmlspecialchars($device['location']) . '</font></td></tr> <tr><td><b>Uptime</b></font></td><td>' . deviceUptime($device) . '</font></td></tr> </tbody></table> </td></tr> <tr><td> <center>' . $graphs . '</center></td></tr> </tbody></table> </body> </html>'; alert_notify($device, "ALERT: [" . $device['hostname'] . "] [" . $alert['entity_type'] . "] [" . $entity['entity_name'] . "] " . $alert['alert_message'], $message); $update_array['last_alerted'] = time(); $update_array['has_alerted'] = 1; dbUpdate($update_array, 'alert_table-state', '`alert_table_id` = ?', array($entry['alert_table_id'])); } else { echo "No notification required. " . (time() - $entry['last_alerted']); } } elseif ($entry['alert_status'] == '1') { echo "Status: OK. "; } else { echo "Unknown status."; } echo PHP_EOL; } }
$graph_array = array(); $graph_array['height'] = "100"; $graph_array['width'] = "210"; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $drive['storage_id']; $graph_array['type'] = $graph_type; $graph_array['from'] = $config['time']['day']; $graph_array['legend'] = "no"; $link_array = $graph_array; $link_array['page'] = "graphs"; unset($link_array['height'], $link_array['width'], $link_array['legend']); $link = generate_url($link_array); $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $drive['storage_descr']); $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; // $graph_array['style'][] = 'margin-top: -6px'; $minigraph = generate_graph_tag($graph_array); echo '<tr class="' . $background['class'] . '"> <td class="state-marker"></td> <td class="entity" style="max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">' . generate_entity_link('storage', $drive) . '</td> <td style="width: 90px">' . overlib_link($link, $minigraph, $overlib_content) . '</td> <td style="width: 200px">' . overlib_link($link, print_percentage_bar(200, 20, $percent, $used . "/" . $total . " (" . $percent . "%)", "ffffff", $background['left'], $free . " (" . (100 - $percent) . "%)", "ffffff", $background['right']), $overlib_content) . '</td> </tr>'; } echo "</table>"; echo generate_box_close(); } unset($drive_rows); // EOF
$graph_array['to'] = $config['time']['now']; $graph_array['id'] = $sensor['sensor_id']; $graph_array['type'] = "sensor_graph"; $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. $graph_array['from'] = $config['time']['day']; echo ' <tr class="' . $sensor['row_class'] . '"> <td class="state-marker"></td> <td class="entity">' . generate_device_link($sensor) . '</td> <td class="entity">' . generate_entity_link("sensor", $sensor) . '</td> <td class="text-right"><i class="' . $alert . '"></i></td> <td><span class="label">' . $sensor['sensor_thresholds'] . '</span></td> <td>' . generate_entity_link("sensor", $sensor, generate_graph_tag($graph_array), FALSE, FALSE) . '</td> <td style="text-align: right;"><span class="' . $sensor['state_class'] . '">' . $sensor['human_value'] . $sensor['sensor_symbol'] . '</span></td> </tr>' . PHP_EOL; if ($vars['view'] == "graphs") { echo ' <tr class="' . $sensor['row_class'] . '"> <td class="state-marker"></td> <td colspan=6>'; $graph_array = array(); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $sensor['sensor_id']; $graph_array['type'] = 'sensor_graph'; print_graph_row($graph_array, TRUE); echo '</td></tr>'; } # endif graphs
$graph_array['to'] = $config['time']['now']; $graph_array['id'] = $status['status_id']; $graph_array['type'] = "status_graph"; $graph_array['legend'] = "no"; $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. $graph_array['from'] = $config['time']['day']; $mini_graph = generate_graph_tag($graph_array); $status_misc = '<span class="label">' . $status['entPhysicalClass'] . '</span>'; echo '<tr class="' . $status['row_class'] . '"> <td class="state-marker"></td> <td class="entity">' . generate_entity_link('status', $status) . '</td> <td><span class="label">' . $status['entPhysicalClass'] . '</span></td> <td>' . generate_entity_link('status', $status, $mini_graph, NULL, FALSE) . '</td> <td style="text-align: right;"><strong>' . overlib_link($link, '<span class="' . $status['state_class'] . '">' . $status['status_name'] . '</span>', $overlib_content) . '</strong></td> </tr>' . PHP_EOL; if ($vars['view'] == "graphs") { echo '<tr><td class="state-marker"></td><td colspan=5>'; unset($graph_array['height'], $graph_array['width'], $graph_array['legend']); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $status['status_id']; $graph_array['type'] = "status_graph"; print_graph_row($graph_array, TRUE); echo '</td></tr>'; } # endif graphs } echo "</table>"; // EOF
function process_alerts($device) { global $config, $alert_rules, $alert_assoc; echo "处理警报 " . $device['hostname'] . PHP_EOL; $alert_table = cache_device_alert_table($device['device_id']); $sql = "SELECT * FROM `alert_table`"; $sql .= " LEFT JOIN `alert_table-state` ON `alert_table`.`alert_table_id` = `alert_table-state`.`alert_table_id`"; $sql .= " WHERE `device_id` = ? AND `alert_status` IS NOT NULL;"; foreach (dbFetchRows($sql, array($device['device_id'])) as $entry) { echo 'Alert: ' . $entry['alert_table_id'] . ' Status: ' . $entry['alert_status'] . ' '; // If the alerter is now OK and has previously alerted, send an recovery notice. if ($entry['alert_status'] == '1' && $entry['has_alerted'] == '1') { $alert = $alert_rules[$entry['alert_test_id']]; if (!$alert['suppress_recovery']) { $state = json_decode($entry['state'], TRUE); $conditions = json_decode($alert['conditions'], TRUE); $entity = get_entity_by_id_cache($entry['entity_type'], $entry['entity_id']); $metric_array = array(); foreach ($state['metrics'] as $metric => $value) { $metric_array[] = $metric . ' = ' . $value; } $message_tags = array('ALERT_STATE' => 'RECOVERY', 'ALERT_URL' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $entry['alert_table_id'])), 'ALERT_MESSAGE' => $alert['alert_message'], 'METRICS' => implode(PHP_EOL . ' ', $metric_array), 'DURATION' => formatUptime(time() - $entry['last_failed']), 'ENTITY_LINK' => generate_entity_link($entry['entity_type'], $entry['entity_id'], $entity['entity_name']), 'ENTITY_NAME' => $entity['entity_name'], 'ENTITY_DESCRIPTION' => $entity['entity_descr'], 'DEVICE_HOSTNAME' => $device['hostname'], 'DEVICE_LINK' => generate_device_link($device), 'DEVICE_HARDWARE' => $device['hardware'], 'DEVICE_OS' => $device['os_text'] . ' ' . $device['version'] . ' ' . $device['features'], 'DEVICE_LOCATION' => $device['location'], 'DEVICE_UPTIME' => deviceUptime($device)); $message['text'] = simple_template('alert/email_text.tpl', $message_tags, array('is_file' => TRUE)); //$message_tags['CONDITIONS'] = nl2br($message_tags['CONDITIONS']); $message_tags['METRICS'] = nl2br($message_tags['METRICS']); $message['html'] = simple_template('alert/email_html.tpl', $message_tags, array('is_file' => TRUE)); //logfile('debug.log', var_export($message, TRUE)); alert_notify($device, alert_generate_subject('RECOVER', $device, $alert, $entity), $message, $entry['alert_test_id']); log_alert('恢复发送的通知', $device, $entry, 'RECOVER_NOTIFY'); } else { echo '已限制恢复.'; log_alert('限制恢复通知', $device, $entry, 'RECOVER_SUPPRESSED'); } $update_array['last_recovered'] = time(); $update_array['has_alerted'] = 0; dbUpdate($update_array, 'alert_table-state', '`alert_table_id` = ?', array($entry['alert_table_id'])); } if ($entry['alert_status'] == '0') { echo '警报已停止. '; // Has this been alerted more frequently than the alert interval in the config? /// FIXME -- this should be configurable per-entity or per-checker if (time() - $entry['last_alerted'] < $config['alerts']['interval'] && !isset($GLOBALS['spam'])) { $entry['suppress_alert'] = TRUE; } // Check if alert has ignore_until set. if (is_numeric($entry['ignore_until']) && $entry['ignore_until'] > time()) { $entry['suppress_alert'] = TRUE; } // Check if alert has ignore_until_ok set. if (is_numeric($entry['ignore_until_ok']) && $entry['ignore_until_ok'] == '1') { $entry['suppress_alert'] = TRUE; } if ($entry['suppress_alert'] != TRUE) { echo 'Requires notification. '; $alert = $alert_rules[$entry['alert_test_id']]; $state = json_decode($entry['state'], TRUE); $conditions = json_decode($alert['conditions'], TRUE); $entity = get_entity_by_id_cache($entry['entity_type'], $entry['entity_id']); $condition_array = array(); foreach ($state['failed'] as $failed) { $condition_array[] = $failed['metric'] . " " . $failed['condition'] . " " . $failed['value'] . " (" . $state['metrics'][$failed['metric']] . ")"; } $graphs = ""; $metric_array = array(); foreach ($state['metrics'] as $metric => $value) { $metric_array[] = $metric . ' = ' . $value; } if (is_array($config['entities'][$entry['entity_type']]['graph'])) { // We can draw a graph for this type/metric pair! $graph_array = $config['entities'][$entry['entity_type']]['graph']; foreach ($graph_array as $key => $val) { // Check to see if we need to do any substitution if (substr($val, 0, 1) == "@") { $nval = substr($val, 1); echo " replaced " . $val . " with " . $entity[$nval] . " from entity. " . PHP_EOL . "<br />"; $graph_array[$key] = $entity[$nval]; } } //print_r($graph_array); //logfile('debug.log', var_export($graph_array, TRUE)); $image_data_uri = generate_alert_graph($graph_array); //print_r($image_data_uri); //logfile('debug.log', var_export($image_data_uri, TRUE)); $graphs .= '<img src="' . $image_data_uri . '"><br />'; unset($graph_array); } $message_tags = array('ALERT_STATE' => 'ALERT', 'ALERT_URL' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $entry['alert_table_id'])), 'ALERT_MESSAGE' => $alert['alert_message'], 'CONDITIONS' => implode(PHP_EOL . ' ', $condition_array), 'METRICS' => implode(PHP_EOL . ' ', $metric_array), 'DURATION' => formatUptime(time() - $entry['last_failed']), 'ENTITY_LINK' => generate_entity_link($entry['entity_type'], $entry['entity_id'], $entity['entity_name']), 'ENTITY_NAME' => $entity['entity_name'], 'ENTITY_DESCRIPTION' => $entity['entity_descr'], 'ENTITY_GRAPHS' => $graphs, 'DEVICE_HOSTNAME' => $device['hostname'], 'DEVICE_LINK' => generate_device_link($device), 'DEVICE_HARDWARE' => $device['hardware'], 'DEVICE_OS' => $device['os_text'] . ' ' . $device['version'] . ' ' . $device['features'], 'DEVICE_LOCATION' => $device['location'], 'DEVICE_UPTIME' => deviceUptime($device)); $message['text'] = simple_template('alert/email_text.tpl', $message_tags, array('is_file' => TRUE)); $message_tags['CONDITIONS'] = nl2br($message_tags['CONDITIONS']); $message_tags['METRICS'] = nl2br($message_tags['METRICS']); $message['html'] = simple_template('alert/email_html.tpl', $message_tags, array('is_file' => TRUE)); //logfile('debug.log', var_export($message, TRUE)); alert_notify($device, alert_generate_subject('ALERT', $device, $alert, $entity), $message, $entry['alert_test_id']); log_alert('Alert notification sent', $device, $entry, 'ALERT_NOTIFY'); $update_array['last_alerted'] = time(); $update_array['has_alerted'] = 1; dbUpdate($update_array, 'alert_table-state', '`alert_table_id` = ?', array($entry['alert_table_id'])); } else { echo "没有通知要求. " . (time() - $entry['last_alerted']); } } else { if ($entry['alert_status'] == '1') { echo "状态: OK. "; } else { if ($entry['alert_status'] == '2') { echo "Status: Notification Delayed. "; } else { if ($entry['alert_status'] == '3') { echo "Status: Notification Suppressed. "; } else { echo "未知的状态."; } } } } echo PHP_EOL; } }
/** * 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; }
/** * 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; } }
<th>Type</th> <th>Status</th> <th>Errors</th> <th>Load</th> </tr> </thead> <tbody> <?php foreach (dbFetchRows("SELECT * FROM `hrDevice` WHERE `device_id` = ? ORDER BY `hrDeviceIndex`", array($device['device_id'])) as $hrdevice) { echo " <tr>\n"; echo " <td>" . $hrdevice['hrDeviceIndex'] . "</td>\n"; if ($hrdevice['hrDeviceType'] == "hrDeviceProcessor") { $proc_id = dbFetchCell('SELECT processor_id FROM processors WHERE device_id = ? AND hrDeviceIndex = ?', array($device['device_id'], $hrdevice['hrDeviceIndex'])); $proc_url = "device/device=" . $device['device_id'] . "/tab=health/metric=processor/"; echo " <td>" . generate_entity_link('processor', $proc_id) . "</td>\n"; $graph_array['height'] = "20"; $graph_array['width'] = "100"; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $proc_id; $graph_array['type'] = 'processor_usage'; $graph_array['from'] = $config['time']['day']; $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = "150"; $graph_array_zoom['width'] = "400"; $mini_graph = overlib_link($proc_url, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); echo " <td>" . $mini_graph . "</td>\n"; } elseif ($hrdevice['hrDeviceType'] == "hrDeviceNetwork") { $int = str_replace("network interface ", "", $hrdevice['hrDeviceDescr']); $interface = dbFetchRow("SELECT * FROM ports WHERE device_id = ? AND ifDescr = ?", array($device['device_id'], $int)); if ($interface['ifIndex']) {
function generate_processor_row($processor, $vars) { global $config; $table_cols = 4; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $table_cols++; } // Add a column for device. // FIXME should that really be done here? :-) // FIXME - not it shouldn't. we need some per-os rewriting on discovery-time. $text_descr = $processor['processor_descr']; $text_descr = str_replace("Routing Processor", "RP", $text_descr); $text_descr = str_replace("Switching Processor", "SP", $text_descr); $text_descr = str_replace("Sub-Module", "Module ", $text_descr); $text_descr = str_replace("DFC Card", "DFC", $text_descr); $graph_array = array(); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $processor['processor_id']; $graph_array['type'] = 'processor_usage'; $graph_array['legend'] = "no"; $link_array = $graph_array; $link_array['page'] = "graphs"; unset($link_array['height'], $link_array['width'], $link_array['legend']); $link_graph = generate_url($link_array); $link = generate_url(array("page" => "device", "device" => $processor['device_id'], "tab" => "health", "metric" => 'processor')); $overlib_content = generate_overlib_content($graph_array, $processor['hostname'] . " - " . $text_descr); $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; $graph_array['from'] = $config['time']['day']; $mini_graph = generate_graph_tag($graph_array); $perc = round($processor['processor_usage']); $background = get_percentage_colours($perc); $processor['html_row_class'] = $background['class']; $row .= '<tr class="' . $processor['html_row_class'] . '"> <td class="state-marker"></td>'; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $row .= '<td class="entity">' . generate_device_link($processor) . '</td>'; } $row .= ' <td class="entity">' . generate_entity_link('processor', $processor) . '</td> <td>' . overlib_link($link_graph, $mini_graph, $overlib_content) . '</td> <td><a href="' . $link_graph . '"> ' . print_percentage_bar(400, 20, $perc, $perc . "%", "ffffff", $background['left'], 100 - $perc . "%", "ffffff", $background['right']) . ' </a> </td> </tr> '; if ($vars['view'] == "graphs") { $vars['graph'] = "usage"; } if ($vars['graph']) { $row .= '<tr class="' . $processor['html_row_class'] . '">'; $row .= '<td class="state-marker"></td>'; $row .= '<td colspan=' . $table_cols . '>'; unset($graph_array['height'], $graph_array['width'], $graph_array['legend']); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $processor['processor_id']; $graph_array['type'] = 'processor_' . $vars['graph']; print_graph_row($graph_array, TRUE); $row .= '</td></tr>'; } # endif graphs return $row; }
WHERE A.`' . $ip_version . '_address` = ?', array($peer['bgpPeerRemoteAddr'])); if ($peerhost['device_id']) { $peername = generate_device_link($peerhost, short_hostname($peerhost['hostname']), array('tab' => 'routing', 'proto' => 'bgp')); $peer['remote_id'] = $peerhost['device_id']; } else { $peername = $peer['reverse_dns']; } // display overlib graphs $graph_type = "bgp_updates"; $local_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=" . $config['time']['day'] . "&to=" . $config['time']['now'] . "&width=500&height=150&afi=ipv4&safi=unicast"; $localaddresslink = "<span class=entity-title><a href='device/device=" . $peer['device_id'] . "/tab=routing/proto=bgp/' onmouseover=\"return overlib('<img src=\\'{$local_daily_url}\\'>', LEFT" . $config['overlib_defaults'] . ");\" onmouseout=\"return nd();\">" . $peer['human_localip'] . "</a></span>"; if ($peer['remote_id']) { $graph_type = "bgp_updates"; $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=" . $config['time']['day'] . "&to=" . $config['time']['now'] . "&width=500&height=150"; $peeraddresslink = "<span class=entity-title><a href='device/device=" . $peer['remote_id'] . "/tab=routing/proto=bgp/' onmouseover=\"return overlib('<img src=\\'{$peer_daily_url}\\'>', LEFT" . $config['overlib_defaults'] . ");\" onmouseout=\"return nd();\">" . $peer['human_remoteip'] . "</a></span>"; $peeraddresslink = generate_entity_link('bgp_peer', $peer); } else { $peeraddresslink = "<span class=entity-title>" . $peer['human_remoteip'] . "</span>"; } echo '<tr class="' . $peer['html_row_class'] . '">'; unset($sep); foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerRemoteAddr = ?", array($peer['device_id'], $peer['bgpPeerRemoteAddr'])) as $afisafi) { $afi = $afisafi['afi']; $safi = $afisafi['safi']; $this_afisafi = $afi . $safi; $peer['afi'] .= $sep . $afi . "." . $safi; $sep = "<br />"; $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer } unset($sep);
$graph_array['to'] = $config['time']['now']; $graph_array['device'] = $device['device_id']; $graph_array['id'] = $proc['id']; if (is_array($proc['id'])) { $graph_array['type'] = "multi-processor_usage"; } else { $graph_array['type'] = $graph_type; } $graph_array['from'] = $config['time']['day']; $graph_array['legend'] = "no"; $link_array = $graph_array; $link_array['page'] = "graphs"; unset($link_array['height'], $link_array['width'], $link_array['legend']); $link = generate_url($link_array); $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. // $graph_array['style'][] = 'margin-top: -6px'; $count_button = $proc['count'] > 1 ? '<span class="label pull-right" style="margin-top: 2px;"><i class="icon-remove"></i> ' . $proc['count'] . '</span>' : ''; echo '<tr class="' . $background['class'] . '"> <td class="state-marker"></td> <td><span class="entity text-nowrap">' . generate_entity_link('processor', $proc, $text_descr) . '</span>' . $count_button . '</td> <td style="width: 200px">' . overlib_link($link, print_percentage_bar(200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content) . '</td> </tr>'; } echo "</table>"; echo generate_box_close(); } // EOF
humanize_sensor($sensor); if ($sensor['sensor_state']) { $sensor_value = $sensor['state_name']; $limit_class = 'input-mini hidden'; $limit_switch_class = 'hide'; } else { $sensor_value = $sensor['human_value']; $limit_class = 'input-mini'; $limit_switch_class = ''; } echo '<tr class="' . $sensor['row_class'] . '">'; echo '<td class="state-marker"></td>'; echo '<td>' . escape_html($sensor['sensor_index']) . '</td>'; echo '<td>' . $sensor['sensor_type'] . '</td>'; echo '<td>' . $sensor['sensor_class'] . '</td>'; echo '<td><span class="entity text-nowrap">' . generate_entity_link('sensor', $sensor) . '</span></td>'; echo '<td><span class="' . $sensor['state_class'] . '">' . $sensor_value . $sensor['sensor_symbol'] . '</span></td>'; echo '<td><input class="' . $limit_class . '" name="sensors[' . $sensor['sensor_id'] . '][sensor_limit_low]" size="4" value="' . escape_html($sensor['sensor_limit_low']) . '" /></td>'; if ($warn_enable) { echo '<td><input class="' . $limit_class . '" name="sensors[' . $sensor['sensor_id'] . '][sensor_limit_low_warn]" size="4" value="' . escape_html($sensor['sensor_limit_low_warn']) . '" /></td>'; echo '<td><input class="' . $limit_class . '" name="sensors[' . $sensor['sensor_id'] . '][sensor_limit_warn]" size="4" value="' . escape_html($sensor['sensor_limit_warn']) . '" /></td>'; } echo '<td><input class="' . $limit_class . '" name="sensors[' . $sensor['sensor_id'] . '][sensor_limit]" size="4" value="' . escape_html($sensor['sensor_limit']) . '" /></td>'; if (OBS_DEBUG) { echo '<td>' . $sensor['sensor_multiplier'] . '</td>'; } echo '<td><div class="' . $limit_switch_class . '"> <input type=checkbox data-toggle="switch-mini" id="sensor_custom_limit_' . $sensor['sensor_id'] . '" name="sensors[' . $sensor['sensor_id'] . '][sensor_custom_limit]"' . ($sensor['sensor_custom_limit'] ? "checked" : "") . '> </div></td>'; echo '<td><div class="' . $limit_switch_class . '"> <input type=checkbox data-toggle="switch-mini" id="sensor_reset_limit_' . $sensor['sensor_id'] . '" name="sensors[' . $sensor['sensor_id'] . '][sensor_reset_limit]">
function generate_status_row($status, $vars) { global $config; $table_cols = 7; humanize_status($status); $alert = $status['state_event'] == 'alert' ? 'oicon-exclamation-red' : ''; // FIXME - make this "four graphs in popup" a function/include and "small graph" a function. // FIXME - DUPLICATED IN device/overview/status $graph_array = array(); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $status['status_id']; $graph_array['type'] = "status_graph"; $graph_array['legend'] = "no"; $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; $graph_array['from'] = $config['time']['day']; $status_misc = '<span class="label">' . $status['entPhysicalClass'] . '</span>'; $row .= '<tr class="' . $status['row_class'] . '"> <td class="state-marker"></td>'; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $row .= '<td class="entity">' . generate_device_link($status) . '</td>'; $table_cols++; } if ($status['status_event'] && $status['status_name']) { $mini_graph = generate_graph_tag($graph_array); } else { // Do not show "Draw Error" minigraph $mini_graph = ''; } $row .= '<td class="entity">' . generate_entity_link('status', $status) . '</td>'; if ($vars['tab'] != "overview") { $row .= '<td><span class="label">' . $status['entPhysicalClass'] . '</span></td>'; $table_cols++; } $row .= '<td style="width: 90px; text-align: right;">' . generate_entity_link('status', $status, $mini_graph, NULL, FALSE) . '</td>'; if ($vars['tab'] != "overview") { $row .= '<td style="white-space: nowrap">' . generate_tooltip_link(NULL, formatUptime($config['time']['now'] - $status['status_last_change'], 'short-2') . ' ago', format_unixtime($status['status_last_change'])) . '</td> <td style="text-align: right;"><strong><span class="' . $status['state_class'] . '">' . $status['status_event'] . '</span></strong></td>'; $table_cols++; $table_cols++; } $row .= '<td style="width: 80px; text-align: right;"><strong><span class="' . $status['state_class'] . '">' . $status['status_name'] . '</span></strong></td> </tr>' . PHP_EOL; if ($vars['view'] == "graphs") { $vars['graph'] = "status"; } if ($vars['graph'] || $vars['id'] == $status['status_id']) { // If id set in vars, display only specific graphs $row .= '<tr class="' . $status['row_class'] . '"> <td class="state-marker"></td> <td colspan="' . $table_cols . '">'; unset($graph_array['height'], $graph_array['width'], $graph_array['legend']); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $status['status_id']; $graph_array['type'] = "status_graph"; $row .= generate_graph_row($graph_array, TRUE); $row .= '</td></tr>'; } # endif graphs return $row; }
function generate_vm_row($vm, $vars) { global $config; $table_cols = "8"; $out = '<tr class="' . $vm['row_class'] . '">'; // <td class="state-marker"></td>'; // FIXME useful when we start polling VM state if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $out .= '<td class="entity">' . generate_device_link($vm) . '</td>'; $table_cols++; } $out .= '<td class="entity">' . generate_entity_link('virtualmachine', $vm) . '</td>'; $out .= '<td>' . nicecase($vm['vm_state']) . '</td>'; switch ($vm['vm_guestos']) { case 'E: tools not installed': $out .= ' <td class="small">Unknown (VMware Tools not installed)</td>'; break; case 'E: tools not running': $out .= ' <td class="small">Unknown (VMware Tools not running)</td>'; break; case '': $out .= ' <td class="small"><i>(Unknown)</i></td>'; break; default: if (isset($config['vmware_guestid'][$vm['vm_guestos']])) { $out .= ' <td>' . $config['vmware_guestid'][$vm['vm_guestos']] . '</td>'; } else { $out .= ' <td>' . $vm['vm_guestos'] . '</td>'; } break; } $out .= '<td>' . format_bi($vm['vm_memory'] * 1024 * 1024, 3, 3) . 'B</td>'; $out .= '<td>' . nicecase($vm['vm_cpucount']) . '</td>'; $out .= '</tr>'; return $out; }
/** * 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; } }
/** * 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 ' <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; } }
function get_status_array($status) { // Mike: I know that there are duplicated variables, but later will remove global global $config, $cache; $max_interval = filter_var($status['max']['interval'], FILTER_VALIDATE_INT, array('options' => array('default' => 24, 'min_range' => 1))); $max_count = filter_var($status['max']['count'], FILTER_VALIDATE_INT, array('options' => array('default' => 200, 'min_range' => 1))); $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D', 'hide_ignored' => TRUE)); $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I', 'hide_ignored' => TRUE)); // Show Device Status if ($status['devices']) { $query = 'SELECT * FROM `devices` AS D '; $query .= 'WHERE D.`status` = 0' . $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query); foreach ($entries as $device) { $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3')); } } // Uptime if ($status['uptime']) { if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) { $query = 'SELECT * FROM `devices` AS D '; // Since reboot event more complicated than just device uptime less than some time //$query .= ' WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`uptime` < ' . $config['uptime_warning']; $query .= ' WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`last_rebooted` > ?'; $query .= $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query, array($config['time']['now'] - $config['uptime_warning'] - 10)); foreach ($entries as $device) { $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']); } } } // Ports Down if ($status['ports'] || $status['neighbours']) { $status['neighbours'] = $status['neighbours'] && !$status['ports']; // Disable 'neighbours' if 'ports' already enabled $query = 'SELECT * FROM `ports` AS I '; if ($status['neighbours']) { $query .= 'INNER JOIN `neighbours` as L ON I.`port_id` = L.`port_id` '; } $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` '; $query .= "WHERE D.`status` = 1 AND D.ignore = 0 AND I.ignore = 0 AND I.deleted = 0 AND I.`ifAdminStatus` = 'up' AND (I.`ifOperStatus` = 'lowerLayerDown' OR I.`ifOperStatus` = 'down') "; if ($status['neighbours']) { $query .= ' AND L.`active` = 1 '; } $query .= $query_port_permitted; $query .= ' AND I.`ifLastChange` >= DATE_SUB(NOW(), INTERVAL ' . $max_interval . ' HOUR) '; if ($status['neighbours']) { $query .= 'GROUP BY L.`port_id` '; } $query .= 'ORDER BY I.`ifLastChange` DESC, D.`hostname` ASC, I.`ifDescr` * 1 ASC '; $entries = dbFetchRows($query); $i = 1; foreach ($entries as $port) { if ($i > $max_count) { // Limit to 200 ports on overview page break; } humanize_port($port); $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, short_hostname($port['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['port_label'], 13)), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']); } } // Ports Errors (only deltas) if ($status['errors']) { foreach ($cache['ports']['errored'] as $port_id) { if (in_array($port_id, $cache['ports']['ignored'])) { continue; } // Skip ignored ports $port = get_port_by_id($port_id); $device = device_by_id_cache($port['device_id']); humanize_port($port); if ($port['ifInErrors_delta']) { $port['string'] .= 'Rx: ' . format_number($port['ifInErrors_delta']); } if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) { $port['string'] .= ', '; } if ($port['ifOutErrors_delta']) { $port['string'] .= 'Tx: ' . format_number($port['ifOutErrors_delta']); } $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['port_label'], 13)), 'time' => $port['string'], 'location' => $device['location']); } } // Services if ($status['services']) { $query = 'SELECT * FROM `services` AS S '; $query .= 'LEFT JOIN `devices` AS D ON S.`device_id` = D.`device_id` '; $query .= "WHERE S.`service_status` = 'down' AND S.`service_ignore` = 0"; $query .= $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query); foreach ($entries as $service) { $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, short_hostname($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']); } } // BGP if ($status['bgp']) { if (isset($config['enable_bgp']) && $config['enable_bgp']) { $query = 'SELECT * FROM `bgpPeers` AS B '; $query .= 'LEFT JOIN `devices` AS D ON B.`device_id` = D.`device_id` '; $query .= 'LEFT JOIN `bgpPeers-state` AS BS ON B.`bgpPeer_id` = BS.`bgpPeer_id` '; $query .= "WHERE D.`status` = 1 AND (`bgpPeerAdminStatus` = 'start' OR `bgpPeerAdminStatus` = 'running') AND `bgpPeerState` != 'established' "; $query .= $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query); foreach ($entries as $peer) { humanize_bgp($peer); $peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']); $peer['wide'] = strstr($peer['bgpPeerRemoteAddr'], ':') ? TRUE : FALSE; $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, short_hostname($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'short-3'), 'location' => $device['location']); } } } // Return boxes array return $boxes; }
/** * 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; } }
foreach ($entries as $entry_id => $entry) { if ($entry['enable'] == 1) { $enabled = '<img align=absmiddle src="images/16/tick.png" />'; } else { $enabled = '<img align=absmiddle src="images/16/stop.png" />'; } if ($entry['severity'] == "crit") { $severity_class = "text-error"; } elseif ($entry['severity'] == "warn") { $severity_class = "text-warning"; } else { $severity_class = NULL; } echo "<tr>\n"; echo '<td>' . $subtype . '</td><td>' . htmlentities($entry['descr_regex']) . '</td><td>' . $metric . '</td><td>' . htmlentities($entry['operator']) . '</td><td>' . $entry['value'] . '</td><td>' . $entry['count'] . '</td><td><strong class="' . $severity_class . '">' . $entry['severity'] . '</strong></td><td>' . $enabled . '</td>'; echo "</tr>\n"; // Get which entities match this checker $entities = get_entity_list($vars['type'], $subtype, $device['device_id'], $entry['entity'], $entry['descr_regex']); if (!empty($entities)) { echo "<tr><td></td><td colspan=\"9\"><strong>"; foreach ($entities as $entity) { echo '<button class="btn btn-small-thin" type="button" style="margin: 2px;">' . generate_entity_link($vars['type'], $entity) . '</button>'; } echo "</strong></td></tr>\n"; } } } } #} echo " </tbody>\n"; echo "</table>\n";
function generate_storage_row($storage, $vars) { global $config; $table_cols = 8; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $table_cols++; } // Add a column for device. $graph_array = array(); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $storage['storage_id']; $graph_array['type'] = 'storage_usage'; $graph_array['legend'] = "no"; $link_array = $graph_array; $link_array['page'] = "graphs"; unset($link_array['height'], $link_array['width'], $link_array['legend']); $link_graph = generate_url($link_array); $link = generate_url(array("page" => "device", "device" => $storage['device_id'], "tab" => "health", "metric" => 'storage')); $overlib_content = generate_overlib_content($graph_array, $storage['hostname'] . ' - ' . $storage['storage_descr']); $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; $graph_array['from'] = $config['time']['day']; $mini_graph = generate_graph_tag($graph_array); $total = formatStorage($storage['storage_size']); $used = formatStorage($storage['storage_used']); $free = formatStorage($storage['storage_free']); $background = get_percentage_colours($storage['storage_perc']); if ($storage['storage_ignore']) { $storage['row_class'] = 'suppressed'; } else { $storage['row_class'] = $background['class']; } $row .= '<tr class="ports ' . $storage['row_class'] . '"> <td class="state-marker"></td>'; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $row .= '<td class="entity">' . generate_device_link($storage) . '</td>'; } $row .= ' <td class="entity">' . generate_entity_link('storage', $storage) . '</td> <td>' . $total . '</td> <td>' . $used . '</td> <td>' . $free . '</td> <td>' . overlib_link($link_graph, $mini_graph, $overlib_content) . '</td> <td><a href="' . $link_graph . '"> ' . print_percentage_bar(400, 20, $storage['storage_perc'], $storage['storage_perc'] . '%', "ffffff", $background['left'], 100 - $storage['storage_perc'] . "%", "ffffff", $background['right']) . ' </a> </td> </tr> '; if ($vars['view'] == "graphs") { $vars['graph'] = "usage"; } if ($vars['graph']) { echo '<tr class="' . $storage['row_class'] . '">'; echo '<td class="state-marker"></td>'; echo '<td colspan="' . $table_cols . '">'; unset($graph_array['height'], $graph_array['width'], $graph_array['legend']); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $storage['storage_id']; $graph_array['type'] = 'storage_' . $vars['graph']; print_graph_row($graph_array, TRUE); $row .= '</td></tr>'; } # endif graphs return $row; }
if ($wlan['wlan_igmp_snoop'] == "1") { $wlan['igmp_label'] = '<span class="label label-success">IGMP Snooping</span>'; } else { $wlan['igmp_label'] = '<span class="label label-disabled">Disabled</span>'; } if ($wlan['wlan_ssid_bcast'] == "0") { $wlan['ssid_bcast_label'] = ' <span class="pull-right label label-disabled">Hidden SSID</span>'; } else { $wlan['ssid_bcast_label'] = ''; } if ($port = get_port_by_ifIndex($device['device_id'], $wlan['wlan_index'])) { $wlan['port_link'] = generate_entity_link('port', $port); } echo '<tr class="' . $wlan['row_class'] . '"> <td class="state-marker"></td>'; echo '<td><span class="entity">' . generate_entity_link('wifi_wlan', $wlan) . $wlan['ssid_bcast_label'] . '</span><br />' . $wlan['wlan_ssid'] . '</td>'; echo '<td><span class="entity">' . $wlan['port_link'] . '</span></td>'; echo '<td>' . $wlan['wlan_bssid'] . '<br />' . $wlan['wlan_bss_type'] . '</td>'; echo '<td>' . $wlan['type'] . '<br />Ch.' . $wlan['wlan_channel'] . ' (' . $wlan['freq'] . 'MHz)</td>'; echo '<td>' . $wlan['wlan_prot_mode'] . '<br />' . $wlan['igmp_label'] . '</td>'; echo '<td>' . $wlan['wlan_beacon_period'] . 'ms<br />' . $wlan['wlan_dtim_period'] . '</td>'; echo '<td>' . $wlan['wlan_frag_thresh'] . 'B<br />' . $wlan['wlan_rts_thresh'] . 'B</td>'; echo '</tr>'; } echo "</table>"; $pagetitle[] = "Radios"; // EOF // FIXME wot? vv function humanize_wifi_wlan(&$wlan) { }
} $background = get_percentage_colours($percent); $graph_array = array(); $graph_array['height'] = "100"; $graph_array['width'] = "210"; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $mempool['mempool_id']; $graph_array['type'] = $graph_type; $graph_array['from'] = $config['time']['day']; $graph_array['legend'] = "no"; $link_array = $graph_array; $link_array['page'] = "graphs"; unset($link_array['height'], $link_array['width'], $link_array['legend']); $link = generate_url($link_array); $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; // $graph_array['style'][] = 'margin-top: -6px'; $minigraph = generate_graph_tag($graph_array); echo '<tr class="' . $background['class'] . '"> <td class="state-marker"></td> <td class="entity" style="max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><strong>' . generate_entity_link('mempool', $mempool) . '</strong></td> <td style="width: 90px">' . overlib_link($link, $minigraph, $overlib_content) . '</td> <td style="width: 200px">' . overlib_link($link, print_percentage_bar(200, 20, $percent, $used . "/" . $total . " (" . $percent . "%)", "ffffff", $background['left'], $free . " (" . (100 - $percent) . "%)", "ffffff", $background['right']), $overlib_content) . '</td> </tr>'; } echo "</table>"; echo generate_box_close(); } // EOF
function generate_p2pradio_row($radio, $vars) { global $config; $table_cols = 12; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $table_cols++; } // Add a column for device. $row .= '<tr class="' . $radio['row_class'] . '"> <td class="state-marker"></td> <td></td>'; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $row .= '<td class="entity">' . generate_device_link($radio) . '</td>'; } $row .= ' <td class="entity">' . generate_entity_link('p2pradio', $radio) . '</td> <td width="100"><span class="label">' . strtoupper($radio['radio_modulation']) . '</span></td> <td width="90">' . format_si($radio['radio_cur_capacity']) . 'bps</td> <td width="100">' . format_si($radio['radio_total_capacity']) . 'bps</td> <td width="90">' . format_si($radio['radio_eth_capacity']) . 'bps</td> <td width="70">' . ($radio['radio_e1t1_channels'] ?: "N/A") . '</td> <td width="70"><span class="label label-error">' . $radio['radio_tx_power'] . 'dBm</span></td> <td width="70"><span class="label label-warning">' . $radio['radio_rx_level'] . 'dBm</span></td> <td width="90"><span class="label label-success">' . $radio['radio_tx_freq'] / 1000000 . 'GHz</span></td> <td width="90"><span class="label label-info">' . $radio['radio_rx_freq'] / 1000000 . 'GHz</span></td> '; $row .= '</tr>'; if ($vars['view'] == "graphs") { $graphs = array('capacity', 'power', 'rxlevel', 'gain', 'rmse', 'symbol_rates'); $show_graph_title = TRUE; } elseif (isset($vars['graph'])) { $graphs = explode(",", $vars['graph']); } if (is_array($graphs)) { $row .= '<tr class="' . $radio['row_class'] . '">'; $row .= '<td class="state-marker"></td>'; $row .= '<td colspan=' . $table_cols . '>'; unset($graph_array['height'], $graph_array['width'], $graph_array['legend']); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $radio['radio_id']; foreach ($graphs as $graph_type) { $graph_array['type'] = 'p2pradio_' . $graph_type; if ($show_graph_title) { $row .= '<h3>' . $config['graph_types']['p2pradio'][$graph_type]['name'] . '</h3>'; } $row .= generate_graph_row($graph_array, TRUE); } $row .= "</td>"; $row .= "</tr>"; } return $row; }
/** * 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; } } // 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 '<table class="table table-condensed table-bordered table-striped table-rounded table-hover"> <thead> <tr> <th class="state-marker"></th> <th style="width: 1px;"></th>'; // No table id //<th style="width: 5%;">Id</th>'); if ($list['device_id']) { echo ' <th style="width: 15%">设备</th>'; } if ($list['alert_test_id']) { echo ' <th style="min-width: 15%;">警报</th>'; } if ($list['entity_type']) { echo ' <th style="width: 10%">类型</th>'; } if ($list['entity_id']) { echo ' <th style="">实体</th>'; } echo ' <th style="width: 20px">状态</th> <th style="width: 100px;">信息</th> <th style="width: 90px;">已检测</th> <th style="width: 90px;">已更改</th> <th style="width: 90px;">警告</th> <th style="width: 20px;"></th> </tr> </thead> <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="location.href=\'' . 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>'; } // Print link to the alert rule page if ($list['alert_test_id']) { echo '<td><a href="', generate_url(array('page' => 'alert_check', 'alert_test_id' => $alert_rule['alert_test_id'])), '">', $alert_rule['alert_name'], '</a></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>'; } echo '<td>'; ## FIXME -- generate a nice popup with parsed information from the state array echo overlib_link("", '<i class="icon-info-sign"></i>', "<pre>" . print_r(json_decode($alert['state'], TRUE), TRUE) . "</pre>", NULL); echo '</td>'; echo '<td class="' . $alert['class'] . '">' . $alert['last_message'] . '</td>'; echo '<td>' . overlib_link('', $alert['checked'], format_unixtime($alert['last_checked'], 'r'), NULL) . '</td>'; echo '<td>' . overlib_link('', $alert['changed'], format_unixtime($alert['last_changed'], 'r'), NULL) . '</td>'; echo '<td>' . overlib_link('', $alert['alerted'], format_unixtime($alert['last_alerted'], 'r'), NULL) . '</td>'; echo '<td><a href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $alert['alert_table_id'])) . '"><i class="oicon-gear" /></a></td>'; echo '</tr>'; } echo ' </tbody>' . PHP_EOL; echo '</table>' . PHP_EOL; if ($vars['pagination'] && !$short) { echo $pagination_html; } }
/** * Display device inventory hierarchy. * * @param string $ent, $level, $class * @return none * */ function print_ent_physical($ent, $level, $class) { global $device; $ents = dbFetchRows("SELECT * FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalContainedIn` = ? ORDER BY `entPhysicalContainedIn`, `entPhysicalIndex`", array($device['device_id'], $ent)); foreach ($ents as $ent) { $link = ''; $text = " <li class='{$class}'>"; /* Currently no icons for: JUNIPER-MIB::jnxFruType.10.1.1.0 = INTEGER: frontPanelModule(8) JUNIPER-MIB::jnxFruType.12.1.0.0 = INTEGER: controlBoard(5) For Geist RCX, IPOMan: outlet relay */ switch ($ent['entPhysicalClass']) { case 'chassis': $text .= '<i class="oicon-database"></i> '; break; case 'module': case 'portInterfaceCard': $text .= '<i class="oicon-drive"></i> '; break; case 'port': $text .= '<i class="oicon-network-ethernet"></i> '; break; case 'container': case 'flexiblePicConcentrator': $text .= '<i class="oicon-box-zipper"></i> '; break; case 'stack': $text .= '<i class="oicon-databases"></i> '; break; case 'fan': case 'airflowSensor': $text .= '<i class="oicon-weather-wind"></i> '; break; case 'powerSupply': case 'powerEntryModule': $text .= '<i class="oicon-plug"></i> '; break; case 'backplane': $text .= '<i class="oicon-zones"></i> '; break; case 'sensor': $text .= '<i class="oicon-asterisk"></i> '; $sensor = dbFetchRow("SELECT * FROM `sensors` AS S\n LEFT JOIN `sensors-state` AS ST ON S.`sensor_id` = ST.`sensor_id`\n WHERE `device_id` = ? AND (`entPhysicalIndex` = ? OR `sensor_index` = ?)", array($device['device_id'], $ent['entPhysicalIndex'], $ent['entPhysicalIndex'])); break; default: $text .= '<i class="oicon-chain"></i> '; } if ($ent['entPhysicalParentRelPos'] > '-1') { $text .= '<strong>' . $ent['entPhysicalParentRelPos'] . '.</strong> '; } $ent_text = ''; if ($ent['ifIndex']) { $interface = get_port_by_ifIndex($device['device_id'], $ent['ifIndex']); $ent['entPhysicalName'] = generate_port_link($interface); } if ($ent['entPhysicalModelName'] && $ent['entPhysicalName']) { $ent_text .= "<strong>" . $ent['entPhysicalModelName'] . "</strong> (" . $ent['entPhysicalName'] . ")"; } elseif ($ent['entPhysicalModelName']) { $ent_text .= "<strong>" . $ent['entPhysicalModelName'] . "</strong>"; } elseif (is_numeric($ent['entPhysicalName']) && $ent['entPhysicalVendorType']) { $ent_text .= "<strong>" . $ent['entPhysicalName'] . " " . $ent['entPhysicalVendorType'] . "</strong>"; } elseif ($ent['entPhysicalName']) { $ent_text .= "<strong>" . $ent['entPhysicalName'] . "</strong>"; } elseif ($ent['entPhysicalDescr']) { $ent_text .= "<strong>" . $ent['entPhysicalDescr'] . "</strong>"; } $ent_text .= "<br /><div class='small' style='margin-left: 20px;'>" . $ent['entPhysicalDescr']; if ($ent['entPhysicalClass'] == "sensor" && $sensor['sensor_value']) { $ent_text .= ' (' . $sensor['sensor_value'] . ' ' . $sensor['sensor_class'] . ')'; $link = generate_entity_link('sensor', $sensor, $ent_text, NULL, FALSE); } $text .= $link ? $link : $ent_text; if ($ent['entPhysicalSerialNum']) { $text .= ' <span class="text-info">[Serial: ' . $ent['entPhysicalSerialNum'] . ']</span> '; } $text .= "</div>"; echo $text; $count = dbFetchCell("SELECT COUNT(*) FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalContainedIn` = ?", array($device['device_id'], $ent['entPhysicalIndex'])); if ($count) { echo "<ul>"; print_ent_physical($ent['entPhysicalIndex'], $level + 1, ''); echo "</ul>"; } echo "</li>"; } }
function generate_pseudowire_row($pw, $vars) { global $config; humanize_pseudowire($pw); $table_cols = 11; $graph_array = array(); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $pw['pseudowire_id']; $graph_array['type'] = $pw['graph']; $graph_array['legend'] = "no"; $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; $graph_array['from'] = $config['time']['day']; if ($pw['event'] && $pw['pwOperStatus']) { $mini_graph = generate_graph_tag($graph_array); } else { // Do not show "Draw Error" minigraph $mini_graph = ''; } $out = '<tr class="' . $pw['row_class'] . '"><td class="state-marker"></td>'; $out .= '<td class="entity" style="text-align: right;">' . generate_entity_link('pseudowire', $pw, NULL, NULL, TRUE, TRUE) . '</td>'; $out .= '<td>' . nicecase($pw['pwType']) . '/' . nicecase($pw['pwPsnType']) . '</td>'; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $out .= '<td class="entity">' . generate_device_link($pw, NULL, array('tab' => 'pseudowires')) . '</td>'; $table_cols++; } $out .= '<td class="entity">' . generate_entity_link('port', $pw['port_id']) . '</td>'; $out .= '<td><span class="text-success"><i class="glyphicon glyphicon-arrow-right"></i></span></td>'; if ($pw['peer_port_id']) { $out .= '<td class="entity">' . generate_entity_link('device', $pw['peer_device_id']) . '</td>'; $out .= '<td class="entity">' . generate_entity_link('port', $pw['peer_port_id']) . '</td>'; } else { $out .= '<td class="entity">' . generate_popup_link('ip', $pw['peer_addr']) . '</td>'; $out .= '<td>' . $pw['pwRemoteIfString'] . '</td>'; } $out .= '<td>' . generate_entity_link('pseudowire', $pw, $mini_graph, NULL, FALSE) . '</td>'; $out .= '<td style="white-space: nowrap">' . generate_tooltip_link(NULL, formatUptime($config['time']['now'] - $pw['last_change'], 'short-2') . ' ago', format_unixtime($pw['last_change'])) . '</td>'; $out .= '<td style="text-align: right;"><strong><span class="' . $pw['pw_class'] . '">' . $pw['event'] . '</span></strong></td>'; $out .= '<td style="text-align: right;"><strong><span class="' . $pw['pw_class'] . '">' . $pw['pwOperStatus'] . '</span></strong></td>'; $out .= '<td>' . formatUptime($pw['pwUptime'], 'short-2') . '</td>'; $out .= '</tr>'; if ($vars['graph'] || $vars['view'] == "graphs" || $vars['id'] == $pw['pseudowire_id']) { // If id set in vars, display only specific graphs $graph_array = array(); $graph_array['type'] = $vars['graph'] ? $vars['graph'] : $pw['graph']; $graph_array['id'] = $pw['pseudowire_id']; $out .= '<tr class="' . $pw['row_class'] . '">'; $out .= ' <td class="state-marker"></td>'; $out .= ' <td colspan="' . $table_cols . '">'; $out .= generate_graph_row($graph_array, TRUE); $out .= ' </td>'; $out .= '</tr>'; } return $out; }