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
04-21-2015 10:13 AM
Nothing would appear unless you're on the console or monitoring the current VTY line. The results are printed via syslog. If you want the results to appear on the same terminal outside of syslog, change the "action_syslog msg" command to "puts" and reregister the policy.
04-21-2015 11:51 PM
Hi Joseph
I have tried to modify the script , but it did not appear until I have added the puts "$_cli_result" line again , please find the complete script
::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
}
if [catch {cli_read_pattern $cli1(fd) "#"} _cli_result] {
error $_cli_result $errorInfo
}
set output $_cli_result
if [catch {cli_exec $cli1(fd) "exit"} _cli_result] {
error $_cli_result $errorInfo
}
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" }
}
puts "$_cli_result"
# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result
As well , the issue am facing is that the output is missing and not complete , please check below
RP/0/RSP0/CPU0:UM-HQ1-CGN-3G-NAT1#event manager run CGN1.tcl
Wed Apr 22 09:47:52.397 AST
55269(42.17%)
3 672614(23.4%) 55571(42.40%)
4 232347(8.1%) 11434(8.72%)
5 228224(7.9%) 11400(8.70%)
6 231314(8.0%) 11359(8.67%)
7 221876(7.7%) 11425(8.72%)
------------------------------------------------------------------------
Total Sessions: 3581296 Total users: 267455
Main DB size is 2875008 and User DB size is 131072
#
Thanks a lot for your help
BR,
Mohammad
04-22-2015 01:58 AM
Hi
As well , I have the below script
::cisco::eem::event_register_timer cron cron_entry "*/1 * * * *"
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_exec $cli1(fd) "show ipv4 interface brief | exclude unassigned"} _cli_result] {
error $_cli_result $errorInfo
}
puts "$_cli_result"
# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result
Which is working , but when I change the show command to the below , it's not working
show cgn nat44 nat1 statistics | include "sessions|subscribers"
Can I append a file on a TFTP server (windows machine)?
Can I draw this ?
BR,
Mohammad
04-22-2015 09:46 AM
Your command has embedded quotes. Assuming it works when you type it manually, then this should work in Tcl:
if { [catch {cli_exec $cli1(fd) {show cgn nat44 nat1 statistics | include "sessions|subscribers"}} _cli_result] } {
Yes, you can save this to a TFTP server. Just execute the commands you'd have to execute manually as cli_exec within Tcl (assuming they are not interactive). If the commands are interactive, then you'll have to follow the example in the other Tcl script to use cli_write and cli_read_pattern to respond to the prompts.
04-22-2015 09:41 AM
Interesting. Seems the output isn't being saved where it should. Try adding:
append output $_cli_result
Right before the "foreach" line. See if that helps.
05-05-2015 03:52 AM
Hi Joseph
I tried to add the append output $_cli_result but the same output (the missing output) appeared again
The script is fine , I just need to resolve this issue
BR,
Mohammad
05-05-2015 04:53 PM
What does your current script look like?
05-05-2015 11:30 PM
::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
}
if [catch {cli_read_pattern $cli1(fd) "#"} _cli_result] {
error $_cli_result $errorInfo
}
set 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" }
}
puts "$_cli_result"
# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result
05-06-2015 10:58 AM
I see the problem. Change the regexp line to:
if { [regexp {^([0-9]+) ([0-9]+)\([0-9.]+%\) ([0-9]+)} $line -> core sessions users] } {
Then if you want to see the full matched output, change your last puts to:
puts $output
05-11-2015 12:41 AM
The same
RP/0/RSP0/CPU0:CGN-3G-NAT1#event manager run CGN1.tcl
Mon May 11 10:39:58.201 AST
# 57521(43.89%)
3 769793(26.8%) 57527(43.89%)
4 246830(8.6%) 11543(8.81%)
5 259836(9.0%) 11620(8.87%)
6 246769(8.6%) 11585(8.84%)
7 261787(9.1%) 11650(8.89%)
------------------------------------------------------------------------
Total Sessions: 4105605 Total users: 276219
Main DB size is 2875008 and User DB size is 131072
#
#
Terminating attach to node 0/1/CPU0..
05-11-2015 07:15 AM
Chane the regsub line to:
regsub -all {\s+} $line " " line
And it looks like you didn't change the last puts so that it prints all output?
05-12-2015 12:28 AM
Hi Joseph and sorry for keep bothering
The output differs but still missing
RP/0/RSP0/CPU0:UM-HQ1-CGN-3G-NAT1#event manager run CGN1.tcl
Tue May 12 10:25:53.837 AST
Core: 3, Sessions: 763202, Users: 57544
Core: 4, Sessions: 240879, Users: 11622
Core: 5, Sessions: 254223, Users: 11545
Core: 6, Sessions: 243926, Users: 11479
Core: 7, Sessions: 237100, Users: 11545
# 57455(43.83%)
3 763202(26.5%) 57544(43.90%)
4 240879(8.4%) 11622(8.87%)
5 254223(8.8%) 11545(8.81%)
6 243926(8.5%) 11479(8.76%)
7 237100(8.2%) 11545(8.81%)
------------------------------------------------------------------------
Total Sessions: 4020292 Total users: 276022
Main DB size is 2875008 and User DB size is 131072
#
#
The complete script now looks like the 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
}
if [catch {cli_read_pattern $cli1(fd) "#"} _cli_result] {
error $_cli_result $errorInfo
}
set 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" }
}
puts $output
# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result
05-12-2015 06:37 AM
You may need to move the "set output" command right after you run the show_nat44_stats command. Then change the existing "set output" command to:
append output $_cli_result
05-18-2015 03:34 AM
Hi Joseph
if [catch {cli_write $cli1(fd) "show_nat44_stats"} _cli_result] {
error $_cli_result $errorInfo
}
append output $_cli_result
if [catch {cli_read_pattern $cli1(fd) "#"} _cli_result] {
error $_cli_result $errorInfo
}
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" }
}
Still the same output
05-18-2015 08:48 AM
I meant for there also to be an append output $_cli_result after the cli_read_pattern call. Add that, then change the cli_read_pattern line to:
if [cli_read_pattern $cli1(fd) {#\s}} _cli_result] {
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