2014-06-10 Alejandro Gallardo <alejandro.gallardo@artica.es>

* include/functions_graph.php: Added the function
	"graph_snmp_traps_treemap".

	* include/functions_netflow.php: Fixed a little error.

	* operation/snmpconsole/snmp_view.php: Fixed the pagination.
	Now is possible to see a treemap graph of oid per agent with
	the snmptraps received.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10156 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
alexhigh 2014-06-10 15:21:58 +00:00
parent 01c0086c1a
commit c747b15a32
4 changed files with 518 additions and 395 deletions

View File

@ -1,3 +1,14 @@
2014-06-10 Alejandro Gallardo <alejandro.gallardo@artica.es>
* include/functions_graph.php: Added the function
"graph_snmp_traps_treemap".
* include/functions_netflow.php: Fixed a little error.
* operation/snmpconsole/snmp_view.php: Fixed the pagination.
Now is possible to see a treemap graph of oid per agent with
the snmptraps received.
2014-06-10 Miguel de Dios <miguel.dedios@artica.es>
* extensions/update_manager.php, extensions/update_manager/*,

View File

@ -3246,7 +3246,7 @@ function graph_netflow_circular_mesh ($data, $unit, $radius = 700) {
}
/**
* Print a rescangular graph with the traffic of the ports for each IP
* Print a rectangular graph with the traffic of the ports for each IP
*/
function graph_netflow_host_traffic ($data, $unit, $width = 700, $height = 700) {
global $config;
@ -4082,4 +4082,21 @@ function get_criticity_pie_colors ($data_graph) {
return $colors;
}
/**
* Print a rectangular graph with the snmptraps received
*/
function graph_snmp_traps_treemap ($data, $width = 700, $height = 700) {
global $config;
if (empty ($data)) {
return fs_error_image ();
}
include_once($config['homedir'] . "/include/graphs/functions_d3.php");
return d3_tree_map_graph ($data, $width, $height, true);
}
?>

View File

@ -1362,23 +1362,26 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
$id = -1;
$data = array();
$data['name'] = __("Host detailed traffic") . ": " . $type;
$data['children'] = array();
foreach ($data_aux as $address => $ports) {
$children = array();
$children['id'] = $id++;
$children['name'] = $address;
$children['children'] = array();
foreach ($ports as $port => $value) {
$children_data = array();
$children_data['id'] = $id++;
$children_data['name'] = $port;
$children_data['value'] = $value;
$children_data['tooltip_content'] = "$port: <b>" . format_numeric($value) . " " . netflow_format_unit($unit) . "</b>";
$children['children'][] = $children_data;
if (! empty($netflow_data)) {
$data['name'] = __("Host detailed traffic") . ": " . $type;
$data['children'] = array();
foreach ($data_aux as $address => $ports) {
$children = array();
$children['id'] = $id++;
$children['name'] = $address;
$children['children'] = array();
foreach ($ports as $port => $value) {
$children_data = array();
$children_data['id'] = $id++;
$children_data['name'] = $port;
$children_data['value'] = $value;
$children_data['tooltip_content'] = "$port: <b>" . format_numeric($value) . " " . netflow_format_unit($unit) . "</b>";
$children['children'][] = $children_data;
}
$data['children'][] = $children;
}
$data['children'][] = $children;
}
return graph_netflow_host_traffic ($data, netflow_format_unit($unit), 'auto', 400);

View File

@ -40,6 +40,7 @@ $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 = '';
@ -63,18 +64,34 @@ $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'] = '<a href="' . $url . '&pure=' . $config["pure"] . '&refr=' . $refr . '&tab=statistics">' .
html_print_image("images/op_reporting.png", true, array ("title" => __('Statistics'))) .'</a>';
$list['text'] = '<a href="' . $url . '&pure=' . $config["pure"] . '&refr=' . $refr . '">' .
html_print_image("images/op_snmp.png", true, array ("title" => __('List'))) .'</a>';
if ($tab)
$url .= "&tab=$tab";
if ($config["pure"]) {
$link['text'] = '<a target="_top" href="'.$url.'&pure=0&refr=' . $refr . '">' . html_print_image("images/normal_screen.png", true, array("title" => __('Normal screen'))) . '</a>';
$fullscreen['text'] = '<a target="_top" href="'.$url.'&pure=0&refr=' . $refr . '">' . html_print_image("images/normal_screen.png", true, array("title" => __('Normal screen'))) . '</a>';
}
else {
// Fullscreen
$link['text'] = '<a target="_top" href="'.$url.'&pure=1&refr=' . $refr . '">' . html_print_image("images/full_screen.png", true, array("title" => __('Full screen'))) . '</a>';
$fullscreen['text'] = '<a target="_top" href="'.$url.'&pure=1&refr=' . $refr . '">' . html_print_image("images/full_screen.png", true, array("title" => __('Full screen'))) . '</a>';
}
// Header
ui_print_page_header(__("SNMP Console"), "images/op_snmp.png", false,
"", false, array($link));
"", false, array($fullscreen, $list, $statistics));
// OPERATIONS
@ -142,11 +159,6 @@ if (isset ($_POST["updatebt"])) {
}
}
$table->width = '90%';
$table->size = array ();
$table->size[0] = '120px';
$table->data = array ();
// All traps
$all_traps = db_get_all_rows_sql ("SELECT DISTINCT source FROM ttrap");
if (empty($all_traps))
@ -170,7 +182,7 @@ foreach ($all_traps as $trap) {
//Make query to extract traps of DB.
switch ($config["dbtype"]) {
case "mysql":
$sql = "SELECT *
$sql = "SELECT *
FROM ttrap
WHERE (`source` IN (
SELECT direccion FROM tagente
@ -180,6 +192,7 @@ switch ($config["dbtype"]) {
LIMIT %d,%d";
break;
case "postgresql":
case "oracle":
$sql = "SELECT *
FROM ttrap
WHERE (source IN (
@ -189,18 +202,22 @@ switch ($config["dbtype"]) {
ORDER BY timestamp DESC
LIMIT %d OFFSET %d";
break;
case "oracle":
$sql = "SELECT *
FROM ttrap
WHERE (source IN (
SELECT direccion FROM tagente
WHERE id_grupo IN ($str_user_groups)
)
OR source='' OR source NOT IN (SELECT direccion FROM tagente)) %s
ORDER BY timestamp DESC
LIMIT %d OFFSET %d";
break;
}
$sql_all = "SELECT *
FROM ttrap
WHERE (source IN (
SELECT direccion FROM tagente
WHERE id_grupo IN ($str_user_groups)
)
OR source='' OR source NOT IN (SELECT direccion FROM tagente)) %s
ORDER BY timestamp DESC";
$sql_count = "SELECT COUNT(id_trap)
FROM ttrap
WHERE (source IN (
SELECT direccion FROM tagente
WHERE id_grupo IN ($str_user_groups)
)
OR source='' OR source NOT IN (SELECT direccion FROM tagente)) %s";
//$whereSubquery = 'WHERE 1=1';
$whereSubquery = '';
@ -276,21 +293,13 @@ switch ($config["dbtype"]) {
$sql = oracle_recode_query ($sql, $set);
break;
}
$sql_all = sprintf($sql_all, $whereSubquery);
$sql_count = sprintf($sql_count, $whereSubquery);
$traps = db_get_all_rows_sql($sql);
// No traps
if (empty ($traps)) {
echo '<div class="nf">'.__('There are no SNMP traps in database').'</div>';
return;
}
if (($config['dbtype'] == 'oracle') && ($traps !== false)) {
for ($i=0; $i < count($traps); $i++) {
unset($traps[$i]['rnum']);
}
}
$table->width = '90%';
$table->size = array ();
$table->size[0] = '120px';
$table->data = array ();
// Alert status select
$table->data[1][0] = '<strong>'.__('Alert').'</strong>';
@ -330,7 +339,7 @@ $table->data[3][3] = '<strong>'.__('Group by OID/IP').'</strong>';
$table->data[3][4] .= __('Yes').'&nbsp;'.html_print_radio_button ('group_by', 1, '', $group_by, true).'&nbsp;&nbsp;';
$table->data[3][4] .= __('No').'&nbsp;'.html_print_radio_button ('group_by', 0, '', $group_by, true);
$filter = '<form method="POST" action="index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&refr='.((int)get_parameter('refr', 0)).'&pure='.$config["pure"].'">';
$filter = '<form method="POST" action="index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&refr='.((int)get_parameter('refr', 0)).'&pure='.$config["pure"].'&tab='.$tab.'">';
$filter .= html_print_table($table, true);
$filter .= '<div style="width: ' . $table->width . '; text-align: right;">';
$filter .= html_print_submit_button(__('Update'), 'search', false, 'class="sub upd"', true);
@ -341,358 +350,441 @@ ui_toggle($filter, __('Toggle filter(s)'));
unset ($table);
// Prepare index for pagination
$trapcount = count($traps);
$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;
if ($tab == '') {
$urlPagination = $url_snmp . "&pagination=" . $pagination . "&offset=" . $offset;
$traps = db_get_all_rows_sql($sql);
$trapcount = (int) db_get_value_sql($sql_count);
ui_pagination ($trapcount, $urlPagination, $offset, $pagination);
echo '<form name="eventtable" method="POST" action="' . $url_snmp . '">';
$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] = '<a href="index.php?sec=estado&sec2=godmode/agentes/configurar_agente&new_agent=1&direccion='.$trap["source"].'" title="'.__('Create agent').'">'.$trap["source"].'</a>';
}
else {
if (! check_acl ($config["id_user"], $agent["id_grupo"], "AR")) {
continue;
}
$data[1] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent["id_agente"].'" title="'.__('View agent details').'">';
$data[1] .= '<strong>'.$agent["nombre"].'</strong></a>';
}
//OID
$table->cellclass[$idx][2] = get_priority_class ($severity);
$data[2] = '<a href="javascript: toggleVisibleExtendedInfo(' . $trap["id_trap"] . ');">' . (empty($trap["oid"]) ? __('N/A') : $trap["oid"]) .'</a>';
//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] = '<strong>'.$count_group_traps.'</strong></a>';
}
//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] = '<a href="index.php?sec=workspace&sec2=operation/users/user_edit&ver='.$trap["id_usuario"].'">'.substr ($trap["id_usuario"], 0, 8).'</a>';
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] = '<span title="'.$trap["timestamp"].'">';
$data[6] .= ui_print_timestamp ($trap["timestamp"], true);
$data[6] .= '</span>';
// 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] .= '<a href="' . $url_snmp . '&check='.$trap["id_trap"].'">' . html_print_image("images/ok.png", true, array("border" => '0', "title" => __('Validate'))) . '</a> ';
}
if ($trap['source'] == '') {
$is_admin = db_get_value('is_admin', 'tusuario', 'id_user',$config['id_user']);
if ($is_admin) {
$data[8] .= '<a href="' . $url_snmp . '&delete='.$trap["id_trap"].'&offset='.$offset.'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')">' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . '</a> ';
}
} 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] .= '<a href="' . $url_snmp . '&delete='.$trap["id_trap"].'&offset='.$offset.'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')">' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . '</a> ';
}
}
$data[8] .= '<a href="javascript: toggleVisibleExtendedInfo(' . $trap["id_trap"] . ');">' . html_print_image("images/eye.png", true, array("alt" => __('Show more'), "title" => __('Show more'))) .'</a>';
$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 = '<table style="border:solid 1px #D3D3D3;" width="90%" class="toggle">
<tr>
<td align="left" valign="top" width="15%" ><b>' . __('Custom data:') . '</b></td>
<td align="left" >';
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 .= '<a href='.$new_url.'>'.__('See more details').'</a>';
} else {
// Print binding vars separately
$binding_vars = explode ("\t", $trap['oid_custom']);
foreach ($binding_vars as $var) {
$string .= $var . "<br/>";
}
}
$string .= '</td>
</tr>
<tr>
<td align="left" valign="top">' . '<b>' . __('OID:') . '</td>
<td align="left"> ' . $trap['oid'] . '</td>
</tr>';
if ($trap["description"] != "") {
$string .= '<tr>
<td align="left" valign="top">' . '<b>' . __('Description:') . '</td>
<td align="left">' . $trap['description'] . '</td>
</tr>';
}
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 .= '<tr><td align="left" valign="top">' . '<b>' . __('Type:') . '</td><td align="left">' . $desc_trap_type . '</td></tr>';
}
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 .= '<tr>
<td align="left" valign="top">' . '<b>' . __('Count:') . '</td>
<td align="left">' . $count_group_traps . '</td>
</tr>';
$string .= '<tr>
<td align="left" valign="top">' . '<b>' . __('First trap:') . '</td>
<td align="left">' . $first_trap . '</td>
</tr>';
$string .= '<tr>
<td align="left" valign="top">' . '<b>' . __('Last trap:') . '</td>
<td align="left">' . $last_trap . '</td>
</tr>';
}
$string .= '</table>';
$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 traps
if (empty ($traps)) {
echo '<div class="nf">'.__('There are no SNMP traps in database').'</div>';
return;
}
}
// No matching traps
if ($idx == 0) {
echo '<div class="nf">' . __('No matching traps found') . '</div>';
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 '<form name="eventtable" method="POST" action="' . $url_snmp . '">';
$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] = '<a href="index.php?sec=estado&sec2=godmode/agentes/configurar_agente&new_agent=1&direccion='.$trap["source"].'" title="'.__('Create agent').'">'.$trap["source"].'</a>';
}
else {
if (! check_acl ($config["id_user"], $agent["id_grupo"], "AR")) {
continue;
}
$data[1] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent["id_agente"].'" title="'.__('View agent details').'">';
$data[1] .= '<strong>'.$agent["nombre"].'</strong></a>';
}
//OID
$table->cellclass[$idx][2] = get_priority_class ($severity);
$data[2] = '<a href="javascript: toggleVisibleExtendedInfo(' . $trap["id_trap"] . ');">' . (empty($trap["oid"]) ? __('N/A') : $trap["oid"]) .'</a>';
//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] = '<strong>'.$count_group_traps.'</strong></a>';
}
//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] = '<a href="index.php?sec=workspace&sec2=operation/users/user_edit&ver='.$trap["id_usuario"].'">'.substr ($trap["id_usuario"], 0, 8).'</a>';
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] = '<span title="'.$trap["timestamp"].'">';
$data[6] .= ui_print_timestamp ($trap["timestamp"], true);
$data[6] .= '</span>';
// 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] .= '<a href="' . $url_snmp . '&check='.$trap["id_trap"].'">' . html_print_image("images/ok.png", true, array("border" => '0', "title" => __('Validate'))) . '</a> ';
}
if ($trap['source'] == '') {
$is_admin = db_get_value('is_admin', 'tusuario', 'id_user',$config['id_user']);
if ($is_admin) {
$data[8] .= '<a href="' . $url_snmp . '&delete='.$trap["id_trap"].'&offset='.$offset.'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')">' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . '</a> ';
}
} 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] .= '<a href="' . $url_snmp . '&delete='.$trap["id_trap"].'&offset='.$offset.'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')">' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . '</a> ';
}
}
$data[8] .= '<a href="javascript: toggleVisibleExtendedInfo(' . $trap["id_trap"] . ');">' . html_print_image("images/eye.png", true, array("alt" => __('Show more'), "title" => __('Show more'))) .'</a>';
$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 = '<table style="border:solid 1px #D3D3D3;" width="90%" class="toggle">
<tr>
<td align="left" valign="top" width="15%" ><b>' . __('Custom data:') . '</b></td>
<td align="left" >';
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 .= '<a href='.$new_url.'>'.__('See more details').'</a>';
} else {
// Print binding vars separately
$binding_vars = explode ("\t", $trap['oid_custom']);
foreach ($binding_vars as $var) {
$string .= $var . "<br/>";
}
}
$string .= '</td>
</tr>
<tr>
<td align="left" valign="top">' . '<b>' . __('OID:') . '</td>
<td align="left"> ' . $trap['oid'] . '</td>
</tr>';
if ($trap["description"] != "") {
$string .= '<tr>
<td align="left" valign="top">' . '<b>' . __('Description:') . '</td>
<td align="left">' . $trap['description'] . '</td>
</tr>';
}
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 .= '<tr><td align="left" valign="top">' . '<b>' . __('Type:') . '</td><td align="left">' . $desc_trap_type . '</td></tr>';
}
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 .= '<tr>
<td align="left" valign="top">' . '<b>' . __('Count:') . '</td>
<td align="left">' . $count_group_traps . '</td>
</tr>';
$string .= '<tr>
<td align="left" valign="top">' . '<b>' . __('First trap:') . '</td>
<td align="left">' . $first_trap . '</td>
</tr>';
$string .= '<tr>
<td align="left" valign="top">' . '<b>' . __('Last trap:') . '</td>
<td align="left">' . $last_trap . '</td>
</tr>';
}
$string .= '</table>';
$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 '<div class="nf">' . __('No matching traps found') . '</div>';
}
else {
html_print_table ($table);
}
unset ($table);
echo '<div style="width:98%; text-align:right;">';
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 "&nbsp;";
html_print_submit_button (__('Delete'), "deletebt", false, 'class="sub delete" onClick="javascript:return confirm(\''.__('Are you sure?').'\')"');
}
echo "</div></form>";
echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
echo '<h3>' . __('Status') . '</h3>';
echo html_print_image("images/pixel_green.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Validated');
echo '<br />';
echo html_print_image("images/pixel_red.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not validated');
echo '</div>';
echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
echo '<h3>' . __('Alert') . '</h3>';
echo html_print_image("images/pixel_yellow.png", true, array("width" => "20", "height" => "20")) . ' - ' .__('Fired');
echo '<br />';
echo html_print_image("images/pixel_gray.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not fired');
echo '</div>';
echo '<div style="float:left; padding-left:30px; line-height: 19px; vertical-align: top; width:120px;">';
echo '<h3>' . __('Action') . '</h3>';
echo html_print_image("images/ok.png", true) . ' - ' .__('Validate');
echo '<br />';
echo html_print_image("images/cross.png", true) . ' - ' . __('Delete');
echo '</div>';
echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
echo '<h3>'.__('Legend').'</h3>';
foreach (get_priorities () as $num => $name) {
echo '<span class="'.get_priority_class ($num).'">'.$name.'</span>';
echo '<br />';
}
echo '</div>';
echo '<div style="clear:both;">&nbsp;</div>';
}
else {
html_print_table ($table);
$traps = db_get_all_rows_sql($sql_all);
$trapcount = (int) db_get_value_sql($sql_count);
// No traps
if (empty ($traps)) {
echo '<div class="nf">'.__('There are no SNMP traps in database').'</div>';
return;
}
if (($config['dbtype'] == 'oracle') && ($traps !== false)) {
for ($i=0; $i < count($traps); $i++) {
unset($traps[$i]['rnum']);
}
}
include_once($config['homedir'] . '/include/functions_graph.php');
$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'];
}
}
$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'] .= "<b>" . $values['text'] . "</b><br>";
$children_data['tooltip_content'] .= sprintf(__('%d traps received from this source with this oid'), $values['num']);
$children['children'][] = $children_data;
}
$data['children'][] = $children;
}
}
echo graph_snmp_traps_treemap($data, 'auto', 500);
}
unset ($table);
echo '<div style="width:98%; text-align:right;">';
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 "&nbsp;";
html_print_submit_button (__('Delete'), "deletebt", false, 'class="sub delete" onClick="javascript:return confirm(\''.__('Are you sure?').'\')"');
}
echo "</div></form>";
echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
echo '<h3>' . __('Status') . '</h3>';
echo html_print_image("images/pixel_green.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Validated');
echo '<br />';
echo html_print_image("images/pixel_red.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not validated');
echo '</div>';
echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
echo '<h3>' . __('Alert') . '</h3>';
echo html_print_image("images/pixel_yellow.png", true, array("width" => "20", "height" => "20")) . ' - ' .__('Fired');
echo '<br />';
echo html_print_image("images/pixel_gray.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not fired');
echo '</div>';
echo '<div style="float:left; padding-left:30px; line-height: 19px; vertical-align: top; width:120px;">';
echo '<h3>' . __('Action') . '</h3>';
echo html_print_image("images/ok.png", true) . ' - ' .__('Validate');
echo '<br />';
echo html_print_image("images/cross.png", true) . ' - ' . __('Delete');
echo '</div>';
echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
echo '<h3>'.__('Legend').'</h3>';
foreach (get_priorities () as $num => $name) {
echo '<span class="'.get_priority_class ($num).'">'.$name.'</span>';
echo '<br />';
}
echo '</div>';
echo '<div style="clear:both;">&nbsp;</div>';
?>
<script language="JavaScript" type="text/javascript">