From bc36bb053411dc4b6c4b403aa8e59e481595c127 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Mon, 17 Dec 2018 15:39:44 +0100 Subject: [PATCH] Add support for exact matches to SNMP alerts. Ref pandora_enterprise#3214. Former-commit-id: 35aa55d4d2ae236e614be7f4db50a9eb9f62aafa --- pandora_console/godmode/snmpconsole/snmp_alert.php | 2 +- pandora_server/lib/PandoraFMS/Core.pm | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index 870597bee5..b223d8dafe 100755 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -634,7 +634,7 @@ if ($create_alert || $update_alert) { // OID echo '' . - '' . __('Enterprise String') . '' . + '' . __('Enterprise String') . ui_print_help_tip (__('Matches substrings. End the string with $ for exact matches.'), true) . '' . ''; html_print_input_text ("oid", $oid, '', 50, 255); echo ''; diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index c986eb0510..f4485e789b 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -3400,7 +3400,16 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { $alert->{'oid'} = decode_entities($alert->{'oid'}); my $oid = $alert->{'oid'}; if ($oid ne '') { - next if (index ($trap_oid, $oid) == -1 && index ($trap_oid_text, $oid) == -1); + my $term = substr($oid, -1); + # Strict match. + if ($term eq '$') { + chop($oid); + next if ($trap_oid ne $oid && $trap_oid_text ne $oid); + } + # Partial match. + else { + next if (index ($trap_oid, $oid) == -1 && index ($trap_oid_text, $oid) == -1); + } $alert_data .= "OID: $oid "; }