07-10-2020 02:24 AM
event evHi All,
My requirement is, i'm trying to ping the IP's one after another if the last ping fail then it has to disable and enable the port
Like
ping 8.8.8.8 so lo 0
(Wait for 5 secs)
ping 8.8.8.8 so lo 0
(If abouve ping fails then only below cmds should be executed or no action required)
confg t
int cell 1
shut
no shut
(and again execute the ping)
ping 8.8.8.8 so lo 0
(Wait for 5 secs)
ping 8.8.8.8 so lo 0
I tried with below configuration
event manager applet Interface_Down
event syslog pattern ".*%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0, changed state to down.*"
action 1.0 syslog priority alerts msg "Interface DOWN"
action 1.1 wait 5
action 2.0 syslog priority alerts msg "Creating interesting traffic to push on to the VPN"
action 2.1 cli command "enable "
action 2.2 cli command "ping 8.8.8.8 so lo 0"
action 2.3 wait 5
action 2.4 cli command "ping 8.8.8.8 so lo 0"
action 3.0 syslog priority alerts msg "Bouncing the Cell Interface"
action 3.1 cli command "enable "
action 3.2 cli command "config t"
action 3.3 cli command "int cell 1 "
action 3.4 cli command "shut "
action 3.5 cli command "no shut "
action 3.6 cli command "end "
action 4.0 syslog priority alerts msg "Turn on the VPN"
action 4.1 cli command "ping 8.8.8.8 so lo 0"
action 4.2 wait 20
action 4.3 cli command "ping 8.8.8.8 so lo 0"
action 4.4 syslog priority alerts msg "Exiting"
but after the 1st ping the CLI is getting closed. Below is the output
cisco#
Jul 10 09:20:28.277: %HA_EM-1-LOG: Interface_Down: Creating interesting traffic to push on to the VPN
Jul 10 09:20:28.277: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : CTL : cli_open called.
Jul 10 09:20:28.281: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : CCCCCC************************* WARNING **************************** ***
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT :
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : This system is intended for authorised users only.
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT :
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : Activities on this system may be monitored. Users of this system
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : represent that they have been properly authorised by the system
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : owners to access the system. The system owners may institute
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : proceedings seeking to recover damages for any unauthorised use or
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : access to the system. Unauthorised use or access may also attract
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : criminal sanctions under State and Commonwealth legislation.
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT :
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : *****************************************************************
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT :
Jul 10 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : cisco#
Jul 1
cisco#0 09:20:28.283: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : IN : cisco#enable
Jul 10 09:20:28.293: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : cisco#
Jul 10 09:20:28.293: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : IN : cisco#ping 8.8.8.8 so lo 0
cisco#
Jul 10 09:20:38.323: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : Type escape sequence to abort.
Jul 10 09:20:38.323: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : Sending 5, 100-byte ICMP Echos to 8.8.8.8, timeout is 2 seconds:
Jul 10 09:20:38.323: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : Packet sent with a source address of 10.201.218.254
Jul 10 09:20:38.323: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : .....
Jul 10 09:20:38.323: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : Success rate is 0 percent (0/5)
Jul 10 09:20:38.323: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : OUT : cisco#
cisco#
Jul 10 09:20:43.323: %HA_EM-6-LOG: Interface_Down : DEBUG(cli_lib) : : CTL : cli_close called.
Jul 10 09:20:43.323:
Jul 10 09:20:43.323: tty is now going through its death sequence
cisco#
07-10-2020 07:33 PM
You can try to store the results of the first ping and compare with the second ping before taking action :
some example ;
https://community.cisco.com/t5/routing/eem-or-tcl-ping-with-variable/td-p/3952772
07-13-2020 12:09 AM
How to fo the IF. Ping should happen only above ping responce failed
07-14-2020 11:05 AM
Line 3.1 in your policy is not needed since the its already in enable mode. EEM automatically times out after 20 seconds so you will need to change the maxrun timer for the script to run longer. Here is an example of using if statements to measure ping success/failure.
action 011 set destination "example.com"
action 140 set pingsuccess "0"
action 199 while $pingsuccess eq 0
action 260 cli command "ping $destination"
action 261 syslog msg "$_cli_result"
action 262 regexp "Unrecognized host or address, or protocol not running" "$_cli_result"
action 263 if $_regexp_result eq "1"
action 264 syslog msg "Unable to resolve $destination"
action 265 end
action 270 regexp "Success rate is 100 percent \([3-5]/5\)" "$_cli_result"
action 280 if $_regexp_result eq "1"
action 290 syslog msg "Successfully pinged $destination"
action 295 set pingsuccess "1"
action 300 break
action 310 end
action 350 syslog msg "Not able to reach $destination"
action 360 wait 10
action 400 end
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: