Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

Running a TCL script through EEM every 60 seconds

I have a script written in the TCLSH of IOS, I can test this script from the shell using the following commands

LAB-RTR#tclsh
LAB-RTR(tcl)#source flash:test.tcl

 NO CALLS

 

Is there a way I can run this test.tcl script every 60 seconds on the router.

 

SCRIPT test.tcl

 

proc get_ints {} {
set syslog [open "syslog:" w+]
#puts "BEFORE\n"
set check ""
set int_out [ exec "show voice call status\n" ]
#puts "INTOUT $int_out\n"
set mylist [regexp -nocase -line -inline {(^([0-9]*|No) active calls? found)} $int_out]

#puts "MYLIST $mylist\n"

foreach int $mylist {
 #puts "INT $int\n"
 if {$int == "No"} {
  puts " NO CALLS\n";
  puts $syslog "NO CALLS"
 } elseif {[string is integer -strict $int]} {
  puts "$int CALLS\n";
  puts $syslog "$int CALLS"
 } else {
  #puts "GARBAGE\n";
 }
}
close $syslog
}

#puts ""

puts [eval get_ints]

  • EEM Scripting
1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

Convert this to an EEM Tcl

Convert this to an EEM Tcl policy.  Just add:

 

proc exec { cmd } {

    global errorInfo

    if { [catch {cli_open} result] } {

        error $result $errorInfo

    }

    array set cli $result

    set output [cli_exec $cli(fd) $cmd]

    catch {cli_close $cli(fd) $cli(tty_id)}

    return $output

}

 

Then register this as an EEM Tcl policy with this at the top:

 

::cisco::eem::event_register_timer watchdog time 60

 

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

 

It will then run every 60 seconds.

6 REPLIES
Cisco Employee

Convert this to an EEM Tcl

Convert this to an EEM Tcl policy.  Just add:

 

proc exec { cmd } {

    global errorInfo

    if { [catch {cli_open} result] } {

        error $result $errorInfo

    }

    array set cli $result

    set output [cli_exec $cli(fd) $cmd]

    catch {cli_close $cli(fd) $cli(tty_id)}

    return $output

}

 

Then register this as an EEM Tcl policy with this at the top:

 

::cisco::eem::event_register_timer watchdog time 60

 

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

 

It will then run every 60 seconds.

New Member

Hey Joseph, Thanks a lot for

Hey Joseph, Thanks a lot for pointing me in the right direction. I have my script running the way I want. I was able to generate a syslog using the script, now I need to generate a SNMP trap can you give me an example of how to do it.

 

 action_syslog priority emergencies msg "TOO MANY CALLS" -- This works

Cisco Employee

Something like this would

Something like this would work:

 

action_snmp_trap strdata "TOO MANY CALLS"

New Member

Hey Joseph, Thanks for all

Hey Joseph, Thanks for all your help. I have one last question, so now that I am running my script every 60 seconds if there is an issue I send multiple traps to our monitoring system. Is there any way you can keep track if the trap was already sent I will not send another trap again.

 

One way I can think of is using a loopback interface. But I would prefer not shutting down the loopback interface just to keep track of what my script is doing.

 

IF issue {
   IF Loop1 is up {
            don't send trap
    } ELSE {
            bring Loop1 up
            Send Trap
    }
 } ELSE (No issue) {
   shutdown Loop1
 }
 

 

Cisco Employee

EEM has the concept of

EEM has the concept of contexts where you can store data between executions.  You save data using context_save and retrieve it using context_retrieve.  Note: context data is volatile, so when it is retrieved, the context is destroyed.  See http://www.cisco.com/c/en/us/td/docs/ios/netmgmt/configuration/guide/12_2sx/nm_12_2sx_book/nm_eem_policy_tcl.html#wp1210964 for more details.

New Member

Thanks  lot Joseph.

Thanks  lot Joseph.

349
Views
0
Helpful
6
Replies
This widget could not be displayed.