From 6cfba445adb7fc9401fc1d1256ff51eff362f265 Mon Sep 17 00:00:00 2001 From: ramonn Date: Fri, 24 Apr 2009 08:25:55 +0000 Subject: [PATCH] 2009-04-24 Ramon Novoa * lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Core.pm: Generate an event when executing a SNMP alert. Small fixes. * lib/PandoraFMS/ReconServer.pm: Enabled OS filtering. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1652 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 7 +++++++ pandora_server/lib/PandoraFMS/Core.pm | 15 +++++++++------ pandora_server/lib/PandoraFMS/ReconServer.pm | 7 ++++--- pandora_server/lib/PandoraFMS/SNMPServer.pm | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 7603c95cbb..db0e8369f7 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2009-04-24 Ramon Novoa + + * lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Core.pm: Generate + an event when executing a SNMP alert. Small fixes. + + * lib/PandoraFMS/ReconServer.pm: Enabled OS filtering. + 2009-04-23 Ramon Novoa * lib/PandoraFMS/SNMPServer.pm: Add a newline character after diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 6dd88b111c..52a86e47e2 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -826,9 +826,9 @@ sub pandora_module_keep_alive_nd { ########################################################################## # Execute alerts that apply to the given SNMP trap. ########################################################################## -sub pandora_evaluate_snmp_alerts ($$$$$$$) { +sub pandora_evaluate_snmp_alerts ($$$$$$$$) { my ($pa_config, $trap_id, $trap_agent, $trap_oid, - $trap_oid_text, $trap_custom_value, $dbh) = @_; + $trap_oid_text, $trap_custom_oid, $trap_custom_value, $dbh) = @_; # Get all SNMP alerts my @snmp_alerts = get_db_rows ($dbh, 'SELECT * FROM talert_snmp'); @@ -844,10 +844,10 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$) { my $oid = $alert->{'oid'}; ($fire_alert, $alert_data) = (1, 'SNMP/OID:' . $oid) if ($trap_oid =~ m/$oid/i || $trap_oid_text =~ m/$oid/i); - # Custom value + # Custom OID/value } elsif ($alert_type == 1){ # type 1 is custom value my $custom_oid = $alert->{'custom_oid'}; - ($fire_alert, $alert_data) = (1, 'SNMP/VALUE:' . $custom_oid) if ($trap_custom_value =~ m/$custom_oid/i); + ($fire_alert, $alert_data) = (1, 'SNMP/VALUE:' . $custom_oid) if ($trap_custom_value =~ m/$custom_oid/i || $trap_custom_oid =~ m/$custom_oid/i); # Agent IP } else { my $agent = $alert->{'agent'}; @@ -893,8 +893,11 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$) { FROM talert_actions, talert_commands WHERE talert_actions.id_alert_command = talert_commands.id AND talert_actions.id = ?', $alert->{'id_alert'}); - if (defined ($action)) { - pandora_execute_action ($pa_config, '', undef, \%alert, 1, $action, $dbh); + if (defined ($action) && pandora_execute_action ($pa_config, '', undef, \%alert, 1, $action, $dbh) == 1) { + + # Generate an event + pandora_event ($pa_config, "SNMP alert fired (" . $alert->{'description'} . ")", + 0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', $dbh); } # Update alert status diff --git a/pandora_server/lib/PandoraFMS/ReconServer.pm b/pandora_server/lib/PandoraFMS/ReconServer.pm index 61a857f7ed..2e9af2ede9 100644 --- a/pandora_server/lib/PandoraFMS/ReconServer.pm +++ b/pandora_server/lib/PandoraFMS/ReconServer.pm @@ -150,12 +150,13 @@ sub data_consumer ($$) { next unless ($alive == 1); + # Guess the OS and filter + my $id_os = guess_os ($pa_config, $addr); + next if ($task->{'id_os'} > 0 && $task->{'id_os'} != $id_os); + $hosts_found++; $addr_found .= $addr . " "; - # Guess the OS - my $id_os = guess_os ($pa_config, $addr); - # Resolve the address my $host_name = gethostbyaddr(inet_aton($addr), AF_INET); $host_name = $addr unless defined ($host_name); diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index d78e649730..60a1835276 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -134,7 +134,7 @@ sub pandora_snmptrapd { my ($custom_oid, $custom_type, $custom_value) = ('', '', $type_desc); # Custom OID - if ($type == 6) { + if ($type eq '6') { #String data next if ($data =~ m/STRING/) && ($data !~ m/([0-9\.]*)\s\=\s([A-Za-z0-9]*)\:\s\"(.+)\"/); @@ -152,7 +152,7 @@ sub pandora_snmptrapd { logger ($pa_config, "Received SNMP Trap from $source", 4); # Evaluate alerts for this trap - pandora_evaluate_snmp_alerts ($pa_config, $trap_id, $source, $oid, $oid, $custom_oid . ' ' . $custom_value, $dbh); + pandora_evaluate_snmp_alerts ($pa_config, $trap_id, $source, $oid, $oid, $custom_oid, $custom_value, $dbh); } enterprise_hook ('snmp_trap2agent', [$trap2agent, $pa_config, $source, $oid, $value, $custom_oid, $custom_value, $timestamp, $dbh]);