ON THIS PAGE
Example: Raise an SNMP Trap in Response to an Event
This example configures an event policy to raise a trap and to execute an event script in response to an event:
Requirements
A device running Junos OS, which is configured for SNMP.
Overview
The following example configures the event policy raise-trap-on-ospf-nbrdown
to trigger on the RPD_OSPF_NBRDOWN
event, which indicates a terminated OSPF adjacency with a neighboring
router. The event policy action raises a trap in response to the event.
The device sends a notification to the SNMP manager, if one is configured
under the [edit snmp]
hierarchy level.
Additionally, the event policy executes the event script ospf.xsl in response to this event and provides
the affected interface as an argument to the script. The $$rpd_ospf_nbrdown.interface-name
argument resolves to the interface name associated with the triggering
event.
The event script output is recorded in the file ospf-out, and the output file is uploaded to the
destination mgmt-archives
, which is configured
at the [edit event-options destinations]
hierarchy level.
To invoke an event script in an event policy, the event script must
be present in the /var/db/scripts/event directory on the hard disk, and it must be enabled in the configuration.
Configuration
CLI Quick Configuration
To quickly configure this example, copy the following
commands, paste them in a text file, remove any line breaks, change
any details necessary to match your network configuration, and then
copy and paste the commands into the CLI at the [edit]
hierarchy
level.
set event-options policy raise-trap-on-ospf-nbrdown events rpd_ospf_nbrdown set event-options policy raise-trap-on-ospf-nbrdown then raise-trap set event-options policy raise-trap-on-ospf-nbrdown then event-script ospf.xsl arguments interface "{$$rpd_ospf_nbrdown.interface-name}" set event-options policy raise-trap-on-ospf-nbrdown then event-script ospf.xsl output-filename ospf-out set event-options policy raise-trap-on-ospf-nbrdown then event-script ospf.xsl destination mgmt-archives
Configuring the Event Policy
Step-by-Step Procedure
To configure an event policy that raises a trap on receipt of an event and optionally executes an event script:
Create and name the event-policy.
[edit] user@R1# edit event-options policy raise-trap-on-ospf-nbrdown
Configure the event policy to match on the desired event, which in this example is the
RPD_OSPF_NBRDOWN
event.[edit event-options policy raise-trap-on-ospf-nbrdown] user@R1# set events rpd_ospf_nbrdown
Configure the event policy action to raise an SNMP trap in response to the event.
[edit event-options policy raise-trap-on-ospf-nbrdown] user@R1# set then raise-trap
(Optional) Configure additional actions to take in response to the event.
This example executes an event script and uploads the associated output file to a predefined destination.
[edit event-options policy raise-trap-on-ospf-nbrdown] user@R1# set then event-script ospf.xsl arguments interface {$$rpd_ospf_nbrdown.interface-name} user@R1# set then event-script ospf.xsl output-filename ospf-out destination mgmt-archives
Commit the configuration.
user@R1# commit
Results
[edit event-options] policy raise-trap-on-ospf-nbrdown { events rpd_ospf_nbrdown; then { event-script ospf.xsl { arguments { interface "{$$rpd_ospf_nbrdown.interface-name}"; } output-filename ospf-out; destination mgmt-archives; } raise-trap; } }