diff --git a/pandora_console/extras/mr/66.sql b/pandora_console/extras/mr/66.sql index b0022d31b0..6da042ee7e 100644 --- a/pandora_console/extras/mr/66.sql +++ b/pandora_console/extras/mr/66.sql @@ -1,5 +1,9 @@ START TRANSACTION; +ALTER TABLE `ttrap` ADD COLUMN `utimestamp` INT UNSIGNED NOT NULL DEFAULT 0; + +UPDATE ttrap SET utimestamp=UNIX_TIMESTAMP(timestamp); + CREATE TABLE IF NOT EXISTS `tgraph_analytics_filter` ( `id` INT NOT NULL auto_increment, `filter_name` VARCHAR(45) NULL, diff --git a/pandora_console/include/class/SnmpConsole.class.php b/pandora_console/include/class/SnmpConsole.class.php index 4a2c32de2e..86132d3956 100644 --- a/pandora_console/include/class/SnmpConsole.class.php +++ b/pandora_console/include/class/SnmpConsole.class.php @@ -549,6 +549,11 @@ class SnmpConsole extends HTML $order = get_datatable_order(true); $filters = get_parameter('filter', []); + // Build ranges. + $now_timestamp = time(); + $interval_seconds = ($filters['filter_hours_ago'] * 3600); + $ago_timestamp = ($now_timestamp - $interval_seconds); + // Build ranges. $now = new DateTime(); $ago = new DateTime(); @@ -688,7 +693,7 @@ class SnmpConsole extends HTML if ($date_from_trap != '') { if ($time_from_trap != '') { $whereSubquery .= ' - AND (UNIX_TIMESTAMP(timestamp) > UNIX_TIMESTAMP("'.$date_from_trap.' '.$time_from_trap.'")) + AND (utimestamp > '.$ago_timestamp.') '; } else { $whereSubquery .= ' @@ -700,7 +705,7 @@ class SnmpConsole extends HTML if ($date_to_trap != '') { if ($time_to_trap) { $whereSubquery .= ' - AND (UNIX_TIMESTAMP(timestamp) < UNIX_TIMESTAMP("'.$date_to_trap.' '.$time_to_trap.'")) + AND (utimestamp < '.$now_timestamp.') '; } else { $whereSubquery .= ' diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 9ddd3fafa0..6410194940 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1257,6 +1257,7 @@ CREATE TABLE IF NOT EXISTS `ttrap` ( `text` VARCHAR(255) DEFAULT '', `description` VARCHAR(255) DEFAULT '', `severity` TINYINT UNSIGNED NOT NULL DEFAULT 2, + `utimestamp` INT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`id_trap`), INDEX timestamp (`timestamp`), INDEX status (`status`), diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index ad154ab06b..6cf898e07e 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -382,8 +382,8 @@ sub pandora_snmptrapd { # Insert the trap into the DB if (! defined(enterprise_hook ('snmp_insert_trap', [$pa_config, $source, $oid, $type, $value, $custom_oid, $custom_value, $custom_type, $timestamp, $server_id, $dbh]))) { - my $trap_id = db_insert ($dbh, 'id_trap', 'INSERT INTO ttrap (timestamp, source, oid, type, value, oid_custom, value_custom, type_custom) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', - $timestamp, $source, $oid, $type, $value, $custom_oid, $custom_value, $custom_type); + my $trap_id = db_insert ($dbh, 'id_trap', 'INSERT INTO ttrap (timestamp, source, oid, type, value, oid_custom, value_custom, type_custom, utimestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', + $timestamp, $source, $oid, $type, $value, $custom_oid, $custom_value, $custom_type, time()); logger ($pa_config, "Received SNMP Trap from $source", 4); # Evaluate alerts for this trap