Blogs

Scripting How-To: Finding All Routes Added to the Routing Table Less Than 24 Hours (86400 Seconds) Ago

By Erdem posted 03-30-2016 14:24

  

In the get-route-information XML, each routing table entry has an age child with the junos:seconds attribute measured in seconds. Use the following SLAX script to find all routes whose age in seconds is less than 86400 seconds:

 

version 1.0;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
import "../import/junos.xsl";
var $arguments = {
<argument> {
<name> "time";
<description> "age of route in seconds [default 86,400]";
}
}
param $time = 86400;
match / {
<op-script-results> {
var $result = jcs:invoke( "get-route-information" );
for-each( $result/route-table/rt ) {
if( .//rt-entry/age/@junos:seconds < $time ) {
<output> jcs:printf("%-20s%-12s%-10s",.//rt-destination,.//age,.//protocol-name );
}
}
<output> "The script is complete";
}
}

 


#routingtableentry
#How-To