Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Webcast-Catalyst9k
New Member

Up/Down scripting for Serial interfaces.

I need to get traps for several Interfaces when they go up and down.

Serial 0/0/0:0

Serial 0/1/0:9

FXO 0/1/1:21

are some examples

I have been doing so with rmon traps like below

rmon event 10 log trap SIL description RmonEvent owner ABCD

rmon alarm 10 ifOperStatus.10 1 absolute rising-threshold 2 10 falling-threshold 1 10 owner ABCD

The problem is that the ifindex often moves when a router is changed out (which occurs more often than you think.). the Port designation don't change but the ifindex does.

When this happens i have to adjust the rmon stuff manually.

What I need to do is create a EEM script that sets up a trap based on the interface name that traps when it goes up or down.

Is this doeable?

Everyone's tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

Up/Down scripting for Serial interfaces.

You're missing a space.

action 1.3 regexp "= ([0-9]+)" "$_cli_result" match ifindex

14 REPLIES
Cisco Employee

Up/Down scripting for Serial interfaces.

You can use syslog messages for this.  For example:

event manager applet slg-to-trap

event syslog pattern "Line protocol on Interface.*changed state to"

action 1.0 regexp "Interface ([^,]+), changed state to (up|down)" $_syslog_msg match intf state

action 2.0 snmp-trap strdata "Interface $intf changed state to $state"

New Member

Up/Down scripting for Serial interfaces.

Thanks,

Bear in mind this scripting stuff is new to me.

I tried this and dont think it  works.

Does the Serial Port go up and down like an Ethernet port?

I dont see any "Serial0/0/0:10" going up and or down....

Cisco Employee

Up/Down scripting for Serial interfaces.

Okay.  If you're not getting syslogs, then you can use the track event detector to do what you want.  you will need to create multiple applets, though.  For example:

track 1 interface Se0/0/0:10 line-proto

!

event manager applet Se0_0_0_10

event track 1 state any

action 1.0 snmp-trap strdata "Interface Serial0/0/0:10 changed state to $_track_state"

New Member

Up/Down scripting for Serial interfaces.

That works GREAT on the serial interfaces however, I have an E1 going to a channelbank over DS0 connection that I need to track.

For example: FXO 0/1/1:21 is a channel on a E1 that I need to track up and down.

I can do so with a rmon event on its ifoperstatus.(ifindex) but the ifindex changes between routers.

When I do a track 1 interface ? the controller e1 or the FXO is not there to enter.

Any thoughts on how to fix this one?

Thanks again.

Cisco Employee

Up/Down scripting for Serial interfaces.

You'd have to use something like the timer event detector, but then things become much more complex as you need to track previous state.  Why not configure:

snmp-server ifindex persist

So that ifIndex values don't change.  then you can continue to use RMON or use the SNMP event detector in EEM to monitor those interfaces.

New Member

Up/Down scripting for Serial interfaces.

Thanks again Joseph.

If have ifindex persist in my configuration and that keeps the ifindexes from moving between reboots however, I have times when I swap the entire router out and the ifindexes move. For example the ifindex for FXO 0/1/1:21 on Router 1 was 210... When I installed router 2 it is 258.

What I was thinking about doing was creating a bootup event that does the following.

1. Looks up the ifindex of FXO 0/1/1:21 using cli show snmp mib ifmib ifindex | include FXO 0/1/1:21 and puts this value in a variable.

2. Via a cli command, create an rmon event and an rmon alarm using that variable.

I think I know how to do the cli stuff but how to put the ifindex in step 1 into a variable for step 2 is a question...

There has to be a better way but.....

Would this work?

New Member

Up/Down scripting for Serial interfaces.

I have figured out how to get the results of the "show snmp mib ifmib ifindex | include FXO 0/1/1:21" into $_cli_result.

This variable contains a string like "FXO 0/1/1:21 IFIndex = 258". What I need to do now is to strip off the number at the end to use in the rmon creation.

I have been trying several regular expressions to no avail. Help?

Cisco Employee

Up/Down scripting for Serial interfaces.

This should work:

regexp "= ([0-9]+)" $_cli_result match ifindex

puts "ifIndex is $ifindex"

New Member

Up/Down scripting for Serial interfaces.

Thanks. I really appreciate your help. That regexp did not work however.

event manager applet HST1

action 1.0   cli command "enable"

action 1.1   cli command "show snmp mib ifmib ifindex | include FXO 0/1/1:21"

action 1.2   puts "$_cli_result"

action 1.3   regexp "=([0-9]+)" "$_cli_result" match ifindex

action 1.4   puts "$ifindex"

Prints out the cli result

FXO 0/1/1:21: Ifindex = 258

Then throws an error...

%HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: ifindex

%HA_EM-3-FMPD_ERROR: Error executing applet HST1 statement 1.4

Cisco Employee

Up/Down scripting for Serial interfaces.

You're missing a space.

action 1.3 regexp "= ([0-9]+)" "$_cli_result" match ifindex

New Member

Up/Down scripting for Serial interfaces.

You absolutely right. missing space...

Works like a champ now....

Thanks Joseph

New Member

Up/Down scripting for Serial interfaces.

Below is the code that I eneded up using:

event manager applet CreateRMON

event timer countdown time 1

action 1.0 cli command "enable"

action 2.0 set iflist "Serial0/0/0:0:,Serial0/0/0:1:,Serial0/0/0:2:,Serial0/0/0:3:,Serial0/0/0:4:,Serial0/0/0:5:"

action 2.1 append iflist ",Serial0/0/0:6:,Serial0/0/0:7:,Serial0/0/0:8:,Serial0/0/0:9:,Serial0/0/0:11:,Serial0/0/0:12:"

action 2.2 append iflist ",Serial0/0/0:13:,Serial0/0/0:14:,FXO 0/1/1:21:,FXO 0/1/1:22:"

action 3.0 foreach interface $iflist ,

action 4.0   cli command "show snmp mib ifmib ifindex | include $interface"

action 4.1   regexp "= ([0-9]+)" "$_cli_result" match ifindex

action 5.0   cli command "config t"

action 5.1   cli command "no rmon event $ifindex"

action 5.2   cli command "no rmon alarm $ifindex"

action 6.0   cli command "rmon event $ifindex log trap SIL description CCSRmon owner CCSAdmin"

action 6.1   cli command "rmon alarm $ifindex ifOperStatus.$ifindex 1 absolute rising-threshold 2 $ifindex falling-threshold 1 $ifindex owner CCSAdmin"

action 6.2   cli command "end"

action 7.0 end

New Member

Up/Down scripting for Serial interfaces.

Hi Joseph,

I've largely copied the above script, customized it for a Nexus switch and attempted (albeit round peg in a square hole) to also have the script fwd out an email everytime any of the Ethernet switchports change to a down state.  The purpose is to preempt a call from the client about a loss of service & notify our teammates before the client is even aware that a loss of service has occurred.

Please see below and let me know if my advanced "copy & paste" skills are up to par!

conf t

event manager applet CreateRMON

description Report when Source Circuit Drops from the Source on a per interface basis.

event timer countdown time 1

action 1.0 cli command "enable"

action 2.0 set iflist "Ethernet8/1:,Ethernet8/2:,Ethernet8/3:,Ethernet8/4:,Ethernet8/5:,Ethernet8/6:"

action 2.1 append iflist ",Ethernet8/7:,Ethernet8/8:,Ethernet8/9:,Ethernet8/10:,Ethernet8/11:,Ethernet8/12:"

action 2.2 append iflist ",Ethernet8/13:,Ethernet8/14:,Ethernet8/15:,Ethernet8/16:,Ethernet8/17:,Ethernet8/18:"

action 2.3 append iflist ",Ethernet8/19:,Ethernet8/20:,Ethernet8/21:,Ethernet8/22:,Ethernet8/23:,Ethernet8/24:"

action 2.4 append iflist ",Ethernet8/25:,Ethernet8/26:,Ethernet8/27:,Ethernet8/28:,Ethernet8/29:,Ethernet8/30:"

action 2.5 append iflist ",Ethernet8/31:,Ethernet8/32:,Ethernet8/33:,Ethernet8/34:,Ethernet8/35:,Ethernet8/36:"

action 2.6 append iflist ",Ethernet8/37:,Ethernet8/38:,Ethernet8/39:,Ethernet8/40:,Ethernet8/41:,Ethernet8/42:"

action 2.7 append iflist ",Ethernet8/43:,Ethernet8/44:,Ethernet8/45:,Ethernet8/46:,Ethernet8/47:,Ethernet8/48:"

action 2.8 append iflist ",Ethernet9/1:,Ethernet9/2:,Ethernet9/3:,Ethernet9/4:,Ethernet9/5:,Ethernet9/6:"

action 2.9 append iflist ",Ethernet9/7:,Ethernet9/8:,Ethernet9/9:,Ethernet9/10:,Ethernet9/11:,Ethernet9/12:"

action 3.0 append iflist ",Ethernet9/13:,Ethernet9/14:,Ethernet9/15:,Ethernet9/16:,Ethernet9/17:,Ethernet9/18:"

action 3.1 append iflist ",Ethernet9/19:,Ethernet9/20:,Ethernet9/21:,Ethernet9/22:,Ethernet9/23:,Ethernet9/24:"

action 3.2 append iflist ",Ethernet9/25:,Ethernet9/26:,Ethernet9/27:,Ethernet9/28:,Ethernet9/29:,Ethernet9/30:"

action 3.3 append iflist ",Ethernet9/31:,Ethernet9/32:,Ethernet9/33:,Ethernet9/34:,Ethernet9/35:,Ethernet9/36:"

action 3.4 append iflist ",Ethernet9/37:,Ethernet9/38:,Ethernet9/39:,Ethernet9/40:,Ethernet9/41:,Ethernet9/42:"

action 3.5 append iflist ",Ethernet9/43:,Ethernet9/44:,Ethernet9/45:,Ethernet9/46:,Ethernet9/47:,Ethernet9/48:"

action 4.0 foreach interface $iflist ,

action 5.0   cli command "show snmp mib ifmib ifindex | include $interface"

action 5.1   regexp "= ([0-9]+)" "$_cli_result" match ifindex

action 6.0   cli command "config t"

action 6.1   cli command "no rmon event $ifindex"

action 6.2   cli command "no rmon alarm $ifindex"

action 7.0   cli command "rmon event $ifindex log trap SIL description CCSRmon owner CCSAdmin"

action 7.1   cli command "rmon alarm $ifindex ifOperStatus.$ifindex 1 absolute rising-threshold 2 $ifindex falling-threshold 1 $ifindex owner NetworkAdmin"

action 7.2 mail server "192.168.1.146" to "engineer@cisco.com" from "devtest@cisco.com" subject "Interface Outage" body "$_ifOperStatus"

action 7.3   cli command "end"

action 8.0 end

Thanks,

Jay K.

Cisco Employee

Up/Down scripting for Serial interfaces.

This will not work on a Nexus switch.  The EEM on NX-OS is nothing like that of IOS.  The ability to send email and perform logic within EEM applets is missing.

1538
Views
10
Helpful
14
Replies
CreatePlease to create content