Blog Viewer

Scripting How-To: Display similar output to the Cisco IOS command "show interface status"

By Erdem posted 08-14-2015 15:46

  

 

Display Similar Output to the Cisco IOS "show interface status" Command

 

For SLAX version 1.0 and higher, you can use the show-interface-status script to mirror the Cisco IOS command "show interface status".

 

This script displays the logical-interface name, status, VLAN members, speed, and duplex of the Ethernet switching-interfaces on the system. It provides similar output to the Cisco IOS command "show interface status".

 

A command-line argument exists (interface) that filters the exact interface. Error checking is performed based on the interface you enter.

Source Code and GitHub Links

 

The source code below is also available from the following GitHub locations:

 

 

Example Configuration

1 set system scripts op file show-interface-status.slax

Example Output

01 user@cli# run op show-interface-status
02 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)
03 ae6.0                                                          up     IC-to-ISG     100      untagged   186080    187144                        3Gbps                   disabled                                            
04 ae7.0                                                          down   default       100      untagged   0         0                             Unspecified              disabled                                            
05 ge-0/0/0.0                                                     up     IC-to-ISG     100      untagged   45496     320544                        Auto        Auto         enabled         1000 Mbps   full-duplex None       
06 ge-0/0/1.0                                                     up     IC-to-ISG     100      untagged   0         366048                        Auto        Auto         enabled         1000 Mbps   full-duplex None       
07 ge-0/0/2.0                                                     up     IC-to-ISG     100      untagged   46040     321568                        Auto        Auto         enabled         1000 Mbps   full-duplex None       
08 ge-0/0/3.0                                                     up     IC-to-ISG     100      untagged   0         366048                        Auto        Auto         enabled         1000 Mbps   full-duplex None       
09 ge-0/0/6.0                                                     up     IC-to-ISG     100      untagged   47032     319520                        1000mbps    Full-Duplex  enabled                                             
10 ge-0/0/8.0                                                     down   default       100      untagged   0         0                             1000mbps    Full-Duplex  enabled                                             
11 ge-0/0/18.0                                                    up     IC-to-ISG     100      untagged   0         366048                        Auto        Auto         enabled         1000 Mbps   full-duplex  Symmetric  
12 ge-0/0/19.0                                                    up     IC-to-ISG     100      untagged   45496     321056                        Auto        Auto         enabled         1000 Mbps   full-duplex  Symmetric  
13 ge-0/0/20.0                                                    up     IC-to-ISG     100      untagged   0         366496                        Auto        Auto         enabled         1000 Mbps   full-duplex  Symmetric  
14 ge-0/0/21.0                                                    up     IC-to-ISG     100      untagged   0         365984                        Auto        Auto         enabled         1000 Mbps   full-duplex  Symmetric
 
SLAX Script Contents
 
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 } 
 
XML Script Contents
 
01 <?xml version="1.0"?>
02 <script>
03 <title>show-interface-status.slax</title>
04 <author>tokolowicz</author>
05 <synopsis>
06 This script mirrors the Cisco IOS comand "show interface status"
07 </synopsis>
08 <coe>op</coe>
09 <type>display</type>