This article explains how to use regular expressions in Junos event policies to filter events based on specific event attributes.
Overview:
Regular expressions can be used with the attributes-match statement to provide more precise filtering of events. By matching specific attribute values, an event policy can trigger actions only when the defined criteria are met.
attributes-match
Configure the attributes-match statement under the event policy as shown below:
[edit event-options policy <policy-name> attributes-match] event.<attribute-name> matches <regular-expression>;
Where:
interface-name
bgp-peer
event-message
The following configuration matches BGP peers in the 192.168.1.0/24 subnet and raises an SNMP trap when a bgp_connect_failed event occurs.
192.168.1.0/24
bgp_connect_failed
set event-options policy bgp events bgp_connect_failedset event-options policy bgp attributes-match bgp_connect_failed.peer-name matches "^192\.168\.1\.[0-9]{1,3}$"set event-options policy bgp then raise-trap
The regular expression:
^192\.168\.1\.[0-9]{1,3}$
matches any IP address in the 192.168.1.0/24 subnet.
The following configuration matches interfaces ranging from ge-0/0/0 through ge-0/0/9 and raises an SNMP trap when a snmp_trap_link_down event is generated.
ge-0/0/0
ge-0/0/9
snmp_trap_link_down
set event-options policy interface-flap events snmp_trap_link_downset event-options policy interface-flap attributes-match snmp_trap_link_down.interface-name matches "^ge-0/0/[0-9]+$"set event-options policy interface-flap then raise-trap
^ge-0/0/[0-9]+$
matches interface names beginning with ge-0/0/ followed by one or more digits, such as:
ge-0/0/
ge-0/0/1
Using regular expressions with the attributes-match statement enables more granular event filtering in Junos event policies. This allows administrators to trigger actions, such as raising SNMP traps, only for events that match specific interface names, IP addresses, or other event attributes.
v1