From 011cb0f0af107a12712bb7476f044ae6cd458c4b Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Tue, 23 Sep 2014 18:05:44 +0200 Subject: [PATCH] Big improvement on the SNMP statistics section * pandora_console/operation/snmpconsole/snmp_view.php: Removed the code of the statistics section. * pandora_console/operation/snmpconsole/snmp_statistics.php: Added file. Statistics section for SNMP. --- .../operation/snmpconsole/snmp_statistics.php | 209 +++++ .../operation/snmpconsole/snmp_view.php | 789 ++++++++---------- 2 files changed, 563 insertions(+), 435 deletions(-) create mode 100644 pandora_console/operation/snmpconsole/snmp_statistics.php diff --git a/pandora_console/operation/snmpconsole/snmp_statistics.php b/pandora_console/operation/snmpconsole/snmp_statistics.php new file mode 100644 index 0000000000..d5d6cc8500 --- /dev/null +++ b/pandora_console/operation/snmpconsole/snmp_statistics.php @@ -0,0 +1,209 @@ +' . + html_print_image("images/normal_screen.png", true, array("title" => __('Normal screen'))) . ''; +} +else { + $fullscreen['text'] = '' . + html_print_image("images/full_screen.png", true, array("title" => __('Full screen'))) . ''; +} + +// List +$list = array(); +$list['text'] = '' . + html_print_image("images/op_snmp.png", true, array ("title" => __('List'))) .''; + +// Statistics (This file) +$statistics = array(); +$statistics['active'] = true; +$statistics['text'] = '' . + html_print_image("images/op_reporting.png", true, array ("title" => __('Statistics'))) .''; + +// Header +ui_print_page_header(__("SNMP Console"), "images/op_snmp.png", false, + "", false, array($fullscreen, $list, $statistics)); + +// Retrieving the data + +$user_groups = users_get_groups($config['id_user'], "AR", false); +$user_groups_str = '0'; +if (!empty($user_groups)) { + $user_groups_str = implode(",", array_keys($user_groups)); +} + +$last_month_timestamp = date("Y-m-d H:i:s", time() - SECONDS_1MONTH); + +$sql_traps_generated = "SELECT %s, COUNT(id_trap) AS num + FROM ttrap + WHERE timestamp >= '%s' + AND (source = '' + OR source NOT IN (SELECT direccion FROM tagente) + OR source IN (SELECT direccion + FROM tagente + WHERE id_grupo IN (%s))) + GROUP BY %s + ORDER BY num DESC, timestamp DESC + LIMIT 25"; + +$sql_traps_generated_by_source = sprintf($sql_traps_generated, "source", $last_month_timestamp, $user_groups_str, "source"); +$sql_traps_generated_by_oid = sprintf($sql_traps_generated, "oid", $last_month_timestamp, $user_groups_str, "oid"); + +$traps_generated_by_source = db_get_all_rows_sql($sql_traps_generated_by_source); +$traps_generated_by_oid = db_get_all_rows_sql($sql_traps_generated_by_oid); + +// No traps +if (empty($traps_generated_by_source) || empty($traps_generated_by_oid)) { + echo '
'.__('There are no SNMP traps in database').'
'; + return; +} + +$water_mark = array('file' => $config['homedir'] . "/images/logo_vertical_water.png", + 'url' => ui_get_full_url("/images/logo_vertical_water.png")); + +// By SOURCE +$table_source = new StdClass(); +$table_source->width = '100%'; +$table_source->head[] = __("Traps received by source") . " - " . sprintf(__('Top %d'), 25); +$table_source->head_colspan[] = 2; +$table_source->headstyle[] = "background-color: #82b92e"; +$table_source->size = array(); +$table_source->size['table'] = '50%'; +$table_source->size['graph'] = '50%'; +$table_source->data = array(); + +$table_source_row = array(); + +$table_source_data = new StdClass(); +$table_source_data->width = '100%'; +$table_source_data->head = array(); +$table_source_data->head['source'] = __('Source IP'); +$table_source_data->head['num'] = __('Number'); +$table_source_data->data = array(); + +$table_source_graph_data = array(); + +foreach ($traps_generated_by_source as $trap) { + $row = array(); + + $agent = agents_get_agent_with_ip($trap['source']); + if ($agent === false) { + $row['source'] = ''.$trap["source"].''; + } + else { + $agent_id = $agent["id_agente"]; + $agent_name = ui_print_truncate_text($agent["nombre"], "agent_medium", true, true, true, '[…]', ''); + $row['source'] = ""; + $row['source'] .= "$agent_name"; + } + $row['num'] = (int) $trap['num']; + + $table_source_data->data[] = $row; + + $table_source_graph_data[$trap["source"]] = (int) $trap["num"]; +} + +$table_source_row['table'] = html_print_table($table_source_data, true); +unset($table_source_data); + +if (empty($table_source_graph_data)) + $table_source_graph = graph_nodata_image(); +else + $table_source_graph = pie3d_graph($config['flash_charts'], $table_source_graph_data, 400, 550, __("Other"), + '', $water_mark, $config['fontpath'], $config['font_size'], 1); + +$table_source_row['graph'] = $table_source_graph; + +$table_source->data[] = $table_source_row; + +html_print_table($table_source); +unset($table_source); + +// By OID +$table_oid = new StdClass(); +$table_oid->width = '100%'; +$table_oid->head[] = __("Traps received by OID") . " - " . sprintf(__('Top %d'), 25); +$table_oid->head_colspan[] = 2; +$table_oid->headstyle[] = "background-color: #82b92e"; +$table_oid->size = array(); +$table_oid->size['table'] = '50%'; +$table_oid->size['graph'] = '50%'; +$table_oid->data = array(); + +$table_oid_row = array(); + +$table_oid_data = new StdClass(); +$table_oid_data->width = '100%'; +$table_oid_data->head = array(); +$table_oid_data->head['oid'] = __('Trap OID'); +$table_oid_data->head['num'] = __('Number'); +$table_oid_data->data = array(); + +$table_oid_graph_data = array(); + +foreach ($traps_generated_by_oid as $trap) { + $table_oid_data->data[] = array( + 'oid' => $trap['oid'], + 'num' => (int) $trap['num'] + ); + + $table_oid_graph_data[$trap["oid"]] = (int) $trap["num"]; +} + +$table_oid_row['table'] = html_print_table($table_oid_data, true); +unset($table_oid_data); + +if (empty($table_oid_graph_data)) + $table_oid_graph = graph_nodata_image(); +else + $table_oid_graph = pie3d_graph($config['flash_charts'], $table_oid_graph_data, 400, 550, __("Other"), + '', $water_mark, $config['fontpath'], $config['font_size'], 1); + +$table_oid_row['graph'] = $table_oid_graph; + +$table_oid->data[] = $table_oid_row; + +html_print_table($table_oid); +unset($table_oid); + +?> \ No newline at end of file diff --git a/pandora_console/operation/snmpconsole/snmp_view.php b/pandora_console/operation/snmpconsole/snmp_view.php index 8e16bd4993..c2372746ce 100644 --- a/pandora_console/operation/snmpconsole/snmp_view.php +++ b/pandora_console/operation/snmpconsole/snmp_view.php @@ -40,7 +40,6 @@ $offset = (int) get_parameter ('offset',0); $trap_type = (int) get_parameter ('trap_type', -1); $group_by = (int)get_parameter('group_by', 0); $refr = (int)get_parameter("refr", 0); -$tab = (string) get_parameter("tab"); $user_groups = users_get_groups ($config['id_user'],"AR", false); $str_user_groups = ''; @@ -65,22 +64,11 @@ $url = "index.php?sec=estado&" . "trap_type=" . $trap_type . "&" . "group_by=" .$group_by; -switch ($tab) { - case 'statistics': - $statistics['active'] = true; - break; - - default: - $list['active'] = true; - break; -} -$statistics['text'] = '' . +$statistics['text'] = '' . html_print_image("images/op_reporting.png", true, array ("title" => __('Statistics'))) .''; $list['text'] = '' . html_print_image("images/op_snmp.png", true, array ("title" => __('List'))) .''; - -if ($tab) - $url .= "&tab=$tab"; +$list['active'] = true; if ($config["pure"]) { $fullscreen['text'] = '' . html_print_image("images/normal_screen.png", true, array("title" => __('Normal screen'))) . ''; @@ -354,441 +342,372 @@ ui_toggle($filter, __('Toggle filter(s)')); unset ($table); -if ($tab == '') { - - $traps = db_get_all_rows_sql($sql); - $trapcount = (int) db_get_value_sql($sql_count); - - // No traps - if (empty ($traps)) { - echo '
'.__('There are no SNMP traps in database').'
'; - return; - } - - if (($config['dbtype'] == 'oracle') && ($traps !== false)) { - for ($i=0; $i < count($traps); $i++) { - unset($traps[$i]['rnum']); - } - } - - $url_snmp = "index.php?" . - "sec=snmpconsole&" . - "sec2=operation/snmpconsole/snmp_view&" . - "filter_severity=" . $filter_severity . "&" . - "filter_fired=" . $filter_fired . "&" . - "filter_status=" . $filter_status . "&" . - "refr=" . ((int)get_parameter('refr', 0)) . "&" . - "pure=" . $config["pure"] . "&" . - "group_by=" . $group_by . "&" . - "free_search_string=" . $free_search_string; - - $urlPagination = $url_snmp . "&pagination=" . $pagination . "&offset=" . $offset; - - ui_pagination ($trapcount, $urlPagination, $offset, $pagination); - - echo '
'; - - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->width = '99%'; - $table->class = "databox"; - $table->head = array (); - $table->size = array (); - $table->data = array (); - $table->align = array (); - - $table->head[0] = __('Status'); - $table->align[0] = "center"; - $table->size[0] = '5%'; - - $table->head[1] = __('SNMP Agent'); - $table->align[1] = "center"; - $table->size[1] = '15%'; - - $table->head[2] = __('OID'); - $table->align[2] = "center"; - $table->size[2] = '18%'; - - if ($group_by) { - $table->head[3] = __('Count'); - $table->align[3] = "center"; - $table->size[3] = '5%'; - } - - $table->head[4] = __('Value'); - $table->align[4] = "center"; - $table->size[4] = '10%'; - - $table->head[5] = __('User ID'); - $table->align[5] = "center"; - $table->size[5] = '10%'; - - $table->head[6] = __('Timestamp'); - $table->align[6] = "center"; - $table->size[6] = '10%'; - - $table->head[7] = __('Alert'); - $table->align[7] = "center"; - $table->size[7] = '5%'; - - $table->head[8] = __('Action'); - $table->align[8] = "center"; - $table->size[8] = '10%'; - - $table->head[9] = html_print_checkbox_extended ("allbox", 1, false, false, "javascript:CheckAll();", 'class="chk" title="'.__('All').'"', true); - $table->align[9] = "center"; - $table->size[9] = '5%'; - - $table->style[8] = "background: #F3F3F3; color: #111 !important;"; - - // Skip offset records - $idx = 0; - if ($traps !== false) { - - foreach ($traps as $trap) { - $data = array (); - if (empty($trap["description"])){ - $trap["description"]=""; - } - $severity = enterprise_hook ('get_severity', array ($trap)); - if ($severity === ENTERPRISE_NOT_HOOK) { - $severity = $trap["alerted"] == 1 ? $trap["priority"] : 1; - } - - //Status - if ($trap["status"] == 0) { - $data[0] = html_print_image("images/pixel_red.png", true, array("title" => __('Not validated'), "width" => "20", "height" => "20")); - } - else { - $data[0] = html_print_image("images/pixel_green.png", true, array("title" => __('Validated'), "width" => "20", "height" => "20")); - } - - // Agent matching source address - $table->cellclass[$idx][1] = get_priority_class ($severity); - $agent = agents_get_agent_with_ip ($trap['source']); - if ($agent === false) { - if (! check_acl ($config["id_user"], 0, "AR")) { - continue; - } - $data[1] = ''.$trap["source"].''; - } - else { - if (! check_acl ($config["id_user"], $agent["id_grupo"], "AR")) { - continue; - } - $data[1] = ''; - $data[1] .= ''.$agent["nombre"].''; - } - - //OID - $table->cellclass[$idx][2] = get_priority_class ($severity); - $data[2] = '' . (empty($trap["oid"]) ? __('N/A') : $trap["oid"]) .''; - - //Count - if ($group_by) { - $sql = "SELECT * FROM ttrap WHERE 1=1 - $where_without_group - AND oid='".$trap['oid']."' - AND source='".$trap['source']."'"; - $group_traps = db_get_all_rows_sql($sql); - $count_group_traps = count($group_traps); - $table->cellclass[$idx][3] = get_priority_class ($severity); - $data[3] = ''.$count_group_traps.''; - } - //Value - $table->cellclass[$idx][4] = get_priority_class ($severity); - if (empty ($trap["value"])) { - $data[4] = __('N/A'); - } - else { - $data[4] = ui_print_truncate_text($trap["value"], GENERIC_SIZE_TEXT, false); - } - - //User - $table->cellclass[$idx][5] = get_priority_class ($severity); - if (!empty ($trap["status"])) { - $data[5] = ''.substr ($trap["id_usuario"], 0, 8).''; - if (!empty($trap["id_usuario"])) - $data[5] .= ui_print_help_tip(get_user_fullname($trap["id_usuario"]), true); - } - else { - $data[5] = '--'; - } - - // Timestamp - $table->cellclass[$idx][6] = get_priority_class ($severity); - $data[6] = ''; - $data[6] .= ui_print_timestamp ($trap["timestamp"], true); - $data[6] .= ''; - - // Use alert severity if fired - if (!empty ($trap["alerted"])) { - $data[7] = html_print_image("images/pixel_yellow.png", true, array("width" => "20", "height" => "20", "border" => "0", "title" => __('Alert fired'))); - } - else { - $data[7] = html_print_image("images/pixel_gray.png", true, array("width" => "20", "height" => "20", "border" => "0", "title" => __('Alert not fired'))); - } - - //Actions - $data[8] = ""; - - if (empty ($trap["status"]) && check_acl ($config["id_user"], 0, "IW")) { - $data[8] .= '' . html_print_image("images/ok.png", true, array("border" => '0', "title" => __('Validate'))) . ' '; - } - if ($trap['source'] == '') { - $is_admin = db_get_value('is_admin', 'tusuario', 'id_user',$config['id_user']); - if ($is_admin) { - $data[8] .= '' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . ' '; - } - } else { - $agent_trap_group = db_get_value('id_grupo', 'tagente', 'nombre', $trap['source']); - if ((check_acl ($config["id_user"], $agent_trap_group, "AW"))) { - $data[8] .= '' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . ' '; - } - } - - $data[8] .= '' . html_print_image("images/eye.png", true, array("alt" => __('Show more'), "title" => __('Show more'))) .''; - $data[8] .= enterprise_hook ('editor_link', array ($trap)); - - - $data[9] = html_print_checkbox_extended ("snmptrapid[]", $trap["id_trap"], false, false, '', 'class="chk"', true); - - array_push ($table->data, $data); - - //Hiden file for description - $string = ' - - - - - - - - '; - - if ($trap["description"] != "") { - $string .= ' - - - '; - } - - if ($trap["type"] != "") { - $trap_types = array(-1 => __('None'), 0 => __('Cold start (0)'), 1 => __('Warm start (1)'), 2 => __('Link down (2)'), 3 => __('Link up (3)'), 4 => __('Authentication failure (4)'), 5 => __('Other')); - - switch ($trap["type"]) { - case -1: - $desc_trap_type = __('None'); - break; - case 0: - $desc_trap_type = __('Cold start (0)'); - break; - case 1: - $desc_trap_type = __('Warm start (1)'); - break; - case 2: - $desc_trap_type = __('Link down (2)'); - break; - case 3: - $desc_trap_type = __('Link up (3)'); - break; - case 4: - $desc_trap_type = __('Authentication failure (4)'); - break; - default: - $desc_trap_type = __('Other'); - break; - } - $string .= ''; - } - - if ($group_by) { - $sql = "SELECT * FROM ttrap WHERE 1=1 - $where_without_group - AND oid='".$trap['oid']."' - AND source='".$trap['source']."'"; - $group_traps = db_get_all_rows_sql($sql); - $count_group_traps = count($group_traps); - - $sql = "SELECT timestamp FROM ttrap WHERE 1=1 - $where_without_group - AND oid='".$trap['oid']."' - AND source='".$trap['source']."' - ORDER BY `timestamp` DESC"; - $last_trap = db_get_value_sql($sql); - - $sql = "SELECT timestamp FROM ttrap WHERE 1=1 - $where_without_group - AND oid='".$trap['oid']."' - AND source='".$trap['source']."' - ORDER BY `timestamp` ASC"; - $first_trap = db_get_value_sql($sql); - - $string .= ' - - - '; - $string .= ' - - - '; - $string .= ' - - - '; - - } - $string .= '
' . __('Custom data:') . ''; - - if ($group_by) { - $new_url = "index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&" . - "filter_severity=" . $filter_severity . "&" . - "filter_fired=" . $filter_fired . "&" . - "filter_status=" . $filter_status . "&" . - "refr=" . ((int)get_parameter('refr', 0)) . "&" . - "pure=" . $config["pure"] . "&" . - "group_by=0&" . - "free_search_string=" . $free_search_string; - - $string .= ''.__('See more details').''; - } else { - // Print binding vars separately - $binding_vars = explode ("\t", $trap['oid_custom']); - foreach ($binding_vars as $var) { - $string .= $var . "
"; - } - } - - $string .= '
' . '' . __('OID:') . ' ' . $trap['oid'] . '
' . '' . __('Description:') . '' . $trap['description'] . '
' . '' . __('Type:') . '' . $desc_trap_type . '
' . '' . __('Count:') . '' . $count_group_traps . '
' . '' . __('First trap:') . '' . $first_trap . '
' . '' . __('Last trap:') . '' . $last_trap . '
'; - - $data = array($string); //$data = array($trap['description']); - $idx++; - $table->rowclass[$idx] = 'trap_info_' . $trap['id_trap']; - $table->colspan[$idx][0] = 10; - $table->rowstyle[$idx] = 'display: none;'; - array_push ($table->data, $data); - - $idx++; - } - } - - // No matching traps - if ($idx == 0) { - echo '
' . __('No matching traps found') . '
'; - } - else { - html_print_table ($table); - } - - unset ($table); - - echo '
'; - if (check_acl ($config["id_user"], 0, "IW")) { - html_print_submit_button (__('Validate'), "updatebt", false, 'class="sub ok"'); - } - - if (check_acl ($config['id_user'], 0, "IM")) { - echo " "; - html_print_submit_button (__('Delete'), "deletebt", false, 'class="sub delete" onClick="javascript:return confirm(\''.__('Are you sure?').'\')"'); - } - echo "
"; - - - echo '
'; - echo '

' . __('Status') . '

'; - echo html_print_image("images/pixel_green.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Validated'); - echo '
'; - echo html_print_image("images/pixel_red.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not validated'); - echo '
'; - echo '
'; - echo '

' . __('Alert') . '

'; - echo html_print_image("images/pixel_yellow.png", true, array("width" => "20", "height" => "20")) . ' - ' .__('Fired'); - echo '
'; - echo html_print_image("images/pixel_gray.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not fired'); - echo '
'; - echo '
'; - echo '

' . __('Action') . '

'; - echo html_print_image("images/ok.png", true) . ' - ' .__('Validate'); - echo '
'; - echo html_print_image("images/cross.png", true) . ' - ' . __('Delete'); - echo '
'; - echo '
'; - echo '

'.__('Legend').'

'; - foreach (get_priorities () as $num => $name) { - echo ''.$name.''; - echo '
'; - } - echo '
'; - echo '
 
'; +$traps = db_get_all_rows_sql($sql); +$trapcount = (int) db_get_value_sql($sql_count); +// No traps +if (empty ($traps)) { + echo '
'.__('There are no SNMP traps in database').'
'; + return; } -else { - $traps = db_get_all_rows_sql($sql_all); - $trapcount = (int) db_get_value_sql($sql_count); - - // No traps - if (empty ($traps)) { - echo '
'.__('There are no SNMP traps in database').'
'; - return; +if (($config['dbtype'] == 'oracle') && ($traps !== false)) { + for ($i=0; $i < count($traps); $i++) { + unset($traps[$i]['rnum']); } +} - if (($config['dbtype'] == 'oracle') && ($traps !== false)) { - for ($i=0; $i < count($traps); $i++) { - unset($traps[$i]['rnum']); - } - } +$url_snmp = "index.php?" . + "sec=snmpconsole&" . + "sec2=operation/snmpconsole/snmp_view&" . + "filter_severity=" . $filter_severity . "&" . + "filter_fired=" . $filter_fired . "&" . + "filter_status=" . $filter_status . "&" . + "refr=" . ((int)get_parameter('refr', 0)) . "&" . + "pure=" . $config["pure"] . "&" . + "group_by=" . $group_by . "&" . + "free_search_string=" . $free_search_string; - include_once($config['homedir'] . '/include/functions_graph.php'); +$urlPagination = $url_snmp . "&pagination=" . $pagination . "&offset=" . $offset; + +ui_pagination ($trapcount, $urlPagination, $offset, $pagination); + +echo '
'; + +$table->cellpadding = 4; +$table->cellspacing = 4; +$table->width = '99%'; +$table->class = "databox"; +$table->head = array (); +$table->size = array (); +$table->data = array (); +$table->align = array (); + +$table->head[0] = __('Status'); +$table->align[0] = "center"; +$table->size[0] = '5%'; + +$table->head[1] = __('SNMP Agent'); +$table->align[1] = "center"; +$table->size[1] = '15%'; + +$table->head[2] = __('OID'); +$table->align[2] = "center"; +$table->size[2] = '18%'; + +if ($group_by) { + $table->head[3] = __('Count'); + $table->align[3] = "center"; + $table->size[3] = '5%'; +} + +$table->head[4] = __('Value'); +$table->align[4] = "center"; +$table->size[4] = '10%'; + +$table->head[5] = __('User ID'); +$table->align[5] = "center"; +$table->size[5] = '10%'; + +$table->head[6] = __('Timestamp'); +$table->align[6] = "center"; +$table->size[6] = '10%'; + +$table->head[7] = __('Alert'); +$table->align[7] = "center"; +$table->size[7] = '5%'; + +$table->head[8] = __('Action'); +$table->align[8] = "center"; +$table->size[8] = '10%'; + +$table->head[9] = html_print_checkbox_extended ("allbox", 1, false, false, "javascript:CheckAll();", 'class="chk" title="'.__('All').'"', true); +$table->align[9] = "center"; +$table->size[9] = '5%'; + +$table->style[8] = "background: #F3F3F3; color: #111 !important;"; + +// Skip offset records +$idx = 0; +if ($traps !== false) { - $data_aux = array(); foreach ($traps as $trap) { - $source = $trap['source']; - $oid = $trap['oid']; - - if (!isset($data_aux[$source])) - $data_aux[$source] = array(); - - if (!isset($data_aux[$source][$oid])) - $data_aux[$source][$oid] = array('num' => 1, 'text' => ''); - else { - $data_aux[$source][$oid]['num']++; - if (empty($data_aux[$source][$oid]['text'])) - $data_aux[$source][$oid]['text'] = $trap['text']; + $data = array (); + if (empty($trap["description"])){ + $trap["description"]=""; + } + $severity = enterprise_hook ('get_severity', array ($trap)); + if ($severity === ENTERPRISE_NOT_HOOK) { + $severity = $trap["alerted"] == 1 ? $trap["priority"] : 1; } - } - - $id = -1; - $data = array(); - - if (!empty($traps)) { - $data['name'] = __("Traps received by source"); - $data['children'] = array(); - - foreach ($data_aux as $source => $oid_data) { - $children = array(); - $children['id'] = $id++; - $children['name'] = $source; - $children['children'] = array(); - foreach ($oid_data as $oid => $values) { - $children_data = array(); - $children_data['id'] = $id++; - $children_data['name'] = $oid; - $children_data['value'] = $values['num']; - $children_data['tooltip_content'] = ''; - if (!empty($values['text'])) - $children_data['tooltip_content'] .= "" . $values['text'] . "
"; - $children_data['tooltip_content'] .= sprintf(__('%d traps received from this source with this oid'), $values['num']); - $children['children'][] = $children_data; - } - $data['children'][] = $children; + //Status + if ($trap["status"] == 0) { + $data[0] = html_print_image("images/pixel_red.png", true, array("title" => __('Not validated'), "width" => "20", "height" => "20")); } + else { + $data[0] = html_print_image("images/pixel_green.png", true, array("title" => __('Validated'), "width" => "20", "height" => "20")); + } + + // Agent matching source address + $table->cellclass[$idx][1] = get_priority_class ($severity); + $agent = agents_get_agent_with_ip ($trap['source']); + if ($agent === false) { + if (! check_acl ($config["id_user"], 0, "AR")) { + continue; + } + $data[1] = ''.$trap["source"].''; + } + else { + if (! check_acl ($config["id_user"], $agent["id_grupo"], "AR")) { + continue; + } + $data[1] = ''; + $data[1] .= ''.$agent["nombre"].''; + } + + //OID + $table->cellclass[$idx][2] = get_priority_class ($severity); + $data[2] = '' . (empty($trap["oid"]) ? __('N/A') : $trap["oid"]) .''; + + //Count + if ($group_by) { + $sql = "SELECT * FROM ttrap WHERE 1=1 + $where_without_group + AND oid='".$trap['oid']."' + AND source='".$trap['source']."'"; + $group_traps = db_get_all_rows_sql($sql); + $count_group_traps = count($group_traps); + $table->cellclass[$idx][3] = get_priority_class ($severity); + $data[3] = ''.$count_group_traps.''; + } + //Value + $table->cellclass[$idx][4] = get_priority_class ($severity); + if (empty ($trap["value"])) { + $data[4] = __('N/A'); + } + else { + $data[4] = ui_print_truncate_text($trap["value"], GENERIC_SIZE_TEXT, false); + } + + //User + $table->cellclass[$idx][5] = get_priority_class ($severity); + if (!empty ($trap["status"])) { + $data[5] = ''.substr ($trap["id_usuario"], 0, 8).''; + if (!empty($trap["id_usuario"])) + $data[5] .= ui_print_help_tip(get_user_fullname($trap["id_usuario"]), true); + } + else { + $data[5] = '--'; + } + + // Timestamp + $table->cellclass[$idx][6] = get_priority_class ($severity); + $data[6] = ''; + $data[6] .= ui_print_timestamp ($trap["timestamp"], true); + $data[6] .= ''; + + // Use alert severity if fired + if (!empty ($trap["alerted"])) { + $data[7] = html_print_image("images/pixel_yellow.png", true, array("width" => "20", "height" => "20", "border" => "0", "title" => __('Alert fired'))); + } + else { + $data[7] = html_print_image("images/pixel_gray.png", true, array("width" => "20", "height" => "20", "border" => "0", "title" => __('Alert not fired'))); + } + + //Actions + $data[8] = ""; + + if (empty ($trap["status"]) && check_acl ($config["id_user"], 0, "IW")) { + $data[8] .= '' . html_print_image("images/ok.png", true, array("border" => '0', "title" => __('Validate'))) . ' '; + } + if ($trap['source'] == '') { + $is_admin = db_get_value('is_admin', 'tusuario', 'id_user',$config['id_user']); + if ($is_admin) { + $data[8] .= '' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . ' '; + } + } else { + $agent_trap_group = db_get_value('id_grupo', 'tagente', 'nombre', $trap['source']); + if ((check_acl ($config["id_user"], $agent_trap_group, "AW"))) { + $data[8] .= '' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . ' '; + } + } + + $data[8] .= '' . html_print_image("images/eye.png", true, array("alt" => __('Show more'), "title" => __('Show more'))) .''; + $data[8] .= enterprise_hook ('editor_link', array ($trap)); + + + $data[9] = html_print_checkbox_extended ("snmptrapid[]", $trap["id_trap"], false, false, '', 'class="chk"', true); + + array_push ($table->data, $data); + + //Hiden file for description + $string = ' + + + + + + + + '; + + if ($trap["description"] != "") { + $string .= ' + + + '; + } + + if ($trap["type"] != "") { + $trap_types = array(-1 => __('None'), 0 => __('Cold start (0)'), 1 => __('Warm start (1)'), 2 => __('Link down (2)'), 3 => __('Link up (3)'), 4 => __('Authentication failure (4)'), 5 => __('Other')); + + switch ($trap["type"]) { + case -1: + $desc_trap_type = __('None'); + break; + case 0: + $desc_trap_type = __('Cold start (0)'); + break; + case 1: + $desc_trap_type = __('Warm start (1)'); + break; + case 2: + $desc_trap_type = __('Link down (2)'); + break; + case 3: + $desc_trap_type = __('Link up (3)'); + break; + case 4: + $desc_trap_type = __('Authentication failure (4)'); + break; + default: + $desc_trap_type = __('Other'); + break; + } + $string .= ''; + } + + if ($group_by) { + $sql = "SELECT * FROM ttrap WHERE 1=1 + $where_without_group + AND oid='".$trap['oid']."' + AND source='".$trap['source']."'"; + $group_traps = db_get_all_rows_sql($sql); + $count_group_traps = count($group_traps); + + $sql = "SELECT timestamp FROM ttrap WHERE 1=1 + $where_without_group + AND oid='".$trap['oid']."' + AND source='".$trap['source']."' + ORDER BY `timestamp` DESC"; + $last_trap = db_get_value_sql($sql); + + $sql = "SELECT timestamp FROM ttrap WHERE 1=1 + $where_without_group + AND oid='".$trap['oid']."' + AND source='".$trap['source']."' + ORDER BY `timestamp` ASC"; + $first_trap = db_get_value_sql($sql); + + $string .= ' + + + '; + $string .= ' + + + '; + $string .= ' + + + '; + + } + $string .= '
' . __('Custom data:') . ''; + + if ($group_by) { + $new_url = "index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&" . + "filter_severity=" . $filter_severity . "&" . + "filter_fired=" . $filter_fired . "&" . + "filter_status=" . $filter_status . "&" . + "refr=" . ((int)get_parameter('refr', 0)) . "&" . + "pure=" . $config["pure"] . "&" . + "group_by=0&" . + "free_search_string=" . $free_search_string; + + $string .= ''.__('See more details').''; + } else { + // Print binding vars separately + $binding_vars = explode ("\t", $trap['oid_custom']); + foreach ($binding_vars as $var) { + $string .= $var . "
"; + } + } + + $string .= '
' . '' . __('OID:') . ' ' . $trap['oid'] . '
' . '' . __('Description:') . '' . $trap['description'] . '
' . '' . __('Type:') . '' . $desc_trap_type . '
' . '' . __('Count:') . '' . $count_group_traps . '
' . '' . __('First trap:') . '' . $first_trap . '
' . '' . __('Last trap:') . '' . $last_trap . '
'; + + $data = array($string); //$data = array($trap['description']); + $idx++; + $table->rowclass[$idx] = 'trap_info_' . $trap['id_trap']; + $table->colspan[$idx][0] = 10; + $table->rowstyle[$idx] = 'display: none;'; + array_push ($table->data, $data); + + $idx++; } - - echo graph_snmp_traps_treemap($data, 'auto', 500); } +// No matching traps +if ($idx == 0) { + echo '
' . __('No matching traps found') . '
'; +} +else { + html_print_table ($table); +} + +unset ($table); + +echo '
'; +if (check_acl ($config["id_user"], 0, "IW")) { + html_print_submit_button (__('Validate'), "updatebt", false, 'class="sub ok"'); +} + +if (check_acl ($config['id_user'], 0, "IM")) { + echo " "; + html_print_submit_button (__('Delete'), "deletebt", false, 'class="sub delete" onClick="javascript:return confirm(\''.__('Are you sure?').'\')"'); +} +echo "
"; + + +echo '
'; +echo '

' . __('Status') . '

'; +echo html_print_image("images/pixel_green.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Validated'); +echo '
'; +echo html_print_image("images/pixel_red.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not validated'); +echo '
'; +echo '
'; +echo '

' . __('Alert') . '

'; +echo html_print_image("images/pixel_yellow.png", true, array("width" => "20", "height" => "20")) . ' - ' .__('Fired'); +echo '
'; +echo html_print_image("images/pixel_gray.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not fired'); +echo '
'; +echo '
'; +echo '

' . __('Action') . '

'; +echo html_print_image("images/ok.png", true) . ' - ' .__('Validate'); +echo '
'; +echo html_print_image("images/cross.png", true) . ' - ' . __('Delete'); +echo '
'; +echo '
'; +echo '

'.__('Legend').'

'; +foreach (get_priorities () as $num => $name) { + echo ''.$name.''; + echo '
'; +} +echo '
'; +echo '
 
'; + + ?>