6.6 Construct an EEM applet to automate configuration, troubleshooting, or data collection
Aligned to Cisco's 350-401 ENCOR v1.2 exam topics.
On this page
What this objective tests
This is a construct objective. The exam asks you to build or complete a small EEM applet.
Embedded Event Manager (EEM) runs on the device. It watches for an event. Then it runs actions. No external server is necessary. This makes EEM useful for local reaction, data collection, and guardrails.
Applet anatomy
Every applet has two required parts:
- Event detector: the trigger. One per applet. Examples: syslog pattern, CLI pattern, timer, track state.
- Action: the work. One or more lines. Actions run in numeric order.
event manager applet NAME
event <detector> <trigger>
action 1.0 <work>
action 2.0 <work>Common event detectors:
| Detector | Example trigger | Use |
|---|---|---|
event syslog pattern | "LINEPROTO-5-UPDOWN.*down" | React to a log message |
event cli pattern | "write memory" sync no | React to a typed command |
event timer watchdog time 300 | every 300 seconds | Periodic collection |
event track 10 state down | tracked object down | React to reachability loss |
Warning: Applets that change configuration can cause loops or outages. Test in a lab first.
Example A: syslog-triggered interface recovery
This applet watches for a link-down message on GigabitEthernet1. It bounces the interface to recover it. Then it logs the result.
event manager applet RECOVER_GI1
event syslog pattern "LINK-3-UPDOWN.*GigabitEthernet1.*down"
action 1.0 syslog msg "EEM: Gi1 went down, starting recovery"
action 2.0 cli command "enable"
action 3.0 cli command "configure terminal"
action 4.0 cli command "interface GigabitEthernet1"
action 5.0 cli command "shutdown"
action 6.0 cli command "no shutdown"
action 7.0 cli command "end"
action 8.0 syslog msg "EEM: Gi1 recovery complete"Read each action line:
1.0writes a syslog message. This proves the applet fired.2.0enters privileged mode. CLI actions start in user mode.3.0enters global configuration mode.4.0selects the interface.5.0shuts the interface down.6.0brings the interface back up. The bounce clears many transient faults.7.0leaves configuration mode.8.0writes a closing syslog message.
Warning: The no shutdown at line 6.0 creates a new syslog message. Make sure your pattern does not match the messages your own applet creates. A self-matching applet loops forever.
Example B: CLI event applet for audit logging
This applet fires when an operator runs write memory. It logs who ran the command. The command still runs normally.
event manager applet AUDIT_WRITE_MEMORY
event cli pattern "write memory" sync no skip no
action 1.0 syslog msg "EEM: user $_cli_username ran write memory"Read each line:
event cli pattern "write memory"matches the typed command.sync nomeans EEM does not wait for the applet. The command runs without approval from the applet.skip nomeans EEM does not skip the command. The command executes normally.$_cli_usernameis an EEM variable. The CLI event detector fills it with the current username.
Change sync yes and the applet must approve the command with an action ... set exit status. That blocks the command until the applet finishes. Use sync no for logging-only applets.
Verification
Check registration first:
show event manager policy registeredExpected output:
No. Class Type Event Type Trap Time Registered Name
1 applet user syslog Off Mon Jul 20 09:14:03 RECOVER_GI1
pattern {LINK-3-UPDOWN.*GigabitEthernet1.*down} maxrun 20
2 applet user cli Off Mon Jul 20 09:15:41 AUDIT_WRITE_MEMORY
pattern {write memory} sync no skip no occurs 1Then prove the applet fired and completed:
| Proof | Command or evidence |
|---|---|
| Registered | show event manager policy registered |
| Triggered | show event manager history events |
| Completed | Matching syslog or config side effect |
Other useful checks:
show running-config | section event manager
show event manager history events
show logging | include EEMLab: build and fire the audit applet
Topology: one IOS XE router or switch. No traffic is necessary.
[Console] ---- [R1: IOS XE]Do these steps:
- Enter configuration mode:
configure terminal. - Create the applet
AUDIT_WRITE_MEMORYfrom Example B. - Exit configuration mode.
- Run
show event manager policy registered. Confirm the applet appears with event typecli. - Run
write memory. - Run
show logging | include EEM. Confirm the message shows your username. - Remove the applet:
no event manager applet AUDIT_WRITE_MEMORY.
Expected syslog line:
%HA_EM-6-LOG: AUDIT_WRITE_MEMORY: EEM: user admin ran write memoryRepeat the lab with Example A if you can shut down a lab interface safely. The shutdown command generates the LINK-3-UPDOWN message. The applet fires and bounces the interface.
Exam traps
- An applet without an event never fires. The event detector is mandatory.
- Actions run in numeric order.
action 1.0runs beforeaction 2.0. - CLI actions need
enablebefore privileged commands. sync nolets the command run freely.sync yesmakes the applet gate the command.- The syslog pattern must match the real message text. Check the exact mnemonic, such as
LINK-3-UPDOWNversusLINEPROTO-5-UPDOWN. - Do not match a syslog pattern that your own applet generates. That creates a loop.
Pass check
You are ready when you can do these things:
- Name the event detector and the actions in any applet.
- Build a syslog-triggered applet with three or more actions.
- Build a CLI event applet that logs the operator name.
- Explain
sync noandskip noin one sentence each. - Prove an applet works with
show event manager policy registeredand syslog evidence.
Sources used
- Cisco ENCOR 350-401 v1.2 exam topics: https://learningcontent.cisco.com/documents/marketing/exam-topics/350-401-ENCORE-v1.2.pdf
- Cisco IOS XE EEM CLI applet configuration guide: https://www.cisco.com/c/en/us/td/docs/routers/ios/config/17-x/syst-mgmt/b-system-management/m_eem-policy-cli.html
- Cisco EEM best practices and useful 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