mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 17:25:26 +02:00
Merge branch 'ent-7866-12249-no-se-muestra-valor-de-macro-snmp_f1' into 'develop'
SNMP variable bindings, filter before capture, assign correctly macro values See merge request artica/pandorafms!4337
This commit is contained in:
commit
5d501f3abf
@ -3983,13 +3983,66 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
|
|||||||
$alert_data .= " Custom: $trap_custom_oid";
|
$alert_data .= " Custom: $trap_custom_oid";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Assign default values to the _snmp_fx_ macros from variable bindings
|
# Parse variables data.
|
||||||
my $count;
|
|
||||||
my @custom_values = split("\t", $trap_custom_oid);
|
my @custom_values = split("\t", $trap_custom_oid);
|
||||||
for ($count = 1; defined ($custom_values[$count-1]); $count++) {
|
|
||||||
my $macro_name = '_snmp_f' . $count . '_';
|
# Evaluate variable filters
|
||||||
my $order_field = $alert->{'order_'.$count};
|
my $filter_match = 1;
|
||||||
if ($custom_values[$count] =~ m/= \S+: (.*)/) {
|
for (my $i = 1; $i <= 20; $i++) {
|
||||||
|
my $order_field = $alert->{'order_'.$i} - 1;
|
||||||
|
|
||||||
|
# Only values greater than 0 allowed.
|
||||||
|
next if $order_field < 0;
|
||||||
|
|
||||||
|
my $filter_name = '_snmp_f' . $i . '_';
|
||||||
|
my $filter_regex = safe_output ($alert->{$filter_name});
|
||||||
|
my $field_value = $custom_values[$order_field];
|
||||||
|
|
||||||
|
# No filter for the current binding var
|
||||||
|
next if ($filter_regex eq '');
|
||||||
|
|
||||||
|
# The referenced binding var does not exist
|
||||||
|
if (! defined ($field_value)) {
|
||||||
|
$filter_match = 0;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Evaluate the filter
|
||||||
|
eval {
|
||||||
|
local $SIG{__DIE__};
|
||||||
|
if ($field_value !~ m/$filter_regex/) {
|
||||||
|
$filter_match = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
# Probably an invalid regexp
|
||||||
|
if ($@) {
|
||||||
|
# Filter is ignored.
|
||||||
|
logger($pa_config, "Invalid regex in SNMP alert #".$alert->{'id_as'}.": [".$filter_regex."]", 3);
|
||||||
|
# Invalid regex are ignored, test next variables.
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
# The filter did not match
|
||||||
|
last if ($filter_match == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
# A filter did not match
|
||||||
|
next if ($filter_match == 0);
|
||||||
|
|
||||||
|
# Assign values to _snmp_fx_ macros.
|
||||||
|
my $count;
|
||||||
|
for ($count = 0; defined ($custom_values[$count]); $count++) {
|
||||||
|
my $macro_name = '_snmp_f' . ($count+1) . '_';
|
||||||
|
my $target = $custom_values[$count];
|
||||||
|
|
||||||
|
if (!defined($target)) {
|
||||||
|
# Ignore emtpy data.
|
||||||
|
$macros{$macro_name} = '';
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($target =~ m/= \S+: (.*)/) {
|
||||||
my $value = $1;
|
my $value = $1;
|
||||||
|
|
||||||
# Strip leading and trailing double quotes
|
# Strip leading and trailing double quotes
|
||||||
@ -4010,40 +4063,6 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
|
|||||||
# All variables
|
# All variables
|
||||||
$macros{'_snmp_argv_'} = $trap_custom_oid;
|
$macros{'_snmp_argv_'} = $trap_custom_oid;
|
||||||
|
|
||||||
# Evaluate _snmp_fx_ filters
|
|
||||||
my $filter_match = 1;
|
|
||||||
for (my $i = 1; $i <= 10; $i++) {
|
|
||||||
my $filter_name = '_snmp_f' . $i . '_';
|
|
||||||
my $filter_value = safe_output ($alert->{$filter_name});
|
|
||||||
|
|
||||||
# No filter for the current binding var
|
|
||||||
next if ($filter_value eq '');
|
|
||||||
|
|
||||||
# The referenced binding var does not exist
|
|
||||||
if (! defined ($macros{$filter_name})) {
|
|
||||||
$filter_match = 0;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Evaluate the filter
|
|
||||||
eval {
|
|
||||||
if ($macros{$filter_name} !~ m/$filter_value/) {
|
|
||||||
$filter_match = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
# Probably an invalid regexp
|
|
||||||
if ($@) {
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
|
|
||||||
# The filter did not match
|
|
||||||
last if ($filter_match == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
# A filter did not match
|
|
||||||
next if ($filter_match == 0);
|
|
||||||
|
|
||||||
# Replace macros
|
# Replace macros
|
||||||
$alert->{'al_field1'} = subst_alert_macros ($alert->{'al_field1'}, \%macros);
|
$alert->{'al_field1'} = subst_alert_macros ($alert->{'al_field1'}, \%macros);
|
||||||
$alert->{'al_field2'} = subst_alert_macros ($alert->{'al_field2'}, \%macros);
|
$alert->{'al_field2'} = subst_alert_macros ($alert->{'al_field2'}, \%macros);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user