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

EEM Tcl script

daniel.jfj
Level 1
Level 1

Hi guys,

Can anyone i've been trying to modify a Cisco tcl script to do what i really need it to do but im not getting anywhere...i'm not a programmer :/

I need to make a script that tracks an event, it can be a interface going down or an ip sla timing out and perform a cli command but save the whole output of the command and sent it over an email.

For instance the system:lib/tcl/eem_scripts/sl_intf_down.tcl is almost there but it does not save the output of a trace command for instance.

On the other hand the system:lib/tcl/eem_scripts/tm_cli_cmd.tcl saves the output of the command and sends it over an email but i cannot change the trigger condition, in this case is a cron entry. i've tried just changing

::cisco::eem::event_register_timer cron name crontimer2 cron_entry  to ::cisco::eem::event_register_syslog occurs 1 pattern $_syslog_pattern maxrun

but no luck.... always get an error:

Probe-SG(config)#event manager policy test2.tcl type user

Embedded Event Manager configuration: failed to create the event spec for policy test2.tcl: regular expression compilation error
Probe-SG(config)#
May 26 03:46:23.114: cli_history_entry_add: free_hist_list size=0, hist_list size=7
May 26 03:46:23.114: check_eem_cli_policy_handler: command_string=event manager policy test2.tcl type user
May 26 03:46:23.114: check_eem_cli_policy_handler: num_matches = 0, response_code = 1fh_policyname = test2.tcltype = 1type = 1find user policy absolute path flash:/scripts//test2.tclfind absolute policy path flash:/scripts//test2.tclfound type = 1register eem policy flash:/scripts//test2.tcl
May 26 03:46:23.118: check 1: not duplicate registrationspawn script flash:/scripts//test2.tcl
May 26 03:46:23.118: fh_spawn: -FMPRE flash:/scripts//test2.tcl
May 26 03:46:23.118: fh_tcl_spawn: argc=3, argstr=-FMPRE, stdin=2, stdout=2,stderr=2, priority=4
May 26 03:46:23.122: waiting for tclsh
May 26 03:46:23.126: fh_tcl_get_mode: mode = 0, StartupScript = flash:/scripts//test2.tcl, RealScript = flash:/scripts//test2.tcl
May 26 03:46:23.126: fh_register_evreg_cmds: tctx=82B5C5F8, dummy=0
May 26 03:46:23.134: fh_register_event_cmn: filename=flash:/scripts//test2.tcl
May 26 03:46:23.146: [fh_event_register_syslog_cmd]
May 26 03:46:23.146: occurs: 1
May 26 03:46:23.146: pattern: *Loopback50*
May 26 03:46:23.146: time: sec=90, msec=0
May 26 03:46:23.146: fh_tcl_assoc_data_delproc: freeing tctx=82B5C5F8
Probe-SG(config)#
May 26 03:46:23.154: tclsh boolean occurred
May 26 03:46:23.154: check 3: tclsh precompilation check
May 26 03:46:23.154: fh_server: fh_io_msg: received msg FH_MSG_EVENT_CREATE from client 1 pclient 1
May 26 03:46:23.154: fh_msg_send_to_fd: receive a reply msg, minor: 5fh_reg_policy_core failed

Probe-SG#sh run | s event                
event manager environment _email_server z.z.z.z
event manager environment _email_to daniel@xxxxx.com
event manager environment _email_from daniel@xxxxx.com
event manager environment _show_cmd trace 8.8.8.8
event manager environment _email_cc daniel.jesus@zzzz.com
event manager environment _syslog_pattern *Loopback50*
event manager environment _log_file flash:/scripts/trace.log
event manager directory user policy flash:/scripts/
event manager directory user library flash:/scripts/

(in this case i was just tracking events on loop50 but i also need to track an ip sla timeout - should be on a different script)

Can anyone help?

Thanks,

Daniel

2 Accepted Solutions

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

You're close.  Your pattern regular expression is wrong.  Try this instead (and don't use variables that start with '_'):

event manager environment syslog_pattern .*Loopback50.*

::cisco::eem::event_register_syslog occurs 1 pattern $syslog_pattern

View solution in original post

8 Replies 8

Joe Clarke
Cisco Employee
Cisco Employee

You're close.  Your pattern regular expression is wrong.  Try this instead (and don't use variables that start with '_'):

event manager environment syslog_pattern .*Loopback50.*

::cisco::eem::event_register_syslog occurs 1 pattern $syslog_pattern

Hi Joseph,

Thank you very much for your reply.

now, i can start the script but i still get errors :/

Probe-SG(config-if)#
May 26 12:19:20.125: %LINK-3-UPDOWN: Interface Loopback50, changed state to up
May 26 12:19:21.296: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback50, changed state to up
Probe-SG(config-if)#
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl: can't read "arr_einfo(timer_type)": no such element in array
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl:     while executing
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl: "set timer_type $arr_einfo(timer_type)"
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl:     invoked from within
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl: "$slave eval $Contents"
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl:     (procedure "eval_script" line 7)
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl:     invoked from within
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl: "eval_script slave $scriptname"
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl:     invoked from within
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl: "if {$security_level == 1} {       #untrusted script
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl:      interp create -safe slave
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl:      interp share {} stdout slave
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl:      interp share {} stderr slave..."
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl:     (file "system:/lib/tcl/base.tcl" line 50)
May 26 12:19:22.044: %HA_EM-6-LOG: trace.tcl: Tcl policy execute failed: can't read "arr_einfo(timer_type)": no such element in array
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl: can't read "arr_einfo(timer_type)": no such element in array
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl:     while executing
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl: "set timer_type $arr_einfo(timer_type)"
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl:     invoked from within
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl: "$slave eval $Contents"
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl:     (procedure "eval_script" line 7)
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl:     invoked from within
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl: "eval_script slave $scriptname"
Probe-SG(config-if)#
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl:     invoked from within
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl: "if {$security_level == 1} {       #untrusted script
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl:      interp create -safe slave
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl:      interp share {} stdout slave
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl:      interp share {} stderr slave..."
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl:     (file "system:/lib/tcl/base.tcl" line 50)
May 26 12:19:23.008: %HA_EM-6-LOG: trace.tcl: Tcl policy execute failed: can't read "arr_einfo(timer_type)": no such element in array
Probe-SG(config-if)#

If you have time to help you, please do

Thank you!!

Daniel

It would be helpful to post the script as you have it now.  The reference to arr_einfo(timer_type) needs to be removed as you're no longer using the timer ED.

Hi Joseph,

Again thank you for your time on this.

.tcl is attached.

Regards,

Daniel

Try this.

Hi Joseph,

Almost... it does the trace but

(snipped)

May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: DEBUG(cli_lib) : OUT :     209.85.242.233 8 msec
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: DEBUG(cli_lib) : OUT :     209.85.242.243 8 msec
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: DEBUG(cli_lib) : OUT :   8 209.85.242.125 20 msec
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: DEBUG(cli_lib) : OUT :     209.85.250.237 8 msec
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: DEBUG(cli_lib) : OUT :     209.85.242.125 12 msec
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: DEBUG(cli_lib) : OUT :   9 66.249.94.166 8 msec
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: DEBUG(cli_lib) : OUT :     66.249.94.126 20 msec
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: DEBUG(cli_lib) : CTL : 20+ lines read from cli_read, debug output truncated.
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: DEBUG(cli_lib) : CTL : cli_close called.
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: DEBUG(cli_lib) : IN  : Probe-SG#exit

invalid command name "result"
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:     while executing
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: "result"
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:     invoked from within
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: "if {[info exists _email_server]} {
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:     set routername [info hostname]
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:     if {[string match "" $routername]} {
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:     error "Host name is not configured"..."
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:     invoked from within
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: "$slave eval $Contents"
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:     (procedure "eval_script" line 7)
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:     invoked from within
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: "eval_script slave $scriptname"
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:     invoked from within
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: "if {$security_level == 1} {       #untrusted script
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:      interp create -safe slave
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:      interp share {} stdout slave
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:      interp share {} stderr slave..."
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl:     (file "system:/lib/tcl/base.tcl" line 50)
May 27 07:16:16.866: %HA_EM-6-LOG: trace.tcl: Tcl policy execute failed: invalid command name "result"
May 27 07:16:16.866: fh_tcl_esi_close: fd=14
May 27 07:16:16.870: fh_tcl_assoc_data_delproc: freeing tctx=8374306Creceived SIGCHLD pulse from child death pid=203received pulse from child death code=1; epc=0x83B81940EEM policy trace.tcl has ended with normal exit status of 0x0fh_schedule_policy: prev_epc=0x83B81940;

cheers,

Daniel

Try this.

Hi Joseph,

Working like a charm!!!

Thank you very much for your help =)

Cheers,

Daniel

Review Cisco Networking for a $25 gift card