cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
6773
Views
5
Helpful
2
Comments
ashirkar
Level 7
Level 7

Introduction:

This document describe about configuring EEM Script for periodically clearing interface counters using regular expression.

Before moving to configuration I would like to describe some basic things use in the script:

 

1) Watchdog System detector: watchdog detector generates periodic timer events that allow EEM script to run at repeating time intervals.

 

2) "event tag event-tag timer watchdog time”: To specify the event criteria for an EEM applet that is run on the basis of time-specific events, use the event timer command in applet configuration mode.

 

3) "action info type interface-names" :Specifies the action of obtaining interface names when an EEM applet is triggered.

 

4) Specifying foreach Iterating Statements:

 

To specify a conditional statement that iterates over an input string using the delimiter as a tokenizing pattern, perform this task. The foreach iteration statement is used to iterate through a collection to get the desired information. The delimiter is a regular expression pattern string. The token found in each iteration is assigned to the given iterator variable. All arithmetic calculations are performed as long integers without any checks for overflow. In this task, the value of the variable x is set to 5. An iteration statement is set to run through the input string red, blue, green, orange. For every element in the input string, a corresponding message is displayed on the screen.use below command syntax to specify foreach statment under event manager.

"action label foreach [string-iterator] [string-input] [string-delimiter]"

 

5) Regular Expressions: Using regular expressions, you can specify the rules for a set of possible strings to be matched.

Command sytax:" action label regexp string-pattern string-input [string-match [string-submatch1] [string-submatch2] [string-submatch3]]"

 

Configuration Example:

On Router R1 ,I have serial as well as fastethernet ports but we are configuring script using regular expression in such way that it will only periodically clear fastethernet interfaces counter but serial interface counter remain unchanged.

 

R1 configuration:

hostname R4

ip cef

!

interface FastEthernet0/0

no ip address

shutdown

duplex half

!

interface FastEthernet1/0

ip address 10.1.1.1 255.255.255.0

duplex full

speed 100

!

interface FastEthernet1/1

no ip address

shutdown

duplex auto

speed auto

!

interface Serial2/0

ip address 20.1.1.1 255.255.255.0

serial restart-delay 0

!

 

Interface status before configuring EEM script:

 

R1#sh int fa1/0 | in packet

5 minute input rate 0 bits/sec, 0 packets/sec

5 minute output rate 0 bits/sec, 0 packets/sec

     115 packets input, 12922 bytes

     0 input packets with dribble condition detected

     116 packets output, 13281 bytes, 0 underruns

R1#sh int s2/0 | in packet

5 minute input rate 0 bits/sec, 0 packets/sec

5 minute output rate 0 bits/sec, 0 packets/sec

     444 packets input, 43836 bytes, 0 no buffer

     444 packets output, 43796 bytes, 0 underruns

 

Configuring EEM script on R1:

R1#conf t

Enter configuration commands, one per line. End with CNTL/Z.

R1(config)#event manager applet COUNTER_CLEAR

R1(config-applet)# event tag 1.0 timer watchdog time 300

R1(config-applet)# action 1.0 info type interface-names regexp "Fa|Se"

R1(config-applet)# action 1.1 foreach _iface "$_info_interface_names"

R1(config-applet)# action 1.2 regexp ".*(Serial).*" "$_iface"

R1(config-applet)# action 1.3 if $_regexp_result eq 1

R1(config-applet)# action 1.4 continue

R1(config-applet)# action 1.5 else

R1(config-applet)# action 1.6 cli command "enable"

R1(config-applet)# action 1.7 cli command "clear counters $_iface" pattern "confirm"

R1(config-applet)# action 1.8 cli command "y"

R1(config-applet)# action 1.9 end

R1(config-applet)# action 2.0 end

R1(config-applet)#end

 

Verification:

To verify applied script we are debugging as shown below:

R1#debug event manager action cli

Debug EEM action cli debugging is on

R1#ter le 0

R1#

*May 3 14:53:06.667: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : CTL : cli_open called.

*May 3 14:53:06.675: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : R1>

*May 3 14:53:06.679: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : IN : R1>enable

*May 3 14:53:06.695: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : R1#

*May 3 14:53:06.695: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : IN : R1#clear counters FastEthernet0/0

*May 3 14:53:06.711: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : Clear "show interface" counters on this interface [confirm]

*May 3 14:53:06.715: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : IN : y

*May 3 14:53:06.719: %CLEAR-5-COUNTERS: Clear counter on interface FastEthernet0/0 by on vty0 (EEM:COUNTER_CLEAR)

*May 3 14:53:06.731: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : y

*May 3 14:53:06.735: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : R1#

*May 3 14:53:06.735: %HA_EM-6-LOG: COU

R1#NTER_CLEAR : DEBUG(cli_lib) : : OUT : R1#

*May 3 14:53:06.739: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : IN : R1#enable

*May 3 14:53:06.759: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : R1#

*May 3 14:53:06.763: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : IN : R1#clear counters FastEthernet1/0

*May 3 14:53:06.783: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : Clear "show interface" counters on this interface [confirm]

*May 3 14:53:06.787: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : IN : y

*May 3 14:53:06.799: %CLEAR-5-COUNTERS: Clear counter on interface FastEthernet1/0 by on vty0 (EEM:COUNTER_CLEAR)

*May 3 14:53:06.811: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : y

*May 3 14:53:06.811: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : R1#

*May 3 14:53:06.819: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : IN : R1#enable

*May 3 14:53:06.839: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : R1#

*May

R1# 3 14:53:06.839: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : R1#

*May 3 14:53:06.843: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : IN : R1#clear counters FastEthernet1/1

*May 3 14:53:06.963: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : Clear "show interface" counters on this interface [confirm]

*May 3 14:53:06.967: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : IN : y

*May 3 14:53:06.979: %CLEAR-5-COUNTERS: Clear counter on interface FastEthernet1/1 by on vty0 (EEM:COUNTER_CLEAR)

*May 3 14:53:06.991: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : y

*May 3 14:53:06.991: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : OUT : R1#

*May 3 14:53:07.039: %HA_EM-6-LOG: COUNTER_CLEAR : DEBUG(cli_lib) : : CTL : cli_close called.

 

R1#sh int fa1/0 | in packet

5 minute input rate 0 bits/sec, 0 packets/sec

5 minute output rate 0 bits/sec, 0 packets/sec

     2 packets input, 2984 bytes

     0 input packets with dribble condition detected

     29 packets output, 2968 bytes, 0 underruns

R1#sh int s2/0 | in packet

5 minute input rate 0 bits/sec, 0 packets/sec

5 minute output rate 0 bits/sec, 0 packets/sec

     520 packets input, 49158 bytes, 0 no buffer

     520 packets output, 49074 bytes, 0 underruns

From the above output; script is only clearing fastethernet interface counter not for serial interfaces.

Related Information:

Cisco EEM Basic Overview and Sample Configurations

Cisco EEM Best Practices

Comments
sam wang
Level 1
Level 1

I tried to apply it on switch3750, My purpose is just want to clear Gigabit interface, do not clear TenGigabit interface, but it sounds my regexp is not right.   Could you please tell me how to do it ?   And my second question is what the meaning of "$_info_interface_names" ?   Thanks a lot for your kindly help!!

 

conf t
event manager applet COUNTER_CLEAR
event tag 1.0 timer watchdog time 25
action 1.0 info type interface-names regexp "GigabitEthernet|TenGigabitEthernet"
action 1.1 foreach _iface "$_info_interface_names"
action 1.2 regexp ".*(TenGigabitEthernet).*" "$_iface"
action 1.3 if @_regexp_result eq 1
action 1.4 continue
action 1.5 else
action 1.6 cli command "enable"
action 1.7 cli command "clear counters $_iface" pattern "confirm"
action 1.8 cli command "y"
action 1.9 end
action 2.0 end

 

Janos Potor
Community Member

Hy!

At action 1.3, there is a typo: @_regexp_result

To the second question,

action 1.0 info type interface-names regexp "GigabitEthernet|TenGigabitEthernet"

action 1.1 foreach _iface "$_info_interface_names"

 

Jano

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: