6.6 Construct an EEM applet that automates a task, a troubleshooting step or data collection
ENCOR 350-401 v1.2 · 6.0 Automation and Artificial Intelligence
Embedded Event Manager (EEM) lets IOS react to its own events: a syslog message, an interface counter, a CLI command, a timer, a tracked object. An applet pairs one event with a list of actions, such as running commands, sending a syslog message or an email. ENCOR expects you to build one for automation, troubleshooting or data collection.
What you must know
- Write an applet:
eventthen numberedactionlines. - Use common event detectors: syslog pattern, track, timer (cron, watchdog), CLI, interface counters, none (manual).
- Use actions:
cli command,syslog msg,mail,wait,puts, variables such as$_event_pub_time. - Verify and run applets, and avoid common mistakes (enable first, numbering order).
An applet that collects data
event manager applet OSPF-DOWN
event syslog pattern "%OSPF-5-ADJCHG.*FULL to DOWN"
action 1.0 cli command "enable"
action 2.0 cli command "show ip ospf neighbor | append flash:ospf-down.txt"
action 3.0 cli command "show logging | include OSPF | append flash:ospf-down.txt"
action 4.0 syslog msg "OSPF neighbor lost: data saved to flash:ospf-down.txt"Actions run in string order of their labels (1.0, 2.0, 10.0 sorts before 2.0, so use consistent numbering). cli command "enable" is needed first because applets start in user EXEC.
The adjacency drops, the applet captures the state to flash and announces it (1), so you have evidence even if the problem clears before anyone looks.
Other events
event manager applet NIGHTLY-BACKUP
event timer cron cron-entry "0 2 * * *"
action 1.0 cli command "enable"
action 2.0 cli command "copy running-config tftp://10.0.50.30/r1.cfg" pattern "Address"
action 3.0 cli command ""
!
event manager applet UPLINK-TRACK
event track 1 state down
action 1.0 syslog priority critical msg "Uplink probe failed"event none creates an applet you run by hand with event manager run NAME, a handy way to package a troubleshooting routine.
Commands
show event manager policy registered | Registered applets and their events. |
show event manager history events | When each applet ran. |
event manager run NAME | Runs an applet with event none. |
debug event manager action cli | Shows each CLI action and its output. |
Exam traps
- Applets start in user EXEC: add
cli command "enable"first. - Action labels sort as strings: 1.0, 10.0, 2.0. Number consistently.
- Interactive prompts need
patternand an answer action. - A syslog pattern is a regular expression.
Check yourself
- Which event detector reacts to a log message?
event syslog pattern "…".- Why does an applet's
show running-configfail? - The applet runs in user EXEC; it needs
cli command "enable"first. - How do you create an applet you trigger by hand?
- Use
event noneand run it withevent manager run <name>.
Labs
Try it live: Automate the router: RESTCONF, NETCONF, JSON and EEM