[j-nsp] read CLI "banner" XML element value with SLAX script

Jonathan Looney jonlooney at gmail.com
Wed Jan 13 11:25:11 EST 2016


You can get the same information from the <junos-context> node passed in
the <op-script-input> document. The <junos-context> node is also stored in
the $junos-context variable.

For example:

root at r0-re0:~ # cat /var/tmp/is-master.slax
version 1.1;


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


match / {
    <op-script-output> {
        <output> {
            expr "Through method one, this is the ";
            if (op-script-input/junos-context/re-master) {
                expr "master.";
            } else {
                expr "slave.";
            }
        }
        <output> {
            expr "Through method two, this is the ";
            if ($junos-context/re-master) {
                expr "master.";
            } else {
                expr "slave.";
            }
        }
    }
}

root at r0-re0:~ # cli
root at r0-re0> op url /var/tmp/is-master.slax
Through method one, this is the master.
Through method two, this is the master.



root at r0-re1> op url re0:/var/tmp/is-master.slax
Through method one, this is the slave.
Through method two, this is the slave.


By the way, as a shameless plug, a colleague and I are co-authoring a book
on Junos automation, due out soon:
http://shop.oreilly.com/product/0636920041498.do . The book shows the
junos-context portion of the input document. There is some other
potentially useful information in the junos-context node (hostname, model,
time, executing username, etc.).

Jonathan


On Wed, Jan 13, 2016 at 6:49 AM, Martin T <m4rtntns at gmail.com> wrote:

> Hi,
>
> Junos has "banner" XML element under "rpc-reply" and "cli" hierarchy:
>
> <rpc-reply>
>   <cli>
>     <banner></banner>
>   </cli>
> </rpc-reply>
>
> Is it somehow possible to read the value of "banner" element with SLAX
> script? For example I have a router with dual routing-engines, i.e
> "banner" element has either value of "{master}" or "{backup}":
>
> {master}
> root at M10i> show version brief | display xml | find cli
>     <cli>
>         <banner>{master}</banner>
>     </cli>
> </rpc-reply>
>
> {master}
> root at M10i>
>
>
> Now if I try to print the value of "banner" element, then this does not
> work:
>
>
> {master}
> root at M10i> file show /var/db/scripts/op/show-banner.slax
> version 1.0;
>
> ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
>
> match / {
>   <op-script-results> {
>     var $sh_ver_cmd = <command> "show version brief";
>     var $sh_ver_cmd_out = jcs:invoke( $sh_ver_cmd );
>     var $banner_var = $sh_ver_cmd_out//banner;
>     <output> $banner_var;
>   }
> }
>
> {master}
> root at M10i> op show-banner
>
>
> {master}
> root at M10i>
>
>
> Is there a way to process everything between <rpc-reply></rpc-reply>
> elements? I'm afraid that my script processes data between
> <software-information> and </software-information> elements.
>
>
> thanks,
> Martin
> _______________________________________________
> juniper-nsp mailing list juniper-nsp at puck.nether.net
> https://puck.nether.net/mailman/listinfo/juniper-nsp
>


More information about the juniper-nsp mailing list