From 8f574573ce6d772a1d4f63f415d1a5dd1cb80dec Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 6 Nov 2009 15:44:02 +0000 Subject: [PATCH] 2009-11-06 Miguel de Dios * 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 --- pandora_console/ChangeLog | 11 +- .../alerts/configure_alert_compound.php | 2 +- .../operation/agentes/status_monitor.php | 12 +- .../operation/snmpconsole/snmp_view.php | 285 ++++++++++-------- 4 files changed, 184 insertions(+), 126 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 3f3b6ca7d9..db5ec73feb 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,4 +1,13 @@ -2009-11-04 Ramon Novoa +2009-11-06 Miguel de Dios + + * 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 * DEBIAN/control: fix dependencies, not necesary mysql-server, because the mysql can install in another machine. diff --git a/pandora_console/godmode/alerts/configure_alert_compound.php b/pandora_console/godmode/alerts/configure_alert_compound.php index 68207bcf48..d6b206f272 100644 --- a/pandora_console/godmode/alerts/configure_alert_compound.php +++ b/pandora_console/godmode/alerts/configure_alert_compound.php @@ -724,7 +724,7 @@ $(document).ready (function () { "get_agent_alerts_simple" : 1, "id_agent" : this.value }, - function (data, status) { + function (data, status) { if (! data) { $("#alerts_loading").hide (); tr = $('').append ($('') diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 605f64f2ae..7a4f48ddd0 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -118,11 +118,14 @@ if ($ag_freestring != "") { // Status selector if ($status == 0) { //Up $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)"; -} 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)"; -} 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) "; } 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)"; @@ -246,7 +249,8 @@ foreach ($result as $row) { if ($seconds >= ($row["module_interval"] * 2)) { $option = array ("html_attr" => 'class="redb"'); - } else { + } + else { $option = array (); } diff --git a/pandora_console/operation/snmpconsole/snmp_view.php b/pandora_console/operation/snmpconsole/snmp_view.php index 9e77074578..48c4a30964 100644 --- a/pandora_console/operation/snmpconsole/snmp_view.php +++ b/pandora_console/operation/snmpconsole/snmp_view.php @@ -142,10 +142,48 @@ foreach ($traps as $trap) { $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) { echo '