rekrowteN | Networker

All you want to know about computer networks and more

Cisco EEM – Do the Change While You Sleep

In this post, I was presenting macro on Cisco IOS device, where I was moving VLAN interface for management. I done it without locking myself. EEM (Embedded Event Manager) is another way on how to do it. But this can do even more. It can also be used as the commit at command on JUNOS, which was described in this post.

EEM is much much more than that and is composed of several components as server, publisher and subscriber. In this post, I will do unscheduled and scheduled change on LAN interface on the device. BTW, EEM is not supported on all devices and in all IOS versions. I will not describe EEM in details, it can be found pretty easily on the web.

First step is to create policy, which is composed of actions. Actually, first thing should be an event. And before that, it is the name of the applet. So first example will be unscheduled change. Applet is called CHANGE_INT, which stands for change interface. There will be no event, so there is no trigger for this small script. Actions are as following:

event manager applet CHANGE_INT
 event none
 action 0 cli command "enable"
 action 1 cli command "conf t"
 action 2 cli command "int f1/0"
 action 3 cli command "sh"
 action 4 cli command "int f1/1"
 action 5 cli command "ip add 192.168.0.1 255.255.255.0"
 action 6 cli command "no sh"

And that’s it. We are done. Just to run it by

event manager run CHANGE_INT

What will happen here? Interface F1/0 has IP address 192.168.0.1/24, which will be moved to interface F1/1 and F1/0 will be shut down. Here is output before change.

R1#sh ip int br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES unset  administratively down down    
FastEthernet1/0            192.168.0.1     YES manual up                    up      
FastEthernet1/1            unassigned      YES unset  administratively down down

Now I will run it. I am on the console and have terminal monitor turned on, so you can see progress of my script:

R1#event manager run CHANGE_INT
R1#
*Jan  9 23:26:45.703: %SYS-5-CONFIG_I: Configured from console by vty0
*Jan  9 23:26:47.339: %LINK-5-CHANGED: Interface FastEthernet1/0, changed state to administratively down
*Jan  9 23:26:47.631: %LINK-3-UPDOWN: Interface FastEthernet1/1, changed state to up
*Jan  9 23:26:48.339: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to down
*Jan  9 23:26:48.631: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/1, changed state to up

And finally, I will check it.

R1#sh ip int brie
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES unset  administratively down down    
FastEthernet1/0            192.168.0.1     YES manual administratively down down    
FastEthernet1/1            192.168.0.1     YES manual up                    up

Do It While You Sleep

I love commit at function in JUNOS and this can be the same. I will revert to the previous state and do exactly the same. But now, it will be scheduled. Event statement will be changed and set for Cron.

event manager applet CHANGE_INT
 event timer cron cron-entry "35 23 9 1 1"
 action 0 cli command "enable"
 action 1 cli command "conf t"
 action 2 cli command "int f1/0"
 action 3 cli command "sh"
 action 4 cli command "int f1/1"
 action 5 cli command "ip add 192.168.0.1 255.255.255.0"
 action 6 cli command "no sh"

I need probably explain that event statement. I am setting timer, which will trigger set of actions when time on the device is matching time in the event statement. This applet is put into Cron, so we are sure that it will be triggered at the exact specific time. String is in this format. It is composed of 5 values separated by a space. Values are:

  • minutes
  • hours
  • day
  • month
  • day of week (0-6, 0 is Sunday)

You can replace value by an asterisk, which is matching everything. All asterisks mean, run the applet every minute. Asterisk on the hour place means, run the script every hour, etc. Some handy tricks are here.

And how does it look like on console? Let’s see:

R1#sh ip int br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES unset  administratively down down    
FastEthernet1/0            192.168.0.1     YES manual up                    up      
FastEthernet1/1            unassigned      YES unset  administratively down down    
R1#sh clock
*23:34:31.563 UTC Mon Jan 9 2012
R1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#event manager applet CHANGE_INT
R1(config-applet)# event timer cron cron-entry "35 23 9 1 1"
R1(config-applet)# action 0 cli command "enable"
R1(config-applet)# action 1 cli command "conf t"
R1(config-applet)# action 2 cli command "int f1/0"
R1(config-applet)# action 3 cli command "sh"
R1(config-applet)# action 4 cli command "int f1/1"
R1(config-applet)# action 5 cli command "ip add 192.168.0.1 255.255.255.0"
R1(config-applet)# action 6 cli command "no sh"
R1(config-applet)#^Z
R1#sh clock
*Jan  9 23:34:51.639: %SYS-5-CONFIG_I: Configured from console by console
*23:34:53.211 UTC Mon Jan 9 2012
R1#
*Jan  9 23:35:00.467: %SYS-5-CONFIG_I: Configured from console by vty0
*Jan  9 23:35:02.099: %LINK-5-CHANGED: Interface FastEthernet1/0, changed state to administratively down
*Jan  9 23:35:02.395: %LINK-3-UPDOWN: Interface FastEthernet1/1, changed state to up
*Jan  9 23:35:03.099: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to down
*Jan  9 23:35:03.395: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/1, changed state to up
R1#sh ip int brie
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES unset  administratively down down
FastEthernet1/0            192.168.0.1     YES manual administratively down down
FastEthernet1/1            192.168.0.1     YES manual up                    up
R1#

What just happened? I have copy pasted config, waited couple of seconds and change was done automatically.

Practical usage? You have big config changes that need to be done on a lot of devices and it will disrupt your network. You can synchronize time on these devices, prepare change, load it to devices and schedule it on the same time. This will decrease outage to the minimum.

About these ads

4 responses to “Cisco EEM – Do the Change While You Sleep

  1. Pingback: Change Management IP Without Macro Or EEM « rekrowteN | Networker

  2. Pingback: Change WAN IP Without Macro Or EEM « rekrowteN | Networker

  3. Pingback: It’s April Fools! Slow Down Console | rekrowteN | Networker

  4. Pingback: It’s April Fools! Practical Jokes | rekrowteN | Networker

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: