cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3253
Views
0
Helpful
8
Replies

TCL Script for monitoring router's interfaces.

thsmfe001
Level 1
Level 1

Hi, All

I want to make TCL script for EEM to check load of interfaces in CRS router.

But I've stuck in difficult to find a way to check all active interfaces in the router.

I am trying to use a below script but it haven't worked well.

I want to leverage loop logic with foreach but i couldn't make it well.

Could you tell me how to make a batch job to monitoring interface load?

Thank You

Yun.

set output [exec "show ip int brief | inc up"]
foreach line [split $output "\n"] {
regsub -all {\s+} $line " " line
set ifname [lindex $line 0]
if { [lindex $line end] == "up" && [lindex $line end-1] == "up" } {

# Get utilization
set utili_val [exec "sh int $ifname | inc load"]

#getting the value of txload and rxload
{ [regexp -line -nocase {.*txload ([0-9]+)/255, rxload ([0-9]+)/255}
$utili_val complete_string tx_val rx_val] }

#calculate the txload percentage; if more than 80 send syslog err
if [expr ($tx_val/255 * 100 >= 50.00]
action_syslog priority err "ERROR: $ifname TXLOAD is: $tx_val; more than 50 percent"

#calculate the rxload percentage; if more than 80 send syslog err
if [expr ($rx_val/255 * 100 >= 50.00]
action_syslog priority err "ERROR: $ifname RXLOAD is: $rx_val; more than 50 percent"
}
}

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

There are a number of problems here.  First, this is not syntactically correct Tcl.  Second, this is not EEM Tcl.  When you say CRS, do you mean this is for the IOS-XR CRS family?  I'm not sure the CLI output of those commands is consistent with what you have here.  Post the output of each of the CLI commands you have in the above code snippet.

View solution in original post

8 Replies 8

Joe Clarke
Cisco Employee
Cisco Employee

There are a number of problems here.  First, this is not syntactically correct Tcl.  Second, this is not EEM Tcl.  When you say CRS, do you mean this is for the IOS-XR CRS family?  I'm not sure the CLI output of those commands is consistent with what you have here.  Post the output of each of the CLI commands you have in the above code snippet.

Thank you for quick reply.

I attached command ouputs referenced in the TCL script.

I modified my script more

Please check it and give me your opinions.

Thank you so much.

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

set ports [exec sh ip int br]
foreach line [split $ports "\n"] {

if [regexp {^([A-Za-z0-9]+\/[0-9\/]+)\s+} $line match port] {

set util_val [exec "show int $port | inc load"]

regexp -line -nocase {.*txload ([0-9]+)/255, rxload ([0-9]+)/255} $util_val complete_string tx_val rx_val

if {$tx_val >= 128} {

action_syslog priority warn msg "WARNING: $port TXLOAD is: $tx_val; more than 50 percent"

if {$rx_val >= 128} {

action_syslog priority warn msg "WARNING: $port RXLOAD is: $rx_val; more than 50 percent"
}
}
}
}

This is still not proper EEM Tcl.  EEM Tcl does not have an exec command, plus you're missing the event.  If you want to use exec versus converting to the proper CLI command handling, then you'll need to include this code: Migration code to move from tclsh to EEM Tcl .

You also need to pick an event to trigger this policy (likely a watchdog timer).  Have a look at http://www.cisco.com/c/en/us/td/docs/routers/crs/software/crs_r4-2/system_monitoring/configuration/guide/b_sysmon_cg42crs/b_sysmon_cg42crs_chapter_010.html for more on the events as well as how to register your final policy with the EEM server.

Thank you for reply.

I modified the script futher with your guide.

Is it better ?

I have some problem not to have a test mechine so i need to check the script before it will be implemented to customer's production environment.

::cisco::eem::event_register_timer countdown time 60 name loadcheck maxrun 86400

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

proc exec { cmd } {
    global errorInfo
   
    if { [catch {cli_open} result] } {
        error $result $errorInfo
    }
   
    array set cli $result
   
    if { [catch {cli_exec $cli(fd) "enable"} result] } {
        error $result $errorInfo
    }
   
    if { [catch {cli_exec $cli(fd) $cmd} result] } {
        error $result $errorInfo
    }
   
    catch {cli_close $cli(fd) $cli(tty_id)}
   
    return $result
}

set ports [exec "sh ip int br"]
foreach line [split $ports "\n"] {

   if [regexp {^([A-Za-z0-9]+\/[0-9\/]+)\s+} $line match port] {

   set util_val [exec "show int $port | inc load"]

   regexp -line -nocase {.*txload ([0-9]+)/255, rxload ([0-9]+)/255} $util_val complete_string tx_val rx_val
  
   if {$tx_val >= 0} {

     action_syslog priority warning msg "ERROR: $port TXLOAD is: $tx_val; more than 50 percent"

   if {$rx_val >= 0} {

    action_syslog priority warning msg "ERROR: $port RXLOAD is: $rx_val; more than 50 percent"
   }
  }
 }
}

You should probably use a watchdog timer as countdown will only run once.  And you've changed your comparisons to check if load is >= 0.  This is not 50%.  You should set that back to 128.

I always thank for your thorough support.

In NX-OS case, It doesn't support eem library supported on another OS.

So how to send syslog messages with a Tcl script working on a NX-OS platform.

Thank you.

NX-OS does not support Tcl-based EEM.  NX-OS can only do EEM applets.  You could build a Tcl or Python script that is called from EEM, though.  There is a hidden CLI command called "logit" that can generate syslog messages.

Review Cisco Networking for a $25 gift card