01 /*
02 * show_interface_staus.slax
03 *
04 * Created by Todd Okolowicz (tokolowicz@juniper.net) on 20090713.
05 * Copyright (c) 2011 Juniper Networks. All rights reserved.
06 *
07 * Version History
08 * ===============
09 * v0.1 Initial release (by Todd Okolowicz)
10 * v0.2 Modified to include vlans on a given port and whether
11 * or not it was trunked (by Robery Lemm)
12 *
13 */
14
15 version 1.0;
16
17 ns junos = "http://xml.juniper.net/junos/*/junos";
18 ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
19 ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
20
21 import "../import/junos.xsl";
22
23 /* This is imported into JUNOS as a CLI option */
24 var $arguments = {
25 <argument> {
26 <name> "interface";
27 <description> "Name of logical interface (e.g. ge-0/0/0.0)";
28 }
29 }
30
31 /* Command-line argument */
32 param $interface;
33
34 match / {
35 <op-script-results> {
36
37 /* Send JUNOS XML API Element via jcs:invoke */
38 var $results1 = jcs:invoke( "get-interface-information" );
39
40 /* Send JUNOS XML API Element via jcs:invoke */
41 var $command-rpc2 = <command> "show ethernet-switching interfaces";
42 var $results2 = jcs:invoke( $command-rpc2 );
43
44 var $command-rpc3 = <command> "show interfaces extensive";
45 var $results3 = jcs:invoke( $command-rpc3 );
46
47 var $command-rpc4 = <command> "show ethernet switching table";
48 var $results4 = jcs:invoke( $command-rpc4 );
49
50 /* This is a functional code block that uses a regular
51 * expression to check the interface cli option for correct syntax. I
52 * disabled it and opted for the code block below. The regex is a
53 * hard-coded and does not account for all possible hardware
54 * configurations (i.e. EX3200 vs. EX4200, uplink vs. no uplink, 1GbE
55 * or 10GbE uplink, Virtual Chassis or stand-alone, etc.) It is more
56 * accurate to compare the cli input vs. the list of Ethernet switching
57 * interfaces actually enabled in the system. I left the regex code block
58 * in for code re-use in future scripts and learning purposes.
59
60 * Error check for incorrect interface syntax using a regex.
61 if ( not ( jcs:empty ( $interface ) ) and jcs:empty ( jcs:regex ( "[xg]e-[0-9]/[0-1]/(([0-9])|([1-3][0-9])|(4[0-7])).0", $interface ) ) ) {
62 <xsl:message terminate="yes"> "The interface " _ $interface _ " isn't valid.\nUsage example: op show_interface_status interface ge-0/0/0.0";
63 }
64 */
65
66 var $matching-interface = $results2/interface [ interface-name == $interface ];
67 if( not ( jcs:empty ($interface ) ) and jcs:empty ( $matching-interface ) ) {
68 <xsl:message terminate="yes"> "The interface " _ $interface _ " isn't valid.\nUsage example: op show_interface_status interface ge-0/0/0.0";
69 }
70
71 /* Create node list based on location path, loop through each node */
72 <output> jcs:printf("%-13s%-25s%-25s%-7s%-14s%-9s%-12s%-10s%-10s%-10s%-10s%-12s%-13s%-16s%-12s%-13s%-12s","Interface", "Physical Description", "Logical Description", "Status", "VLAN Members", "Vlan-Id", "Port-mode", "In(bps)", "Out(bps)", "In-Err", "Out-Err", "Speed-Conf", "Duplex-Conf", "Flow-Ctrl-Conf","Speed(neg)", "Duplex(neg)", "Flow-Ctrl(neg)" );
73 for-each ( $results2/interface [ string-length($interface)==0 or interface-name=$interface ] ) {
74 var $first-vlan = interface-vlan-member-list/interface-vlan-member/interface-vlan-name [position() == 1 ];
75 var $vlan-tag = interface-vlan-member-list/interface-vlan-member/interface-vlan-member-tagid [position() == 1 ];
76 var $interface-name = interface-name;
77 var $status = interface-state;
78 var $vlan-tagness = interface-vlan-member-list/interface-vlan-member/interface-vlan-member-tagness;
79 var $logical-interface = $results1/physical-interface/logical-interface [name==$interface-name];
80 var $physical-interface = $results3/physical-interface/logical-interface [name==$interface-name];
81 var $phys-interface = $results3/physical-interface;
82 <output> jcs:printf("%-13s%-25s%-25s%-7s%-14s%-9s%-12s%-10s%-10s%-10s%-10s%-12s%-13s%-16s%-12s%-13s%-12s",$interface-name, $physical-interface/../description, $logical-interface/description, $status, $first-vlan, $vlan-tag, $vlan-tagness, $logical-interface/../traffic-statistics/input-bps, $logical-interface/../traffic-statistics/output-bps, $logical-interface/../input-error-count, $logical-interface/../output-error-count, $logical-interface/../speed, $logical-interface/../duplex, $logical-interface/../if-flow-control, $physical-interface/../ethernet-autonegotiation/link-partner-speed,$physical-interface/../ethernet-autonegotiation/link-partner-duplexity,$physical-interface/../ethernet-autonegotiation/flow-control );
83 for-each ( ./interface-vlan-member-list/interface-vlan-member[position() != 1 ] ) {
84 <output> jcs:printf("%-70s%-14s%-14s", "", ./interface-vlan-name, ./interface-vlan-member-tagid );
85 }
86 }
87 }
88 }
|