action (EEM)
To match a regular expression pattern on an input string, to specify the action of writing a message to syslog, and to specify the action of reloading the Cisco IOS software when an Embedded Event Manager (EEM) applet is triggered, use the action command in applet configuration mode. To disable this function, use the no form of this command.
action label { regexp string-submatch | | reload | | syslog msg msg-text | | wait wait-interval | else | break | continue | elseif | while | set | increment | handle-error | gets | foreach | divide | decrement | counter | append }
no action label
Syntax Description
label |
Unique identifier that can be any string value. Actions are sorted and run in ascending alphanumeric key sequence using the label as the sort key. If the string contains embedded blanks, enclose it in double quotation marks. |
||
string-submatch |
(Optional) The variable name to store any submatches that are present. A maximum of three submatch strings can be specified. |
||
msg |
Specifies the message to be logged. |
||
msg-text |
Character text, an environment variable, or a combination of the two. If the string contains embedded blanks, enclose it in double quotation marks.
|
||
wait-interval |
The wait interval range is from 1 to 31536000. |
||
else |
Identifies the else conditional action block. If a statement is not associated with this applet, events are still triggered without any action or result. |
||
break |
Causes an immediate exit from a loop of actions. Skips all the actions down to the related end action. |
||
continue |
Causes the loop to continue with the next iteration. |
||
elseif |
Identifies the beginning of an elseif conditional action block when an EEM applet is triggered. |
||
while |
Identifies the while conditional action block when an EEM applet is triggered. |
||
set |
Sets the value of a variable when an EEM applet is triggered. |
||
increment |
Increments the value of the variable with the long integer specified. |
||
handle-error |
Specifies the error. |
||
gets |
Specifies an input from the local tty in a synchronous applet and stores the value in the given variable when an EEM applet is triggered |
||
foreach |
Specifies the iteration of an input string using the delimiter as a tokenizing pattern. |
||
divide |
Specifies the dividend value by the given divisor value when an EEM applet is triggered. |
||
decrement |
Decrements the value of the variable with the integer specified. |
||
counter |
Specifies the counter to be set or modified. |
||
append |
Appends the given string value to the current value of the variable specified. |
Command Default
No messages are written to syslog.
No reload of the Cisco IOS software is performed.
No regular expression patterns are matched.
Command Modes
Applet configuration (config-applet)
Command History
Release |
Modifications |
---|---|
Cisco IOS XE Catalyst SD-WAN Release 17.7.1a |
This command was introduced. |
Cisco IOS XE Catalyst SD-WAN Release 17.14.1a |
The EEM configurations such as else, break, continue, elseif, while, set, increment, handle-error, gets, foreach, divide, decrement, counter, and append are supported. |
Usage Guidelines
For usage guidelines, see the Cisco IOS XE action (EEM) commands.
Use the action else command to identify the else conditional action block. If a statement is not associated with this applet, events are still triggered without any action or result. A warning message stating that no statements are associated with this applet is displayed at the exit time of the configuration.
The following example shows how to specify a message to be sent to syslog when the memory-fail applet is triggered:
Device(config)# event manager applet memory-fail
Device(config-applet)# event snmp oid 1.3.6.1.4.1.9.9.48.1.1.1.6.1 get-type exact entry-op lt entry-val 5120000 poll-interval 10
Device(config-applet)# action 4.0 syslog msg "Memory exhausted; current available memory is $_snmp_oid_val bytes"
The following example shows how to reload the Cisco IOS software when the memory-fail applet is triggered:
Device(config)# event manager applet memory-fail
Device(config-applet)# event snmp oid 1.3.6.1.4.1.9.9.48.1.1.1.6.1 get-type exact entry-op lt entry-val 5120000 poll-interval 10
Device(config-applet)# action 3.0 reload
The following example shows how to define a regular expression match:
Device(config-applet)# event manager applet regexp
Device(config-applet)# event none
Device(config-applet)# action 1 regexp "(.*) (.*) (.*)" "one two three" _match _sub1
The following example shows how to configure an EEM applet to break from a loop of actions:
Device(config)# event manager applet loop
Device(config-applet)# event none
Device(config-applet)# action 1 while 1 eq 1
Device(config-applet)# action 2 break
Device(config-applet)# action 3 end
The following example shows how to configure an EEM applet to continue from a loop of actions:
Device(config)# event manager applet loop
Device(config-applet)# event none
Device(config-applet)# action 2 continue
Device(config-applet)# action 3 end
The following example shows how to identify the beginning of an else action block:
Device(config)# event manager applet loop
Device(config-applet)# event none
Device(config-applet)# action label2 else
Device(config-applet)# action 3 end
The following example shows how to identify the beginning of the elseif conditional action block.
Device(config)# event manager applet action
Device(config-applet)# event none
Device(config-applet)# action 1.0 set x "5"
Device(config-applet)# action 2.0 if $x lt 3
Device(config-applet)# action 3.0 puts "$x is less than 3"
Device(config-applet)# action 4.0 elseif $x lt 10
Device(config-applet)# action 5.0 puts "$x is less than 10"
Device(config-applet)# action 6.0 end
Device(config)# event manager run action 5 is less than 10