Cisco eem script

eem details and how to do it on a switch or router. The best part? You can have the script send an email on the details, using

R1(config-applet)#action 4.0 mail server “11.0.0.2” to “info@auda.com” from ” eem@cisco.com” subject “kokowawa” body “current users $_cli_result”

example one :

Lets create manually triggerd applet , once we run it will trun router interface up and give it ip address .

R1#config terminal

R1(config)#event manager applet set_ip

(this commands create EEM applet with name set_ip )

R1(config-applet)#event none sync yes

(event none mean this eem applet is to be manual trigger

sync yes mean run the commands synchronously which mean run each command and wait tell it execute then run the nest one.)

now we start typing our Actions which will be like this

1.0 is just number of actions and better to use gaps between numbers so maybe you return back to add another missing action

cli mean we will use cli to type a command , this command will be typed on your behalf .

command “enable” is your command

R1(config-applet)#action 1 cli command “enable”

R1(config-applet)#action 2 cli command “config t”

R1(config-applet)#action 3 cli command “interface fa0/0”

R1(config-applet)#action 4 cli command “ip add 10.1.1.1 255.255.255.0”

R1(config-applet)#action 5 cli command “no sh”

R1(config-applet)#action 6 cli command “end”

R1(config-applet)#exit

finally once you want to run this EEM Applet , just type the following command :

R1#event manager run set_ip

you can run R1#show event manager policy available , to see the eems in your router.

Branch Code Paths with if/else

EEM variables can be used to control the execution flow of EEM scripts. Consider this EEM script:

event manager applet snmp_cpu authorization bypass
event timer watchdog time 60
action 0010 info type snmp oid 1.3.6.1.4.1.9.9.109.1.1.1.1.3.1 get-type exact
action 0020 if $_info_snmp_value ge "50"
action 0030 syslog msg "This syslog message will be sent if CPU utilization is above 50%"
action 0040 elseif $_info_snmp_value ge "30"
action 0050 syslog msg "This syslog message will be sent if CPU utilization is above 30% and below 50%"
action 0060 else
action 0070 syslog msg "This syslog message will only be sent if CPU utilization is below 30%"
action 0080 end

This script will run every minute, examine the value of the SNMP OID for CPU utilization, and then enter one of three different execution paths based on the value of the OID. Similar statements can be used on any other legal EEM variable to build complex execution flows in EEM scripts.

Here is the summary of commands, this is for a simple script that enables an interface and adds an ip address. Automagic!

So to learn eem, I suggest read eem-by-examples. Link below. This shows some details on how to create the script. Two web pages. First is this one on learning network:

https://learningnetwork.cisco.com/s/article/understanding-cisco-eem-by-examples-part-1

Then read article for some more examples of scripts.

https://www.cisco.com/c/en/us/support/docs/ios-nx-os-software/ios-xe-16/216091-best-practices-and-useful-scripts-for-ee.html

After that, do some labs on your equipment. And then you are master of EEM.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s