cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3225
Views
0
Helpful
3
Replies

EEM Help (Single Applet, Multiple Events, Different Actions)

Jason Kopacko
Level 4
Level 4

I am trying to create an EEM script that has multiple event triggers that has a different set of actions based on the event that triggered the applet. I have included an applet I use for CPU alerts. I would like to have event #1 generate the syslog messages and event #2 output the results to the vty (since it would have been manually run).

!
event manager applet CPU authorization bypass
event tag E1 syslog pattern "CPURISING" occurs 1
event tag E2 none

trigger
correlate event E1 or event E2
exit

action 1.00 info type routername

action 2.00 comment "#### CLI Command ####"
action 2.01 cli command "enable"
action 2.02 cli command "show processes cpu sorted 5sec | e 0.00"

action 3.00 comment "#### Set Variables ####"
action 3.01 set cpuline "0"
action 3.02 set cpulines "0"
action 3.03 set pidline "0"
action 3.04 set pidlines "0"

action 3.30 set cpuline3 "0"
action 3.31 set cpuline3_pid "0"
action 3.35 set cpuline3_name "0"

action 3.40 set cpuline4 "0"
action 3.41 set cpuline4_pid "0"
action 3.45 set cpuline4_name "0"

action 3.50 set cpuline5 "0"
action 3.51 set cpuline5_pid "0"
action 3.55 set cpuline5_name "0"

action 4.00 comment "#### Process CLI Results ####"
action 4.01 foreach cpuline "$_cli_result" "\n"

action 4.30 if $cpulines eq "3"
action 4.31 regexp " ([0-9]+) " "$cpuline" cpuline3 cpuline3_pid
action 4.39 end

action 4.40 if $cpulines eq "4"
action 4.41 regexp " ([0-9]+) " "$cpuline" cpuline4 cpuline4_pid
action 4.49 end

action 4.50 if $cpulines eq "5"
action 4.51 regexp " ([0-9]+) " "$cpuline" cpuline5 cpuline5_pid
action 4.59 end

action 5.30 comment "#### CLI Command ####"
action 5.31 if $cpulines eq "3"
action 5.32 cli command "show proc $cpuline3_pid"
action 5.33 regexp " \[([a-zA-Z a-zA-Z]+)\]" "$_cli_result" cpuline3_name
action 5.39 end

action 5.40 comment "#### CLI Command ####"
action 5.41 if $cpulines eq "4"
action 5.42 cli command "show proc $cpuline4_pid"
action 5.43 regexp " \[([a-zA-Z a-zA-Z]+)\]" "$_cli_result" cpuline4_name
action 5.49 end

action 5.50 comment "#### CLI Command ####"
action 5.51 if $cpulines eq "5"
action 5.52 cli command "show proc $cpuline5_pid"
action 5.53 regexp " \[([a-zA-Z a-zA-Z]+)\]" "$_cli_result" cpuline5_name
action 5.59 end

action 9.01 if $cpulines eq "5"
action 9.02 syslog msg "Top CPU Processes: ($cpuline3_pid)$cpuline3_name || ($cpuline4_pid)$cpuline4_name || ($cpuline5_pid)$cpuline5_name"
action 9.03 if $cpulines eq "4"
action 9.04 syslog msg "Top CPU Processes: ($cpuline3_pid)$cpuline3_name || ($cpuline4_pid)$cpuline4_name"
action 9.05 if $cpulines eq "3"
action 9.06 syslog msg "Top CPU Process: ($cpuline3_pid)$cpuline3_name"
action 9.07 end
action 9.08 end
action 9.09 end

action 9.90 increment cpulines
action 9.91 if $cpulines eq "6"
action 9.92 break
action 9.93 end

action 9.99 end
exit
!

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

Just use action puts instead of action syslog.  It will do the right thing.  When synchronous, it will print the originating VTY.  When async, it will output to syslog.

View solution in original post

3 Replies 3

Joe Clarke
Cisco Employee
Cisco Employee

Just use action puts instead of action syslog.  It will do the right thing.  When synchronous, it will print the originating VTY.  When async, it will output to syslog.

Thanks Joe.

If I understand you correctly, puts will send to VTY or syslog? So make this change?

==============

action 9.01 if $cpulines eq "5"
action 9.02 puts "Top CPU Processes: ($cpuline3_pid)$cpuline3_name || ($cpuline4_pid)$cpuline4_name || ($cpuline5_pid)$cpuline5_name"
action 9.03 if $cpulines eq "4"
action 9.04 puts "Top CPU Processes: ($cpuline3_pid)$cpuline3_name || ($cpuline4_pid)$cpuline4_name"
action 9.05 if $cpulines eq "3"
action 9.06 puts "Top CPU Process: ($cpuline3_pid)$cpuline3_name"

==============

Yes.

Review Cisco Networking for a $25 gift card