06-06-2017 06:45 AM
Hello, hoping someone can help me identify what I'm doing wrong with my script below:
I've tested my regex and comparison operators in the tclsh on the router, and they're good when set the value of _cli_result manually. In production however, _cli_result seems to be storing the command "show interfaces te0/1 | i rxload" rather than it's output ( reliability 255/255, txload 0/255, rxload 1/255)::cisco::eem::event_register_timer watchdog time 20 maxrun 240namespace import ::cisco::eem::*namespace import ::cisco::lib::*set errorInfo ""#Notify users that we're collectingset output_msg "Collecting commands"action_syslog priority info msg $output_msg#query the event infoarray set arr_einfo [event_reqinfo]if {$_cerrno != 0} {set result [format "component=%s; subsys err=%s; posix err=%s;\n%s" \$_cerr_sub_num $_cerr_sub_err $_cerr_posix_err $_cerr_str]error $result}#open a cli connectionif [catch {cli_open} result] {error $result $errorInfo} else {array set cli1 $result}##Get interface load and save in _cli_resultif [catch {cli_exec $cli1(fd) "show interfaces te0/1 | i rxload"} _cli_result] {error $_cli_result $errorInfo}action_syslog priority info msg $_cli_resultregexp {1(?:(?!1))} $_cli_result rx_load1regexp {([^1\/]+$)} $_cli_result rx_load2set rx_load2 [expr { $rx_load2 / 1.0}]set rx_load [expr {$rx_load1 / $rx_load2}]action_syslog priority info msg $rx_load#Compare current Rx_load to 180/255if {$rx_load < 0.705882352941} {action_syslog priority info msg "RX Load Is acceptable"} else {action_syslog priority info msg "RX load high"}
Solved! Go to Solution.
06-06-2017 01:07 PM
You might try without the pipe to see if it makes a difference. The other thing that seems really weird to me is your choice of regular expressions. They look way too complicated for what you want to do. Why not do:
regexp {rxload (\d+)/(\d+)} $_cli_result -> rx_load1 rx_load2
This is much simpler, and consolidates things into one line.
06-06-2017 11:20 AM
This is IOS-XR, right? I typically haven't seen interfaces named so simply on XR boxes. If the interface really is Te0/1 and the command output otherwise looks normal when run manually, then I would suggest making sure the EEM user account under which is the policy is registered has access to run the command. Try logging in as that user and make sure the command returns the proper output when run manually.
06-06-2017 11:36 AM
Hi Joe,
This is XR, I just simplified the interface in this posting of the script.
Command runs fine manually as the user account that is registered to run this policy.
Dumping _cli_result to the Syslog right after the command is how I was able to find out why my if statement wasn't running.
06-06-2017 01:07 PM
You might try without the pipe to see if it makes a difference. The other thing that seems really weird to me is your choice of regular expressions. They look way too complicated for what you want to do. Why not do:
regexp {rxload (\d+)/(\d+)} $_cli_result -> rx_load1 rx_load2
This is much simpler, and consolidates things into one line.
06-06-2017 01:59 PM
Hey Joe, thanks for that regexp. This is my first foray into tcl/regexp, so thanks for the help on that. I'll try without the pipe and see if that helps the issue.
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