Technology
Writing EEM Scripts Using Variables for Networking Automation in Cisco EEM
How to Write EEM Scripts Using Variables for Networking Automation in Cisco EEM
This guide aims to help network engineers and administrators understand how to write effective EEM (Event Manager) scripts using variables for automation. EEM is a powerful feature in Cisco IOS that allows for automation of network tasks through script-based event management. Below, we will explore different methods for creating variables, including using show commands and syslog messages.
Introduction to Cisco EEM
Cisco EEM is a feature set enhancing Cisco IOS Network Operating System (IOS) that provides an event management framework. It allows for event-driven automation of tasks, enabling network devices to respond to events such as secure failures, configuration changes, and user-defined events. EEM facilitates the deployment of Cisco IOS script-based applications for network automation.
Method 1: Creating Variables from a show Command
One common method to create a variable is by using output from a show command. This method is useful when you need to pull specific information from interface status, configuration details, or other device outputs.
Example: Creating a Variable from a show Command
event manager applet TEST event none action 001 cli command "show ip int brief" action 002 regexp "(S ) is (S ) up (S )br"
Explanation:
event manager applet TEST: Defines the applet with the name "TEST." event none: No specific event is required to trigger the applet, but it will run on device startup. action 001 cli command "show ip int brief": Runs the show ip int brief command to get interface details. action 002 regexp "(S ) is (S ) up (S )“: Uses a regular expression (regexp) to match the output pattern for specific interface information. This regex will capture the interface name, status, and operational mode.The most critical part is the use of _cli_result to reference the matched output. Without it, the applet won't know where to look for the pattern.
Method 2: Creating Variables from a Syslog Message
Another approach is to create variables based on syslog messages. This method is useful when you want to create an applet in response to specific logged events, such as interface failures or configuration changes.
Example: Creating a Variable from a Syslog Message
event manager applet TEST event syslog pattern "Interface (d ) is down" action 1.0 regexp "Interface (d ) is down"
Explanation:
event manager applet TEST: Defines the applet with the name "TEST." event syslog pattern "Interface (d ) is down": Creates an applet that triggers from a syslog message indicating an interface has failed. action 1.0 regexp "Interface (d ) is down": Uses a regular expression to match the specific syslog message pattern. Here, the _syslog_msg syntax is used to denote the pattern should be from a syslog message.By using a regular expression, you can define the exact syslog message you are looking for and capture the relevant information for your applet.
Conclusion
Understanding how to create and use variables in Cisco EEM scripts is crucial for effective network automation. Whether you are pulling information from a show command or a syslog message, the key is to identify the required pattern using regular expressions and reference the appropriate syntax. These examples provide a starting point for creating dynamic and responsive network management solutions.
For further exploration and advanced usage, refer to the Cisco documentation or consult with a network engineering expert.