[j-nsp] Simple Script Running

Serge Vautour sergevautour at yahoo.ca
Thu Feb 3 11:49:27 EST 2011


Hello,

For example, here's a script that checks OSPF, LDP and BGP neighbors on a box 
with 1 commands.

blah at PE1-STJHLab-re0> op status-neighbors

- OSPF: There are 4 active OSPF neighbors. Those neighbors are:
           Interface: ge-1/3/9.0 , IP Address: 10.10.81.5 , ID: 10.10.80.3
           Interface: xe-0/0/0.0 , IP Address: 10.10.81.1 , ID: 10.10.80.80
           Interface: xe-0/2/0.0 , IP Address: 10.10.81.11 , ID: 10.10.80.10
           Interface: xe-7/1/0.0 , IP Address: 10.10.81.9 , ID: 10.10.80.80

- BGP: There are 2 active BGP neighbors. Those neighbors are:
           Session with: 10.10.80.50 , in AS: 855 , IP Address:10.10.80.50+53564
           Session with: 10.10.80.52 , in AS: 855 , IP Address:10.10.80.52+179

- LDP: There are 3 active LDP neighbors. Those neighbors are:
           Session with: 10.10.80.3 (neighbor ID)
           Session with: 10.10.80.10 (neighbor ID)
           Session with: 10.10.80.80 (neighbor ID)


The script is below. Lots of examples at: 
http://code.google.com/p/junoscriptorium/

Serge

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";
 
match / {
    <op-script-output> {
        var $command1 = {
            <command> 'show ospf neighbor';
        }
        var $out1 = jcs:invoke($command1);
        var $contador1 = count($out1/ospf-neighbor[ospf-neighbor-state = 
'Full']);
        <output> {
            if ($contador1) {
                expr '\n\n- OSPF: There are ' _ $contador1 _ ' active OSPF 
neighbors. Those neighbors are:\n';
                for-each ($out1/ospf-neighbor) {
                        var $ifname = ./interface-name;
                        var $ip = ./neighbor-address;
                        var $id = ./neighbor-id;
                        expr '           Interface: ' _ $ifname _ ' , IP 
Address: ' _ $ip _ ' , ID: ' _ $id _ '\n';
                }
            } else {
                expr "\n\n- OSPF: There are not active OSPF neighbors.\n";
            }
        }
 
        var $command3 = {
            <command> 'show bgp neighbor';
        }
        var $out3 = jcs:invoke($command3);
        var $contador3 = count($out3/bgp-peer[peer-state = 'Established']);
        <output> {
            if ($contador3) {
                expr '\n\n- BGP: There are ' _ $contador3 _ ' active BGP 
neighbors. Those neighbors are:\n';
                for-each ($out3/bgp-peer) {
                        var $ip = ./peer-address;
                        var $id = ./peer-id;
                        var $as = ./peer-as;
                        expr '           Session with: ' _ $id _ ' , in AS: ' _ 
$as _ ' , IP Address:' _ $ip _ '\n';
                }
            } else {
                expr "\n\n- BGP: There are not active BGP neighbors.\n";
            }
        }
 
 
        var $command4 = {
            <command> 'show ldp session';
        }                               
        var $out4 = jcs:invoke($command4);
        var $contador4 = count($out4/ldp-session[ldp-connection-state = 
'Open']);
        <output> {
            if ($contador4) {
                expr '\n\n- LDP: There are ' _ $contador4 _ ' active LDP 
neighbors. Those neighbors are:\n';
                for-each ($out4/ldp-session) {
                        var $ip = ./ldp-neighbor-address;
                        expr '           Session with: ' _ $ip _ ' (neighbor 
ID)\n';
                }
            } else {
                expr "\n\n- LDP: There are not active LDP neighbors.\n";
            }
        }
 
 
     }
}


----- Original Message ----
From: ben b <benboyd.lists at gmail.com>
To: juniper-nsp <juniper-nsp at puck.nether.net>
Sent: Thu, February 3, 2011 10:59:02 AM
Subject: [j-nsp] Simple Script Running

All,

I'm trying to get a feel for op scripts in JUNOS and I can invoke commands,
but I'm not seeing the output I thought I'd see (it looks like raw data).

What I'd like to do is run a list of show commands with a script alias.

Could someone point me in the right direction to be able to run like 5
'show' commands (with normal output) in a row with one simple command like
'op status'


Thanks in advance,
Ben
_______________________________________________
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