Automation
Automation

Scripting How-To: Write a syslog message on receiving RPD_OSPF_NBRDOWN event

by Cordelia on ‎08-14-2015 10:10 AM - edited on ‎08-23-2017 12:02 PM by Administrator Administrator (1,309 Views)

Use the ospf_adjacency_flapping Script


For SLAX version 1.0 and higher, you can use the ospf_adjacency_flapping script to write a syslog message on receiving RPD_OSPF_NBRDOWN event. This script raises an syslog message with high priority value in response to the event received.

 

Source Code and GitHub Links

 

The source code below is also available from GitHub at the following locations:
 

Example Configuration

01 The following configuration are needed.
02  
03 user@cli# show system scripts
04 op {
05      file ospf_adjacency_flapping.slax;
06 }
07  
08 user1@ritter# show event-options
09 policy ospf_adjacency_flapping {
10      events rpd_ospf_nbrdown;
11      then {
12          event-script ospf_adjacency_flapping.slax;
13      }
14 }
15  
16 Copy the script ospf_adjacency_flapping.slax to /var/db/script/op directory.
17  
18 This script will work with 9.0 or above because it uses jcs:syslog() function which is introduced in 9.0
19  
20 In additional, due to PR 76849 we cannot log the details, we can only log a simple message as a caveat.

SLAX Script Contents

01 /*
02  * Very simple script which gets triggerd on receiving
03  * RPD_OSPF_NBRDOWN event. RPD_OSPF_NBRDOWN is received when OSPF neighbor
04  * adjacency was terminated. This script raises an syslog message
05  * with high priority value.
06  *
07  * Due to a known issue (PR 76849) this script will not get event details.
08  * So, we can only log a simple log message saying OSPF adjacency happened
09  * but not the details.
10  */
11  
12  
13 version 1.0;
14  
15 ns junos = "http://xml.juniper.net/junos/*/junos";
18  
19 import "../import/junos.xsl";
20  
21 match / {
22      
23     expr jcs:syslog("daemon.crit", "OSPF neighbor adjacency was terminated");
24  
25 }
 
XML Script Contents
 
 
 
01 <?xml version="1.0"?>
02 <script>
03   <title>ospf_adjacency_flapping.slax</title>
04   <author>rsankar</author>
05   <synopsis>
06     Write a syslog message on receving RPD_OSPF_NBRDOWN event
07   </synopsis>
08   <coe>event</coe>
09   <type>protocols</type>
10  
11   <description>
12 This script raises an syslog message with high priority value in response to the event received
13  
14   </description>
15  
16   <keyword>mvpn</keyword>
17   <example>
18     <title>Configuration</title>
19     <description>Configuration required for this event script</description>
20     <config>example-1.conf</config>
21   </example>
22  
23   <xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
24                 src="../../../../../web/leaf.js"
25             type="text/javascript"/>
26 </script>