fixed snmp traps time

This commit is contained in:
alejandro.campos@artica.es 2023-07-18 10:40:33 +02:00
parent 83f3928495
commit c8393ae210
4 changed files with 17 additions and 4 deletions

View File

@ -0,0 +1,7 @@
START TRANSACTION;
ALTER TABLE `ttrap` ADD COLUMN `utimestamp` INT UNSIGNED NOT NULL DEFAULT 0;
UPDATE ttrap SET utimestamp=UNIX_TIMESTAMP(timestamp);
COMMIT;

View File

@ -547,6 +547,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();
@ -686,7 +691,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 .= '
@ -698,7 +703,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 .= '

View File

@ -1226,6 +1226,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`),

View File

@ -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