09-11-2019 01:32 PM
Not sure why, but Cisco did away with the "show interface link" command. We use it all the time as various switch cables are plugged in but never removed. This command would show us the last time the interface was active in a table sort of like show int status. We can make a decision with this data as to whether we could safely allocate this port for another device. I started working on a EEM applet that would step through the interfaces on a switch using "show interface" and provide the output from just 2 lines.
So for this show interface output, I just want to see 2 lines (underlined and bold)
GigabitEthernet1/0/1 is up, line protocol is up (connected)
Hardware is Gigabit Ethernet, address is a8b4.5601.b694 (bia a8b4.5601.b694)
Description: J317
MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 1000Mb/s, media type is 10/100/1000BaseTX
input flow-control is off, output flow-control is unsupported
ARP type: ARPA, ARP Timeout 04:00:00
Last input 00:02:56, output 00:00:00, output hang never
Last clearing of "show interface" counters 2w3d
Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: Class-based queueing
Output queue: 0/40 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 33000 bits/sec, 17 packets/sec
9592 packets input, 1965975 bytes, 0 no buffer
Received 7358 broadcasts (7301 multicasts)
0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 7301 multicast, 0 pause input
0 input packets with dribble condition detected
1321044 packets output, 336466693 bytes, 0 underruns
0 output errors, 0 collisions, 2 interface resets
0 unknown protocol drops
0 babbles, 0 late collision, 0 deferred
0 lost carrier, 0 no carrier, 0 pause output
0 output buffer failures, 0 output buffers swapped out
I was hoping to have the output be very simple and maybe get these on the same line eventually.
GigabitEthernet1/0/1 is up, line protocol is up (connected) Last input 00:02:56, output 00:00:00
GigabitEthernet1/0/2 is down, line protocol is down (notconnect) Last input never, output never
...etc.
I haven't made it very far in the process. Documentation is very limited.
Any ideas? Not all switches have the same interface. Some are Gi, Te, Fa, etc. Anyone ever used any of the built in interface variables? Maybe there is a way to pull this data from the show int status table?
Thanks!
Solved! Go to Solution.
09-12-2019 11:26 AM
This is what you want:
event manager applet SHOW_INT_LINK
event cli pattern "(sh|sho|show)\s+(int|inte|inter|interf|interfa|interfac|interface)\s+(link)" enter
action 001.1 cli command "enable"
action 001.2 puts "\n\nShow Interface Link (List shows ONLY notconnect ports)\n------------------------------------------------------"
action 001.3 cli command "show int status | i notconnect"
action 002.1 foreach _line "$_cli_result" "\n"
action 002.2 regexp "^([A-Z][a-z][0-9][^[:space:]]+)" "$_line" match _intf
action 002.3 if $_regexp_result eq "1"
action 003.1 cli command "show interface $_intf"
action 004.1 foreach _iline "$_cli_result" "\n"
action 004.2 regexp "^(.*Last input.*)\r$" "$_iline" match _lastup
action 004.3 if $_regexp_result eq "1"
action 004.4 puts "$_intf -$_lastup"
action 004.5 end
action 099.1 end
action 099.2 end
action 099.3 end
09-11-2019 02:16 PM
Hi there,
you need two regex strings. The first to match various interface names is:
\S.*Ethernet\d{1,3}\/\d{1,3}(\/\d{1,3}){0,1}
...and the second to match the 'Last input' line could be:
Last input.*$
You then need to save these matches to variables:
event manager applet some_applet action 01 syslog msg "Starting EEM Test" action 02 set test_file "test.txt" action 03 cli command "enable" action 04 cli command "show int gi1/0/1" action 05 regexp "\S.*Ethernet\d{1,3}\/\d{1,3}(\/\d{1,3}){0,1}" "$_cli_result" intf action 06 regexp "Last input.*$" "$_cli_result" lastup
The following will create the variables $intf and $lastup which correspond to the output of show int gi1/0/1 .
You will probably notice the above applet only works for an interface at a time and doesn't/ wouldn't work if you just tried regex'ing sh interface .
Personally if you wanted to do glean this output peridically I would look at scheduling a python script via cron. Python using netmiko will ssh you onto the switch prompt where you will be able to scrape the output into more managebale data structures.
Take a look at this script:
https://github.com/sebrupik/srupik-apic-em-tools/blob/master/frozenPony/src/oneLinerSimple.py
...to give you a starting point.
See this post for how to run it:
https://community.cisco.com/t5/routing/basic-python-script/td-p/3227660
cheers,
Seb.
09-12-2019 06:03 AM
09-12-2019 06:20 AM
As far as I know EEM doesn't have for loops, so it is not possible to iterate through lines in a file, which was why mysupplied applet was so limited. You might be able to create a TCL script (which is supported by IOS), but personally I would be leaning towards a python script at this point.
The best document available is:
https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/eem/configuration/15-mt/eem-15-mt-book.html
...but there are plenty of bespoke solutions on this forum if you know what to search for!
Sometimes it is best to call in our resident expert on these maters.. @Joe Clarke can you help?
cheers,
Seb.
09-12-2019 06:48 AM
You can use loops and conditionals in EEM applets provided you have EEM 3.0 or higher (which these days everyone should have). You can iterate over the "show int status" lines:
cli command "show int status | inc notconn"
foreach line "$_cli_result" "\n"
regexp "^([A-Z][a-z][0-9][^[:space:]]+)" $line match intf
if $_regexp_result eq "1"
puts "Interface is $intf; do your 'show int' stuff here"
end
end
09-12-2019 07:10 AM
Thanks @Joe Clarke , that's a nice applet! :)
09-12-2019 09:06 AM
09-12-2019 11:26 AM
This is what you want:
event manager applet SHOW_INT_LINK
event cli pattern "(sh|sho|show)\s+(int|inte|inter|interf|interfa|interfac|interface)\s+(link)" enter
action 001.1 cli command "enable"
action 001.2 puts "\n\nShow Interface Link (List shows ONLY notconnect ports)\n------------------------------------------------------"
action 001.3 cli command "show int status | i notconnect"
action 002.1 foreach _line "$_cli_result" "\n"
action 002.2 regexp "^([A-Z][a-z][0-9][^[:space:]]+)" "$_line" match _intf
action 002.3 if $_regexp_result eq "1"
action 003.1 cli command "show interface $_intf"
action 004.1 foreach _iline "$_cli_result" "\n"
action 004.2 regexp "^(.*Last input.*)\r$" "$_iline" match _lastup
action 004.3 if $_regexp_result eq "1"
action 004.4 puts "$_intf -$_lastup"
action 004.5 end
action 099.1 end
action 099.2 end
action 099.3 end
09-12-2019 11:42 AM
10-21-2020 09:56 AM
Hi Joe ,
I have been trying to shutdown the interface using EEM applet , if we are using above applet it is listing the interface for which Last Input
Never for instance. How EEM to get it work to disable the ports in that case.
Could you please help with this query.
Regards
Sanjay
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide