2011-08-17 Sancho Lerena <slerena@artica.es>

* SNMPServer.pm: Custom value and custom type are not used anymore.
        All extended info comes into custom_oid which stores now all the
        raw info.

        * Core.pm: pandora_evaluate_snmp_alerts() function now uses complex
        regular expression and new macros to allow complex SNMP trap alerts 
        which takes information from the trap info and puts on the alert.

        * DataServer.pm: Fixed notice about undefined GIS position desc.

        * pandora_db.pl: Version update.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4761 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2011-08-17 20:11:32 +00:00
parent d587b33f0a
commit 1233edd112
5 changed files with 67 additions and 21 deletions

View File

@ -1,3 +1,17 @@
2011-08-17 Sancho Lerena <slerena@artica.es>
* SNMPServer.pm: Custom value and custom type are not used anymore.
All extended info comes into custom_oid which stores now all the
raw info.
* Core.pm: pandora_evaluate_snmp_alerts() function now uses complex
regular expression and new macros to allow complex SNMP trap alerts
which takes information from the trap info and puts on the alert.
* DataServer.pm: Fixed notice about undefined GIS position desc.
* pandora_db.pl: Version update.
2011-08-17 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/NetworkServer.pm: Convert text obj tags to OIDs.

View File

@ -1590,15 +1590,16 @@ sub pandora_module_keep_alive_nd {
}
##########################################################################
=head2 C<< pandora_evaluate_snmp_alerts (I<$pa_config>, I<$trap_id>, I<$trap_agent>, I<$trap_oid>, I<$trap_oid_text>, I<$value>, I<$trap_custom_oid>, I<$trap_custom_value>, I<$dbh>) >>
=head2 C<< pandora_evaluate_snmp_alerts (I<$pa_config>, I<$trap_id>, I<$trap_agent>, I<$trap_oid>, I<$trap_oid_text>, I<$value>, I<$trap_custom_oid>, I<$dbh>) >>
Execute alerts that apply to the given SNMP trap.
=cut
##########################################################################
sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
sub pandora_evaluate_snmp_alerts ($$$$$$$$) {
my ($pa_config, $trap_id, $trap_agent, $trap_oid,
$trap_oid_text, $trap_value, $trap_custom_oid, $trap_custom_value, $dbh) = @_;
$trap_oid_text, $trap_value, $trap_custom_oid, $dbh) = @_;
# Get all SNMP alerts
my @snmp_alerts = get_db_rows ($dbh, 'SELECT * FROM talert_snmp');
@ -1613,28 +1614,57 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
($alert->{'times_fired'}, $alert->{'internal_counter'}, $alert->{'alert_type'});
# OID
# Decode first, could be a complex regexp !
$alert->{'oid'} = decode_entities($alert->{'oid'});
my $oid = $alert->{'oid'};
if ($oid ne '') {
next if ($trap_oid !~ m/^$oid$/i && $trap_oid_text !~ m/^$oid$/i);
$alert_data .= "OID: $oid ";
}
# Custom OID/value
my $custom_oid = $alert->{'custom_oid'};
if ($custom_oid ne '') {
if ($trap_value =~ m/^$custom_oid$/i){
$alert_data .= " Trap Value: $trap_value";
} elsif ($trap_custom_value =~ m/^$custom_oid$/i){
$alert_data .= " Trap Value: $trap_custom_value";
# Specific SNMP Trap alert macros for regexp selectors in trap info
my $snmp_f1 = "";
my $snmp_f2 = "";
my $snmp_f3 = "";
# Custom OID/value
# Decode first, this could be a complex regexp !
$alert->{'custom_oid'} = decode_entities($alert->{'custom_oid'});
my $custom_oid = $alert->{'custom_oid'};
if ($custom_oid ne '') {
if ($trap_custom_oid =~ m/^$custom_oid$/i){
$alert_data .= " Custom: $trap_custom_oid";
# Let's capture some data using regexp selectors !
if (defined($1)){
$snmp_f1 = $1;
}
if (defined($2)){
$snmp_f2 = $2;
}
if (defined($3)){
$snmp_f3 = $3;
}
} elsif ($trap_custom_oid =~ m/^$custom_oid$/i){
$alert_data .= " Trap Value: $trap_custom_oid";
} else {
next;
}
}
# SANCHO DEBUG
my %macros;
$macros{_snmp_f1_} = $snmp_f1;
$macros{_snmp_f2_} = $snmp_f2;
$macros{_snmp_f3_} = $snmp_f3;
$alert->{'al_field1'} = subst_alert_macros ($alert->{'al_field1'}, \%macros);
$alert->{'al_field2'} = subst_alert_macros ($alert->{'al_field2'}, \%macros);
$alert->{'al_field3'} = subst_alert_macros ($alert->{'al_field3'}, \%macros);
# Agent IP
my $agent = $alert->{'agent'};
if ($agent ne '') {
@ -1702,7 +1732,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
WHERE talert_actions.id_alert_command = talert_commands.id
AND talert_actions.id = ?', $alert->{'id_alert'});
my $trap_rcv_full = $trap_oid . " " . $trap_value. " ". $trap_custom_oid . " " . $trap_custom_value;
my $trap_rcv_full = $trap_oid . " " . $trap_value. " ". $trap_custom_oid;
pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert, 1, $action, undef, $dbh, $timestamp) if (defined ($action));

View File

@ -241,11 +241,13 @@ sub process_xml_data ($$$$$) {
my $doc = $xs1->XMLin($content);
$position_description = safe_input ($doc->{result}{content});
} else {
$position_description = ''; # Default value
}
}
if (!defined($position_description)){
$position_description = "";
}
logger($pa_config, "Getting GIS Data=timezone_offset=$timezone_offset longitude=$longitude latitude=$latitude altitude=$altitude position_description=$position_description", 8);
}

View File

@ -151,12 +151,12 @@ sub pandora_snmptrapd {
$value = limpia_cadena ($value);
my ($custom_oid, $custom_type, $custom_value) = ('', '', '');
($custom_oid, $custom_type, $custom_value) = ($1, $2, limpia_cadena ($3)) if ($data =~ m/([0-9\.]*)\s\=\s([A-Za-z0-9]*)\:\s(.+)/);
# custom_type, custom_value is not used since 4.0 version, all custom data goes on custom_oid
$custom_oid = $data;
# Try to save as much information as possible if the trap could not be parsed
$oid = $type_desc if ($oid eq '' || $oid eq '.');
$custom_value = $type_desc if ($custom_oid eq '' || $custom_oid eq '.');
$custom_value = $data if ($custom_value eq '');
# 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, $self->getServerID (), $dbh]))) {
@ -165,7 +165,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, $value, $custom_oid, $custom_value, $dbh);
pandora_evaluate_snmp_alerts ($pa_config, $trap_id, $source, $oid, $oid, $value, $custom_oid, $dbh);
}
}

View File

@ -30,7 +30,7 @@ use PandoraFMS::Tools;
use PandoraFMS::DB;
# version: define current version
my $version = "4.0 PS100310";
my $version = "4.0 PS110810";
# Pandora server configuration
my %conf;