/* * show_interface_staus.slax * * Created by Todd Okolowicz (tokolowicz@juniper.net) on 20090713. * Copyright (c) 2009 Juniper Networks. All rights reserved. * * Version History * =============== * v0.1 Initial release. * v0.2 Modified by Andy Millett to include interface descriptions. */ 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"; /* This is imported into JUNOS as a CLI option */ var $arguments = { { "interface"; "Name of logical interface (e.g. ge-0/0/0.0)"; } } /* Command-line argument */ param $interface; match / { { /* Send JUNOS XML API Element via jcs:invoke */ var $results1 = jcs:invoke( "get-interface-information" ); /* Send JUNOS XML API Element via jcs:invoke */ var $command-rpc = "show ethernet-switching interfaces"; var $results2 = jcs:invoke( $command-rpc ); /* This is a functional code block that uses a regular * expression to check the interface cli option for correct syntax. I * disabled it and opted for the code block below. The regex is a * hard-coded and does not account for all possible hardware * configurations (i.e. EX3200 vs. EX4200, uplink vs. no uplink, 1GbE * or 10GbE uplink, Virtual Chassis or stand-alone, etc.) It is more * accurate to compare the cli input vs. the list of Ethernet switching * interfaces actually enabled in the system. I left the regex code block * in for code re-use in future scripts and learning purposes. * Error check for incorrect interface syntax using a regex. 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 ) ) ) { "The interface " _ $interface _ " isn't valid.\nUsage example: op show_interface_status interface ge-0/0/0.0"; } */ var $matching-interface = $results2/interface [ interface-name == $interface ]; if( not ( jcs:empty ($interface ) ) and jcs:empty ( $matching-interface ) ) { "The interface " _ $interface _ " isn't valid.\nUsage example: op show_interface_status interface ge-0/0/0.0"; } /* Create node list based on location path, loop through each node */ jcs:printf("%-15s%-7s%-15s%-12s%-12s%-15s%-12s", "Interface", "Status", "VLAN Members", "Port-mode", "Speed", "Duplex", "Description" ); for-each ( $results2/interface [ string-length($interface)==0 or interface-name=$interface ] ) { var $first-vlan = interface-vlan-member-list/interface-vlan-member/interface-vlan-name [position() == 1 ]; var $interface-name = interface-name; var $status = interface-state; var $vlan-tagness = interface-vlan-member-list/interface-vlan-member/interface-vlan-member-tagness; var $logical-interface = $results1/physical-interface/logical-interface [name==$interface-name]; jcs:printf("%-15s%-7s%-15s%-12s%-12s%-15s%-12s", $interface-name, $status, $first-vlan, $vlan-tagness, $logical-interface/../speed, $logical-interface/../duplex, $logical-interface/../description ); /* Second for-each loop embedded within first to create node-list of additional vlans possibly assigned to trunk interfaces */ for-each ( ./interface-vlan-member-list/interface-vlan-member[position() != 1 ] ) { jcs:printf("%-22s%-12s", "", ./interface-vlan-name ); } } } }