Junos OS

last person joined: 6 days ago 

Ask questions and share experiences about Junos OS.
  • 1.  Re: JUNOS Perl API - How to 'grep' or 'match' operational command output on router

    Posted 02-10-2010 14:18

    Brilliant! The script works like a treat. Thank you for your help.

     

    Regards,

     

    Richard



  • 2.  RE: Re: JUNOS Perl API - How to 'grep' or 'match' operational command output on router

    Posted 02-09-2010 01:58

    Hello, I'm writng some Perl code to download the current ARP table for a specific interface via the JUNOS Perl Module. The required operational command is "get-arp-table-information", however you cannot specify a specific interface and I'm reluctant to download thousands of ARP entries from the router and then grep the result in code.

     

    Is it possible to apply a 'match' or 'grep' at the time the operational command is run ie equivalent to the cli option of:

     

    >show arp | match ge-0/0/1.20

     

    Many thanks,

     

    Richard McCarthy

    NEC Australia



  • 3.  RE: Re: JUNOS Perl API - How to 'grep' or 'match' operational command output on router

    Posted 02-09-2010 05:37

    Generally speaking, pipes do not work from scripts.  You could always try:

    <command>show arp | match ge-0/0/1.20</command> but I don't expect it to work.

     

    As an alternative, you could install an op script locally on the Junos device that filtered out the arp results for you.  This op script could be called via the <op-script> API element:

     

    http://www.juniper.net/techpubs/software/junos/junos93/junos-xml-ref-oper/html/summary-oper-request510.html#1786729



  • 4.  RE: Re: JUNOS Perl API - How to 'grep' or 'match' operational command output on router

    Posted 02-09-2010 12:55

    Hello and thankyou for your reply. I have tried your suggestion and written a simple opscript and then called it from the Perl API. It works ok, but  notice that the perl call only returns the first line of the op script output? ie if I return multiple lines of arp entries with carriage returns, the other lines past the first line are not returned into the perl module.

     

    Any ideas?



  • 5.  RE: Re: JUNOS Perl API - How to 'grep' or 'match' operational command output on router

    Posted 02-09-2010 13:15

    Could you post the op script you are using?



  • 6.  RE: Re: JUNOS Perl API - How to 'grep' or 'match' operational command output on router

    Posted 02-09-2010 21:51

    Hi, here is the initial script that I've got running. Each MAC address is printed out on a separate line (as you would expect). Can you concatentate the MAC addresses instead using comma separation?

     

    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> "interface";
      <description> "Interface name";
     }
    }

     

    param $interface;

     

    match / {
     <op-script-results> {
      if ($interface) {
       var $rpc = {
        <get-arp-table-information> {
         <expiration-time>;
        }
       }
       var $out = jcs:invoke($rpc);
       if ($out//xnm:error) {
        copy-of $out//xnm:error;
       }
       for-each ($out/arp-table-entry[interface-name = $interface]) {
        <output> ./mac-address;
       }
      }
     }
    }



  • 7.  RE: Re: JUNOS Perl API - How to 'grep' or 'match' operational command output on router

    Posted 02-10-2010 05:05

    Try the following:

     

    <output> {

        for-each ($out/arp-table-entry[interface-name = $interface]) {
            expr ./mac-address;

            if( position() != last() ) {

                expr ",";

            }

        }

    }