Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

Show specific information from output

05.16.18   |  
a week ago

Thanks to user PK, I was able to get my route op script working. Now I have another question. One of the elements (is that the right term?) prints out multiple lines:

 

user@router1> op route ip 192.168.0.67
Prefix            Source Router       AS Path
192.168.0.0/16    10.45.6.43          AS path: 1234 I (Originator)
Cluster list: 8.45.6.66
Originator ID: 10.45.6.43
AS path: Recorded

If I only want the 'AS path' line and nothing else, where should I look to figure this out? So far, I have looked into regex(), substring-after() and split(), but I'm not sure which one is correct. Here is the entire script:

 

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";

/*
 * Shows the source router and AS path of an IP in the network
 */

var $arguments = {
   <argument> {
      <name> "ip";
      <description> "Destination IP address";
      }
   }
   param $ip;
   match / {
   <op-script-results> {
       var $rpc = {
          <get-route-information> {
          <detail>;
          <destination> $ip;
          }
       }
       var $out = jcs:invoke($rpc);
       <rt junos:style="detail"> {
             <output> 'Prefix               Source Router     AS Path';
                 for-each ($out/route-table/rt) {
             <output> jcs:printf('%-20s %-17s %-s', rt-destination _ "/" _ rt-prefix-length, rt-entry/protocol-nh/to, rt-entry/as-path);
             }
          }
       }
    }

I am thinking what I need is something like:

 

       var $path = substring-after("AS path:", ":")

But I am not sure how to apply it to the script or how to relate it to the rt-entry/as-path element. Do I need another for-each function to cycle through the output of the specific rt-entry/as-path element?