
Cisco EEM Usage Options
In this article, I will look at several examples of using Cisco EEM (Embedded Event Manager) in conjunction with Cisco IP SLA and TCL scripts.
1. Host monitoring with email notification.
Not so long ago I had a situation when I needed to monitor backup Internet channels. There are a great many ways to do this, but I thought why should I deploy a separate server or install additional software when the Cisco router is responsible for all communication channels, it also does backups, so let Cisco do monitoring with an email notification.
The system will work using Cisco IP SLA and EEM technologies, which have already been written about on the hub.
So, run echo-requests to the Internet host, with a timeout of 500 ms and checking once an hour.
For convenience, we will declare several variables for EEM, where we set the address of the mail server and the addresses of the mailboxes. Let's create tasks for EEM what to do if there is no ping and in the opposite way. Why one moment. The email client built into EEM does not fully support RFC822. Emails are sent with an empty body. In order to fix the bug, you can manually insert the sending of the CRLF combination when generating the letter. 2. Automatic configuration backup. There are situations when, after a configuration change, Cisco is required to return to their previous settings. I understand that the correct situation is to have copies of the configurations before making changes, or carefully check the changes and only then save, but the situations are different. The EEM community will help us with this.
TCL scripts.
For example, take the Archive Config if Changes script . The script will compare the differences of the configurations, save the configuration in case of differences and send a syslog message.
First, declare the name of the archive file and the number of copies. Declare the file name for the EEM and copy the TCL script. Declare permissions to run and register the script. After registering the script, it will start working automatically. Script listing archive.tcl: Both options were run on the basis of Cisco IOS Software, 3800 Software (C3825-SPSERVICESK9-M), Version 12.4 (6) T. Next, I plan to figure out an alternative way to send email using TCL. When writing an article, materials from sites were used:
Cisco IOS Embedded Event Manager (EEM)
Embedded Event Manager (EEM) Scripting Community
1. Host monitoring with email notification.
Not so long ago I had a situation when I needed to monitor backup Internet channels. There are a great many ways to do this, but I thought why should I deploy a separate server or install additional software when the Cisco router is responsible for all communication channels, it also does backups, so let Cisco do monitoring with an email notification.
The system will work using Cisco IP SLA and EEM technologies, which have already been written about on the hub.
So, run echo-requests to the Internet host, with a timeout of 500 ms and checking once an hour.
ip sla 1
icmp-echo 212.158.166.234
timeout 500
frequency 3600
ip sla schedule 1 life forever start-time now
track 1 rtr 1 reachability
For convenience, we will declare several variables for EEM, where we set the address of the mail server and the addresses of the mailboxes. Let's create tasks for EEM what to do if there is no ping and in the opposite way. Why one moment. The email client built into EEM does not fully support RFC822. Emails are sent with an empty body. In order to fix the bug, you can manually insert the sending of the CRLF combination when generating the letter. 2. Automatic configuration backup. There are situations when, after a configuration change, Cisco is required to return to their previous settings. I understand that the correct situation is to have copies of the configurations before making changes, or carefully check the changes and only then save, but the situations are different. The EEM community will help us with this.
event manager environment _eserv 192.168.1.10
event manager environment _admin admin@localname.com
event manager environment _rep reports@localname.com
event manager applet host_is_down
event track 1 state down
action 1 mail server "$_eserv" to "$_admin" from "$_rep" subject "Habrahabr is not pinging"
event manager applet host_is_up
event track 1 state up
action 1 mail server "$_eserv" to "$_admin" from "$_rep" subject "Habrahabr is pinging now"
action 1 mail server "$_mail_smtp" to "$_mail_rcpt" from "$_info_routername@$_mail_domain" subject "Interface state change" body "\015\012$_syslog_msg"
TCL scripts.
For example, take the Archive Config if Changes script . The script will compare the differences of the configurations, save the configuration in case of differences and send a syslog message.
First, declare the name of the archive file and the number of copies. Declare the file name for the EEM and copy the TCL script. Declare permissions to run and register the script. After registering the script, it will start working automatically. Script listing archive.tcl: Both options were run on the basis of Cisco IOS Software, 3800 Software (C3825-SPSERVICESK9-M), Version 12.4 (6) T. Next, I plan to figure out an alternative way to send email using TCL. When writing an article, materials from sites were used:
Router(config)# archive
Router(config-archive)# path flash:archive_config
Router(config-archive)# maximum 5
Router(config)#event manager environment filename archive_config
Router#copy tftp flash
Address or name of remote host []? 192.168.1.2
Source filename []? archive.tcl
Destination filename [archive.tcl]?
Accessing tftp://192.168.1.2/archive.tcl...
Loading archive.tcl from 192.168.1.2 (via GigabitEthernet0/0): !
[OK - 1308 bytes]
1308 bytes copied in 0.156 secs (8385 bytes/sec)
Router(config)#event manager directory user policy flash:
Router(config)#event manager policy archive.tcl
::cisco::eem::event_register_syslog pattern ".*%SYS-5-CONFIG.*"
if {![info exists filename]} {
set result "Policy cannot be run variable filename has not been set."
error $result $errorInfo
}
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
if [catch {cli_open} result] {
puts stderr $result
exit 1
} else {
array set cli1 $result
}
if [catch {cli_exec $cli1(fd) "en"} result] {
puts stderr $result
exit 1
}
set showarchive [cli_exec $cli1(fd) "show archive"]
if { [regexp “Archive feature not enabled” $showarchive] } {
puts stderr $showarchive
exit 1
}
set lines [split $showarchive "\n"]
foreach line $lines {
set result [regexp {<- Most Recent} $line ]
if {$result != 0} {
set result1 [regexp {^\s+\d+\s+(.+)-(\d+)\s+<-} $line -> path extension]
set output [cli_exec $cli1(fd) "show archive config differences system:/running-config flash:$filename-$extension"]
if { [regexp "!No changes were found" $output] } {
break
} elseif { [regexp "Error: Could not open file" $output] } {
cli_exec $cli1(fd) "archive config"
break
}
else {
cli_exec $cli1(fd) "archive config"
break
}
}
}
Cisco IOS Embedded Event Manager (EEM)
Embedded Event Manager (EEM) Scripting Community