02-03-2015 03:34 AM
Hi , I have Cisco ASR9k running with NAT44 service
I have some numbers to monitor that will be extracted using show | include
I want to write an EEM script that will take an action if this value exceeds a certain value
As well , can I draw these value using show with include option ?
Thanks
05-26-2015 12:02 AM
Hi Joesph
Please check below
::cisco::eem::event_register_none sync yes
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
array set arr_einfo [event_reqinfo]
if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli1 $result
}
if [catch {cli_write $cli1(fd) "run attach 0/1/CPU0"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_read_pattern $cli1(fd) "#"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_write $cli1(fd) "show_nat44_stats"} _cli_result] {
error $_cli_result $errorInfo
}
append output $_cli_result
if [cli_read_pattern $cli1(fd) {#\s}} _cli_result]
error $_cli_result $errorInfo
}
append output $_cli_result
if [catch {cli_exec $cli1(fd) "exit"} _cli_result] {
error $_cli_result $errorInfo
}
append output $_cli_result
foreach line [split $output "\n"] {
set line [string trim $line]
regsub -all {\s+} $line " " line
if { [regexp {^([0-9]+) ([0-9]+)\([0-9.]+%\) ([0-9]+)} $line -> core sessions users] } {
puts "Core: $core, Sessions: $sessions, Users: $users" }
}
append $output
# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result
Is this the right format ?
Thank in advance
05-26-2015 07:30 AM
This looks right (assuming there is in fact a space after the '#' prompt). You may have to play with that regular expression so that it matches the prompt without matching the other '#' in the command output.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide