cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4019
Views
0
Helpful
8
Replies

EEM to Shut and No Shut Interface

andrewfkay
Level 1
Level 1

Hi,

I have confiugred EEM to track an IP SLA and shut interface Fa0 if it fails.  Then, at 23:00 each day (least disruptive to user traffic) open the Fa0 interface again.  I've got this part working fine except I want it to shut the interface down again if the interface remains down once it has been reopened.

At the moment, I don't think it's working because the track doesn't change state from up to down and therefore stays down.  Any ideas how to get this working (I'm new to EEM).

Thanks

Andrew

Config:

track 100 rtr 99 reachability

delay down 5 up 5

!

!

ip sla 99

icmp-echo 10.51.145.3 source-interface fa0

frequency 10

ip sla schedule 99 life forever start-time now

!

!

event manager applet SHUT_FA0

event track 100 state down

action 0 cli command "enable"

action 1 cli command "conf t"

action 2 cli command "interface fa0"

action 3 cli command "shut"

action 4 cli command "end"

!

event manager applet NO_SHUT_FA0

event timer cron cron-entry "00 23 * * 0-6"

action 0 cli command "enable"

action 1 cli command "conf t"

action 2 cli command "interface fa0"

action 3 cli command "no shut"

action 4 cli command "end"

!

8 Replies 8

andrewfkay
Level 1
Level 1

Ok, I've got a bit further with the below config but it seems to end at the 'wait 60' and not go any further.  Any ideas?

!

event manager applet SHUT_FA0

event track 100 state down

action 0.0 cli command "enable"

action 1.0 cli command "conf t"

action 2.0 cli command "interface fa0"

action 3.0 cli command "shut"

action 4.0 cli command "end"

!

event manager applet NO_SHUT_FA0

event timer cron cron-entry "20 14 * * 0-6"

action 0.0 cli command "enable"

action 1.0 cli command "conf t"

action 2.0 cli command "interface fa0"

action 3.0 cli command "no shut"

action 4.0 cli command "end"

action 4.5 wait 60

action 5.0 track read 100

action 5.5 if $_track_state eq down

action 6.0  cli command "enable"

action 6.5  cli command "conf t"

action 7.0  cli command "interface fa0"

action 7.5  cli command "shut"

action 8.0 end

!

The applet will stop executing after 20 seconds.  Adding a wait like this is not recommended (though you can make it work).  You could add a nested applet to do the countdown:

event manager environment q "

!

action 4.0 cli command "event manager applet RE_SHUT_FA0"

action 4.1 cli command "event timer countdown time 60"

action 4.2 cli command "action 1.0 if $_track_state eq down"

action 4.3 cli command "action 1.1 cli command enable"

action 4.4 cli command "action 1.2 cli command $q config t$q"

action 4.5 cli command "action 1.3 cli command $q interface fa0$q"

action 4.6 cli command "action 1.4 cli command shut"

action 4.7 cli command "action 1.5 cli command $q no event manager applet RE_SHUT_FA0$q"

action 4.8 cli command "action 1.6 end"

action 4.9 cli command "end"

That's great.  I'll give it a try.  Could you explain the '$q'?

This allows you to embed a quote in the nested applet.

Ok, my config now looks like this and I'm getting the following error message:

event manager environment q "

event manager applet SHUT_FA0

event timer countdown time 60

action 0.0 cli command "enable"

action 1.0 cli command "conf t"

action 2.0 cli command "interface fa0"

action 3.0 cli command "shut"

action 4.0 cli command "end"

event manager applet NO_SHUT_FA0

event timer cron cron-entry "37 15 * * 0-6"

action 0.0 cli command "enable"

action 1.0 cli command "conf t"

action 2.0 cli command "interface fa0"

action 3.0 cli command "no shut"

action 4.0 cli command "event manager applet RE_SHUT_FA0"

action 4.1 cli command "event timer countdown time 60"

action 4.2 cli command "action 1.0 if $_track_state eq down"

action 4.3 cli command "action 1.1 cli command enable"

action 4.4 cli command "action 1.2 cli command $q config t$q"

action 4.5 cli command "action 1.3 cli command $q interface fa0$q"

action 4.6 cli command "action 1.4 cli command shut"

action 4.7 cli command "action 1.5 cli command $q no event manager applet RE_SHUT_FA0$q"

action 4.8 cli command "action 1.6 end"

action 4.9 cli command "end"

event manager applet RE_SHUT_FA0

event timer countdown time 60

!

Jul 12 14:37:00.108: %HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: _track_state

Jul 12 14:37:00.108: %HA_EM-3-FMPD_ERROR: Error executing applet NO_SHUT_FA0 statement 4.2

Jul 12 14:37:00.108: %HA_EM-4-FMPD_NO_ACTION: No action configured for applet RE_SHUT_FA0

Any ideas?

Sorry, try changing action 4.2 to:

action 4.2 cli command "action 1.0 if \$_track_state eq down"

Hi Joseph,

I have made the change but I'm still having problems.  I get the following message:

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

Also, it creates the applet RE_SHUT_FA0 but I would expect it to be removed after applet has run.  It remains in the running config.

Please add explanation of any changes as I'm an EEM beginner and I'd like to understand the config.

Thanks

Andrew

Do this:

action 4.2 cli command "action 1.0 if \134044_track_state eq down"

The reason for this is that you have to escape the '$'.  It's tricky to do.  You need to use the octal escape sequence of \134 to get the '\\'.  Then when the parent applet runs, it will configure \044, which will turn into '$' by the parser.

The applet should be removed once you fix this error (assuming everything is typed correctly).

Getting Started

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:

Innovations in Cisco Full Stack Observability - A new webinar from Cisco