2009-11-06 Miguel de Dios <miguel.dedios@artica.es>

* operation/snmpconsole/snmp_view.php: fix and optimize the query to traps
	in DB, because the old style didn't run with paginator and it was slow with
	much traps registers.
	* operation/agentes/status_monitor.php,
	godmode/alerts/configure_alert_compound.php: little fix arround the code
	style.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2089 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2009-11-06 15:44:02 +00:00
parent a6e3552ee8
commit b117cae535
4 changed files with 184 additions and 126 deletions

View File

@ -1,4 +1,13 @@
2009-11-04 Ramon Novoa <rnovoa@artica.es> 2009-11-06 Miguel de Dios <miguel.dedios@artica.es>
* operation/snmpconsole/snmp_view.php: fix and optimize the query to traps
in DB, because the old style didn't run with paginator and it was slow with
much traps registers.
* operation/agentes/status_monitor.php,
godmode/alerts/configure_alert_compound.php: little fix arround the code
style.
2009-11-04 Miguel de Dios <miguel.dedios@artica.es>
* DEBIAN/control: fix dependencies, not necesary mysql-server, because the * DEBIAN/control: fix dependencies, not necesary mysql-server, because the
mysql can install in another machine. mysql can install in another machine.

View File

@ -724,7 +724,7 @@ $(document).ready (function () {
"get_agent_alerts_simple" : 1, "get_agent_alerts_simple" : 1,
"id_agent" : this.value "id_agent" : this.value
}, },
function (data, status) { function (data, status) {
if (! data) { if (! data) {
$("#alerts_loading").hide (); $("#alerts_loading").hide ();
tr = $('<tr></tr>').append ($('<td></td>') tr = $('<tr></tr>').append ($('<td></td>')

View File

@ -118,11 +118,14 @@ if ($ag_freestring != "") {
// Status selector // Status selector
if ($status == 0) { //Up if ($status == 0) { //Up
$sql .= " AND tagente_estado.estado = 0 AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2)"; $sql .= " AND tagente_estado.estado = 0 AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2)";
} elseif ($status == 2) { //Critical }
elseif ($status == 2) { //Critical
$sql .= " AND tagente_estado.estado = 1 AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2)"; $sql .= " AND tagente_estado.estado = 1 AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2)";
} elseif ($status == 1) { //warning }
elseif ($status == 1) { //warning
$sql .= " AND tagente_estado.estado = 2 AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2)"; $sql .= " AND tagente_estado.estado = 2 AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2)";
} elseif ($status == 4) { //not normal }
elseif ($status == 4) { //not normal
$sql .= " AND ((UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) >= (tagente_estado.current_interval * 2) OR tagente_estado.estado = 2 OR tagente_estado.estado = 1) "; $sql .= " AND ((UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) >= (tagente_estado.current_interval * 2) OR tagente_estado.estado = 2 OR tagente_estado.estado = 1) ";
} elseif ($status == 3) { //Unknown } elseif ($status == 3) { //Unknown
$sql .= " AND utimestamp > 0 AND tagente_modulo.id_tipo_modulo < 21 AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) >= (tagente_estado.current_interval * 2)"; $sql .= " AND utimestamp > 0 AND tagente_modulo.id_tipo_modulo < 21 AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) >= (tagente_estado.current_interval * 2)";
@ -246,7 +249,8 @@ foreach ($result as $row) {
if ($seconds >= ($row["module_interval"] * 2)) { if ($seconds >= ($row["module_interval"] * 2)) {
$option = array ("html_attr" => 'class="redb"'); $option = array ("html_attr" => 'class="redb"');
} else { }
else {
$option = array (); $option = array ();
} }

View File

@ -142,10 +142,48 @@ foreach ($traps as $trap) {
$oids[$oid] = $oid; $oids[$oid] = $oid;
} }
//Make query to extract traps of DB.
$sql = "SELECT * FROM ttrap %s ORDER BY timestamp DESC LIMIT %d,%d";
$whereSubquery = 'WHERE 1=1';
if ($filter_agent != '')
$whereSubquery .= ' AND source LIKE "' . $filter_agent . "'";
if ($filter_oid != '') {
//Test if install the enterprise to search oid in text or oid field in ttrap.
if ($config['enterprise_installed'])
$whereSubquery .= ' AND (text LIKE "' . $filter_oid . '" OR oid LIKE "' . $filter_oid . '")';
else
$whereSubquery .= ' AND oid LIKE "' . $filter_oid . '"';
}
if ($filter_fired != -1)
$whereSubquery .= ' AND alerted = ' . $filter_fired;
if ($search_string != '')
$whereSubquery .= ' AND value LIKE "%' . $search_string . '%"';
if ($filter_severity != -1) {
//Test if install the enterprise to search oid in text or oid field in ttrap.
if ($config['enterprise_installed'])
$whereSubquery .= ' AND (
(alerted = 0 AND severity = ' . $filter_severity . ') OR
(alerted = 1 AND priority = ' . $filter_severity . '))';
else
$whereSubquery .= ' AND (
(alerted = 0 AND 1 = ' . $filter_severity . ') OR
(alerted = 1 AND priority = ' . $filter_severity . '))';
}
if ($filter_status != -1)
$whereSubquery .= ' AND status = ' . $filter_status;
$sql = sprintf($sql, $whereSubquery, $offset, $config['block_size']);
$traps = get_db_all_rows_sql($sql);
if ($config["pure"] == 1) { if ($config["pure"] == 1) {
echo '<div id="filters" style="display:none;">'; echo '<div id="filters" style="display:none;">';
} else { }
echo '<div id="filters" style="display:block;">'; //There is no value all to property display else {
echo '<div id="filters" style="display: none;">';
} }
// Agent select // Agent select
@ -193,8 +231,13 @@ echo '</div>';
echo '<br />'; echo '<br />';
// Prepare index for pagination // Prepare index for pagination
$trapcount = get_db_sql ("SELECT COUNT(*) FROM ttrap"); $trapcount = get_db_sql ("SELECT COUNT(*) FROM ttrap " . $whereSubquery);
pagination ($trapcount, "index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&filter_agent=".$filter_agent."&filter_oid=".$filter_oid."&pagination=".$pagination."&offset=".$offset."&refr=".$config["refr"]."&pure=".$config["pure"], $offset, $pagination);
$urlPagination = "index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&filter_agent=" . $filter_agent
. "&filter_oid=" . $filter_oid . "&filter_severity=" . $filter_severity
. "&filter_fired=" . $filter_fired . "&filter_status=" . $filter_status
. "&search_string=" . $search_string . "&pagination=".$pagination."&offset=".$offset."&refr=".$config["refr"]."&pure=".$config["pure"];
pagination ($trapcount, $urlPagination, $offset, $pagination);
echo '<form name="eventtable" method="POST" action="index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&pagination='.$pagination.'&offset='.$offset.'">'; echo '<form name="eventtable" method="POST" action="index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&pagination='.$pagination.'&offset='.$offset.'">';
@ -240,131 +283,133 @@ $table->align[9] = "center";
// Skip offset records // Skip offset records
$idx = 0; $idx = 0;
foreach ($traps as $trap) { if ($traps !== false) {
$data = array (); foreach ($traps as $trap) {
$data = array ();
// Apply filters
if ($filter_agent != '' && $trap["source"] != $filter_agent) {
continue;
}
$oid = enterprise_hook ('get_oid', array ($trap)); // // Apply filters
if ($oid === ENTERPRISE_NOT_HOOK) { // if ($filter_agent != '' && $trap["source"] != $filter_agent) {
$oid = $trap["oid"]; // continue;
} // }
//
if ($filter_oid != '' && $oid != $filter_oid) { // $oid = enterprise_hook ('get_oid', array ($trap));
continue; // if ($oid === ENTERPRISE_NOT_HOOK) {
} // $oid = $trap["oid"];
// }
if ($filter_fired != -1 && $trap["alerted"] != $filter_fired) { //
continue; // if ($filter_oid != '' && $oid != $filter_oid) {
} // continue;
// }
if ($filter_status != -1 && $trap["status"] != $filter_status) { //
continue; // if ($filter_fired != -1 && $trap["alerted"] != $filter_fired) {
} // continue;
// }
$severity = enterprise_hook ('get_severity', array ($trap)); //
if ($severity === ENTERPRISE_NOT_HOOK) { // if ($filter_status != -1 && $trap["status"] != $filter_status) {
$severity = $trap["alerted"] == 1 ? $trap["priority"] : 1; // continue;
} // }
//
if ($filter_severity != -1 && $severity != $filter_severity) { $severity = enterprise_hook ('get_severity', array ($trap));
continue; if ($severity === ENTERPRISE_NOT_HOOK) {
} $severity = $trap["alerted"] == 1 ? $trap["priority"] : 1;
if ($search_string != '' && ereg ($search_string, $trap["value"]) == 0 &&
ereg ($search_string, $trap["value_custom"]) == 0) {
continue;
}
//Status
if ($trap["status"] == 0) {
$data[0] = '<img src="images/pixel_red.png" title="'.__('Not validated').'" width="20" height="20" />';
} else {
$data[0] = '<img src="images/pixel_green.png" title="'.__('Validated').'" width="20" height="20" />';
}
// Agent matching source address
$agent = get_agent_with_ip ($trap['source']);
if ($agent === false) {
if (! give_acl ($config["id_user"], 0, "AW")) {
continue;
} }
$data[1] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&new_agent=1&direccion='.$trap["source"].'" title="'.__('Create agent').'">'.$trap["source"].'</a>'; //
} else { // if ($filter_severity != -1 && $severity != $filter_severity) {
if (! give_acl ($config["id_user"], $agent["id_grupo"], "AR")) { // continue;
continue; // }
//
// if ($search_string != '' && ereg ($search_string, $trap["value"]) == 0 &&
// ereg ($search_string, $trap["value_custom"]) == 0) {
// continue;
// }
//Status
if ($trap["status"] == 0) {
$data[0] = '<img src="images/pixel_red.png" title="'.__('Not validated').'" width="20" height="20" />';
} else {
$data[0] = '<img src="images/pixel_green.png" title="'.__('Validated').'" width="20" height="20" />';
} }
$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>'; // Agent matching source address
} $agent = get_agent_with_ip ($trap['source']);
if ($agent === false) {
//OID if (! give_acl ($config["id_user"], 0, "AW")) {
if (empty ($trap["oid"])) { continue;
$data[2] = __('N/A'); }
} else { $data[1] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&new_agent=1&direccion='.$trap["source"].'" title="'.__('Create agent').'">'.$trap["source"].'</a>';
$data[2] = enterprise_hook ('editor_link', array ($trap)); } else {
if ($data[2] === ENTERPRISE_NOT_HOOK) { if (! give_acl ($config["id_user"], $agent["id_grupo"], "AR")) {
$data[2] = $trap["oid"]; 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>';
} }
}
//Value
$data[3] = substr ($trap["value"], 0, 15);
if (empty ($data[3])) { //OID
$data[3] = __('N/A'); if (empty ($trap["oid"])) {
} elseif (strlen ($trap["value"]) > 15) { $data[2] = __('N/A');
$data[3] = '<span title="'.$trap["value"].'">'.$data[3].'...</span>'; } else {
} $data[2] = enterprise_hook ('editor_link', array ($trap));
if ($data[2] === ENTERPRISE_NOT_HOOK) {
$data[2] = $trap["oid"];
}
}
//Custom //Value
$data[4] = '<span title="' . $trap["oid_custom"] . '">' . $trap["value_custom"] . '</span>'; $data[3] = substr ($trap["value"], 0, 15);
if (empty ($data[4])) { if (empty ($data[3])) {
$data[4] = __('N/A'); $data[3] = __('N/A');
} elseif (strlen ($trap["value_custom"]) > 15) { } elseif (strlen ($trap["value"]) > 15) {
$data[4] = '<span title="'.$trap["value_custom"].'">'.$data[4].'...</span>'; $data[3] = '<span title="'.$trap["value"].'">'.$data[3].'...</span>';
} }
//User //Custom
if (!empty ($trap["status"])) { $data[4] = '<span title="' . $trap["oid_custom"] . '">' . $trap["value_custom"] . '</span>';
$data[5] = '<a href="index.php?sec=usuarios&sec2=operation/users/user_edit&ver='.$trap["id_usuario"].'">'.substr ($trap["id_usuario"], 0, 8).'</a>';
$data[5] .= '<a href="#" class="tip">&nbsp;<span>'.dame_nombre_real($trap["id_usuario"]).'</span></a>';
} else {
$data[5] = '--';
}
// Timestamp if (empty ($data[4])) {
$data[6] = '<span title="'.$trap["timestamp"].'">'; $data[4] = __('N/A');
$data[6] .= human_time_comparation ($trap["timestamp"]); } elseif (strlen ($trap["value_custom"]) > 15) {
$data[6] .= '</span>'; $data[4] = '<span title="'.$trap["value_custom"].'">'.$data[4].'...</span>';
}
// Use alert severity if fired //User
if (!empty ($trap["alerted"])) { if (!empty ($trap["status"])) {
$data[7] = '<img src="images/pixel_yellow.png" width="20" height="20" border="0" title="'.__('Alert fired').'" />'; $data[5] = '<a href="index.php?sec=usuarios&sec2=operation/users/user_edit&ver='.$trap["id_usuario"].'">'.substr ($trap["id_usuario"], 0, 8).'</a>';
} else { $data[5] .= '<a href="#" class="tip">&nbsp;<span>'.dame_nombre_real($trap["id_usuario"]).'</span></a>';
$data[7] = '<img src="images/pixel_gray.png" width="20" height="20" border="0" title="'.__('Alert not fired').'" />'; } else {
} $data[5] = '--';
}
// Severity
$table->rowclass[$idx] = get_priority_class ($severity); // Timestamp
$data[6] = '<span title="'.$trap["timestamp"].'">';
//Actions $data[6] .= human_time_comparation ($trap["timestamp"]);
$data[8] = ""; $data[6] .= '</span>';
if (empty ($trap["status"]) && give_acl ($config["id_user"], 0, "IW")) {
$data[8] .= '<a href="index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&check='.$trap["id_trap"].'"><img src="images/ok.png" border="0" title="'.__('Validate').'" /></a>'; // Use alert severity if fired
} if (!empty ($trap["alerted"])) {
if (give_acl ($config["id_user"], 0, "IM")) { $data[7] = '<img src="images/pixel_yellow.png" width="20" height="20" border="0" title="'.__('Alert fired').'" />';
$data[8] .= '<a href="index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&delete='.$trap["id_trap"].'&offset='.$offset.'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')"><img src="images/cross.png" border="0" title="'.__('Delete').'"/></a>'; } else {
} $data[7] = '<img src="images/pixel_gray.png" width="20" height="20" border="0" title="'.__('Alert not fired').'" />';
}
$data[9] = print_checkbox_extended ("snmptrapid[]", $trap["id_trap"], false, false, '', 'class="chk"', true); // Severity
$table->rowclass[$idx] = get_priority_class ($severity);
array_push ($table->data, $data);
$idx++; //Actions
$data[8] = "";
if (empty ($trap["status"]) && give_acl ($config["id_user"], 0, "IW")) {
$data[8] .= '<a href="index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&check='.$trap["id_trap"].'"><img src="images/ok.png" border="0" title="'.__('Validate').'" /></a>';
}
if (give_acl ($config["id_user"], 0, "IM")) {
$data[8] .= '<a href="index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&delete='.$trap["id_trap"].'&offset='.$offset.'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')"><img src="images/cross.png" border="0" title="'.__('Delete').'"/></a>';
}
$data[9] = print_checkbox_extended ("snmptrapid[]", $trap["id_trap"], false, false, '', 'class="chk"', true);
array_push ($table->data, $data);
$idx++;
}
} }
// No matching traps // No matching traps