📜 ⬆️ ⬇️

Cisco EEM Uses

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 it became necessary for me to monitor backup Internet channels. There are a lot of 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 deals with redundancy, so let Cisco do monitoring and e-mail notification.

The system will work using Cisco IP SLA and EEM technologies, which have already been written about.
')
So, let's run echo requests on the Internet host, with a timeout of 500 ms and check 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 will set the address of the mail server and the addresses of mailboxes.

event manager environment _eserv 192.168.1.10
event manager environment _admin admin@localname.com
event manager environment _rep reports@localname.com


Let's create tasks for the EEM, what to do if there is no ping and in the opposite version.

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"


Why one moment. The mail client built into the EEM does not fully support RFC822. Letters are sent with an empty body. In order to eliminate the bug, you can manually insert the sending of the CRLF combination when generating a letter.

action 1 mail server "$_mail_smtp" to "$_mail_rcpt" from "$_info_routername@$_mail_domain" subject "Interface state change" body "\015\012$_syslog_msg"

2. Automatic configuration backup.

There are situations when, after a configuration change, Cisco will need to return to the previous settings. I understand that the correct situation is to have a copy of the configurations before starting the changes, or carefully check the changes and then save, but the situations are different. This will help us community EEM TCL scripts.

For example, take the Archive Config if Changes script. The script will compare configuration differences, save the configuration in case of differences, and send a syslog message.

To begin, let us announce the name of the backup file and the number of copies.

Router(config)# archive
Router(config-archive)# path flash:archive_config
Router(config-archive)# maximum 5


Declare the file name for the EEM and copy the TCL script.

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)


We declare launch permissions and register the script.

Router(config)#event manager directory user policy flash:
Router(config)#event manager policy archive.tcl


After registering the script, it will start working automatically.

Listing of archive.tcl script:
::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
}
}
}


Both versions were launched based on Cisco IOS Software, 3800 Software (C3825-SPSERVICESK9-M), Version 12.4 (6) T.

Next, I plan to deal with an alternative way to send email using TCL.

When writing the article materials from the sites were used:
Cisco IOS Embedded Event Manager (EEM)
Embedded Event Manager (EEM) Scripting Community

Source: https://habr.com/ru/post/91879/


All Articles