cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2691
Views
10
Helpful
7
Replies

Cisco EEM script for 4G interface monitoring

Gordel2306
Level 1
Level 1

Hello,

I have CISCO1941/K9 routers which are running version Version 15.7(3)M6 & only have a 4g cellular interface as a WAN link. The signal or link drops ever so often & doesn't connect unless a shut/no shut is done on the cell interface. When it drops the interface shows up/up but loses it's IP address so I have created the following EEM script. The issue I have found is that when it does lose the IP address it kicks in but doesn't seem to actually shut/ no shut the interface, it only comes good when we manually do this.

+++++++++++++++++

event manager applet Cell_IP_CHECK authorization bypass
event timer cron name Cell_IP_CHECK cron-entry "*/6 * * * *"
action 1.0 cli command "enable"
action 2.0 cli command "show interface Cellular0/0/0 | inc address"
action 2.1 string match "*Internet address is 10.0.*" "$_cli_result"
action 3.0 if $_string_result eq "1" goto 5.0
action 4.0 cli command "enable"
action 4.1 cli command "configure terminal"
action 4.2 cli command "int Cellular0/0/0"
action 4.3 cli command "shut"
action 4.4 wait 1
action 4.5 cli command "no shut"
action 4.6 cli command "end"
action 5.0 cli command "exit"
!
end

++++++++++++++++++++++++

Here's the log output when when cell was down, it seemed to go into config t mode but only came up in the end when we consoled in & did the shut/ no shut.

Appreciate any feedback on the script

*Sep 29 09:12:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 09:18:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 09:24:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 09:30:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 09:36:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 09:42:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 09:48:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 09:54:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 10:00:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 10:06:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 10:12:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 10:18:01.125 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 10:24:01.129 EST: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM:Cell_IP_CHECK)
*Sep 29 10:25:08.621 EST: %LINK-5-CHANGED: Interface Cellular0/0/0, changed state to administratively down
*Sep 29 10:25:48.641 EST: %LINK-3-UPDOWN: Interface Cellular0/0/0, changed state to down
*Sep 29 10:26:04.161 EST: %SYS-5-CONFIG_I: Configured from console by User0 on console
*Sep 29 10:26:08.665 EST: %CELLWAN-2-BEARER_UP: Instance id=0, Default bearer (bearer_id=5) in Cellular0/0/0 is now UP
*Sep 29 10:26:10.769 EST: %LINK-3-UPDOWN: Interface Cellular0/0/0, changed state to up
*Sep 29 10:26:11.769 EST: %LINEPROTO-5-UPDOWN: Line protocol on Interface Cellular0/0/0, changed state to up
*Sep 29 10:26:47.833 EST: %BGP-5-ADJCHANGE: neighbor 10.0.2.2 Up

 

 

 

7 Replies 7

Hello,

 

try and simplify the entire operation by using an IP SLA and an EEM script. This would look like below:

 

track 1 ip sla 1 reachability

!

ip route 8.8.8.8 255.255.255.255 Cellular0/0/0
!
ip sla 1
icmp-echo 8.8.8.8 source-interface Cellular0/0/0
threshold 1000
timeout 1000
frequency 1
!
ip sla schedule 1 life forever start-time now
!
event manager applet CELL_SHUT_NO_SHUT
event track 1 state down
action 1.0 cli command "enable"
action 2.0 cli command "conf t"
action 3.0 cli command "interface Cellular0/0/0"
action 4.0 cli command "shut"
action 5.0 cli command "no shut"
action 6.0 cli command "end"

Thanks Georg , However I found that the IP Base software does not support ip sla feature.

It needs the Security or Data License to use this feature. So I'm stuck with the EEM feature.

Hello,

 

what is the actual log showing when the Cellular interface loses connectivity ?

Hi Georg , Unfortunately I can't see the actual log prior to this as it was rebooted, but basically the 4G tower disconnects from the device & the cellular interface loses it's IP address showing "Internet address will be negotiated using IPCP".

That's why I put in the EEM to 'shut/No shut' the cellular interface which it doesn't show "*Internet address is 10.0.*"  Thxs

Hello,

 

you can use the below workaround and use EEM to send a ping every 10 seconds. If that ping fails, another EEM script runs and ecexutes a shut/no shut of the interface. You need to turn on icmp debugging for this to work. In order for the successful pings not cluttering your log and console, use a logging discriminator:

 

debug ip icmp
!
event manager applet PING
event timer countdown time 10 maxrun 31536000
action 1.0 cli command "enable"
action 2.0 cli command "ping 8.8.8.8 source Cellular 0/0/0"
action 3.0 cli command "end"
!
event manager applet PING
event syslog pattern "time exceeded rcvd"
action 1.0 cli command "enable"
action 2.0 cli command "interface Cellular 0/0/0"
action 3.0 cli command "shut"
action 4.0 cli command "no shut"
action 5.0 cli command "end"
!
logging discriminator ICMP msg-body drops echo reply rcvd
logging buffered discriminator ICMP
logging console discriminator ICMP
logging monitor discriminator ICMP

Dan Frey
Cisco Employee
Cisco Employee

Change the string commands to regexp.  Here is an example using a loopback interface.

event manager applet Cell_IP_CHECK authorization bypass

event none

action 1.0 cli command "enable"

action 2.0 cli command "show interface Loopback2 | inc address"

action 2.1 regexp "Internet address is ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" "$_cli_result" match cellIp

action 3.0 if $_regexp_result eq "0"

action 3.1  syslog msg "No IP present on loopback2"

action 4.0  cli command "enable"

action 4.1  cli command "configure terminal"

action 4.2  cli command "int loopback2"

action 4.3  cli command "shut"

action 4.4  wait 1

action 4.5  cli command "no shut"

action 4.6 else

action 4.7  syslog msg "Loopback2 has IP $cellIp"

action 4.8 end

C1111#event manager run Cell_IP_CHECK

 

Oct  3 17:55:42.808: %HA_EM-6-LOG: Cell_IP_CHECK: No IP present on loopback2

C1111#

C1111#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

C1111(config)#int loopback2

C1111(config-if)#ip add 2.2.2.2 255.255.255.255

C1111(config-if)#end

C1111#event manager run Cell_IP_CHECK

C1111#

Oct  3 17:56:12.292: %HA_EM-6-LOG: Cell_IP_CHECK: Loopback2 has IP 2.2.2.2

C1111#

Gordel2306
Level 1
Level 1

Thanks Daniel Frey, I'm hoping to get a test unit shortly so will give this a try also .. Cheers