cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1713
Views
5
Helpful
4
Replies

IOS-XR Get Interface rxLoad TCL

diverNB89
Level 1
Level 1

Hello, hoping someone can help me identify what I'm doing wrong with my script below:

::cisco::eem::event_register_timer watchdog time 20 maxrun 240
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
set errorInfo ""
#Notify users that we're collecting
set output_msg "Collecting commands"
action_syslog priority info msg $output_msg
#query the event info
array 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 connection
if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli1 $result
}
##Get interface load and save in _cli_result
if [catch {cli_exec $cli1(fd) "show interfaces te0/1 | i rxload"} _cli_result] {
error $_cli_result $errorInfo
}
action_syslog priority info msg $_cli_result
regexp {1(?:(?!1))} $_cli_result rx_load1
regexp {([^1\/]+$)} $_cli_result rx_load2
set 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/255
if {$rx_load < 0.705882352941} {
        action_syslog priority info msg "RX Load Is acceptable"
} else {
    action_syslog priority info msg "RX load high"
}
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)
Anyone have any ideas what I'm doing wrong here?
1 Accepted Solution

Accepted Solutions

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.

View solution in original post

4 Replies 4

Joe Clarke
Cisco Employee
Cisco Employee

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.

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.

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.

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.