From 191fef477c4ed2b911a2060315d22990dd53f515 Mon Sep 17 00:00:00 2001 From: ramonn Date: Tue, 4 Nov 2008 18:40:26 +0000 Subject: [PATCH] 2008-11-04 Ramon Novoa * bin/pandora_snmpconsole: Added support for extended trap information (enterprise version). * bin/pandora_network: Updated function header. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1215 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 7 +++++ pandora_server/bin/pandora_network | 2 +- pandora_server/bin/pandora_snmpconsole | 41 ++++++++++++++------------ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index eac551beed..e687e998fe 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2008-11-04 Ramon Novoa + + * bin/pandora_snmpconsole: Added support for extended trap information + (enterprise version). + + * bin/pandora_network: Updated function header. + 2008-11-04 Ramon Novoa * lib/PandoraFMS/Config.pm, diff --git a/pandora_server/bin/pandora_network b/pandora_server/bin/pandora_network index d7a5abb941..996a7a8de1 100755 --- a/pandora_server/bin/pandora_network +++ b/pandora_server/bin/pandora_network @@ -459,7 +459,7 @@ next_pair: } ########################################################################## -# SUB pandora_query_snmp (pa_config, oid, community, target, error, dbh) +# SUB pandora_query_snmp (pa_config, oid, community, target, version, error, dbh) # Makes a call to SNMP modules to get a value, ########################################################################## sub pandora_query_snmp (%$$$$$) { diff --git a/pandora_server/bin/pandora_snmpconsole b/pandora_server/bin/pandora_snmpconsole index 2e8750f5d8..13ce0ffe72 100755 --- a/pandora_server/bin/pandora_snmpconsole +++ b/pandora_server/bin/pandora_snmpconsole @@ -78,9 +78,9 @@ sub pandora_snmptrapd { my $type; my $type_desc; my $value; - my $custom_oid; - my $custom_type; - my $custom_value; + my $custom_oid = ''; + my $custom_type = ''; + my $custom_value = ''; my $sql_insert; my @index_data; @@ -157,18 +157,20 @@ sub pandora_snmptrapd { $custom_type=""; $custom_value=$type_desc; # Bug fixed, 080108 by anonymous } - - $sql_insert = "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')"; - logger ($pa_config,"Received SNMP Trap from $source", 4); - eval { - $dbh->do($sql_insert) || logger ($pa_config, "Cannot write to database while updating SNMP Trap data (error in INSERT)",0); - # Evaluate TRAP Alerts for this trap - calcula_alerta_snmp ($pa_config, $source, $oid, $custom_value, $timestamp, $dbh); - }; - if ($@) { - logger ($pa_config, "[ERROR] Cannot access to database while updating SNMP Trap data",0); - logger ($pa_config, "[ERROR] SQL Errorcode: $@", 2); - } + + if (! defined(PandoraFMS::Tools::enterprise_hook ('snmp_insert_trap', [$pa_config, $source, $oid, $type, $value, $custom_oid, $custom_value, $custom_type, $timestamp, $dbh]))) { + $sql_insert = "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')"; + logger ($pa_config,"Received SNMP Trap from $source", 4); + eval { + $dbh->do($sql_insert) || logger ($pa_config, "Cannot write to database while updating SNMP Trap data (error in INSERT)",0); + # Evaluate TRAP Alerts for this trap + calcula_alerta_snmp ($pa_config, $source, $oid, $oid, $custom_value, $timestamp, $dbh); + }; + if ($@) { + logger ($pa_config, "[ERROR] Cannot access to database while updating SNMP Trap data",0); + logger ($pa_config, "[ERROR] SQL Errorcode: $@", 2); + } + } PandoraFMS::Tools::enterprise_hook ('snmp_trap2agent', [defined($trap2agent) ? $trap2agent : 0, $pa_config, $source, $oid, $value, $custom_oid, $custom_value, $timestamp, $dbh]); } } @@ -189,9 +191,10 @@ sub calcula_alerta_snmp { my $pa_config = $_[0]; my $trap_agente = $_[1]; my $trap_oid = $_[2]; - my $trap_custom_value = $_[3]; - my $timestamp = $_[4]; - my $dbh = $_[5]; + my $trap_oid_text = $_[3]; + my $trap_custom_value = $_[4]; + my $timestamp = $_[5]; + my $dbh = $_[6]; my $alert_fired = 0; my $query_idag = "select * from talert_snmp"; @@ -223,7 +226,7 @@ sub calcula_alerta_snmp { my $alert_data = ""; if ($alert_type == 0){ # type 0 is OID only - if ( $trap_oid =~ m/$oid/i ){ + if ( $trap_oid =~ m/$oid/i || $trap_oid_text =~ m/$oid/i){ $alert_fired = 1; $alert_data = "SNMP/OID:".$oid; logger ($pa_config,"SNMP Alert debug (OID) MATCHED",10);