cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
16807
Views
25
Helpful
38
Replies

Tcl & EEM forum

Mel Popple
Level 1
Level 1

How about a forum dedicated to Tcl scripting and using Embedded Event Manager?

All useful for testing and debugging.

38 Replies 38

This is unreadable.  Can you reformat or repost?

I read the attached code, and this looks okay.

Hi Joe,

    Thanks again, anyway I am trying to find out if tcl is available on Cat3560 and Cat3750 switches to test this code. I tried it on IOS

c3560-ipbasek9-mz.122-50.SE3 but tcl is not available. Do you know what version would it be available?

Many Thanks,

John

For IPBASE, you'll need 12.2(55)SE or higher.  With IPSERVICES, your current version of code is okay.

Hi Joe,

    There's a little bit change from the original requirement. Please review the code based on the changes below.

1. Run a show command on the switch that will give us a list of the interfaces that are configured as uplinks. 

These commands will run on both a layer 2 and layer 3 switch, and will either give us no output or correct output depending on whether the device is layer 2 or layer 3.

a. On layer 2 switches - show int trunk | include trunking

b. On layer 3 switches –show ip int brief | exclude (unassigned|Loopback|Vlan|Method)

2. For each line of output from the results in 1, do the following.

a. Parse the output data to just get the interface name

b. Run a show command on the interface name to get the utilization stats for the past 5 minutes. 

c. If transfer utilization is greater than x, then generate a syslog message with message stating high utilization on this specific interface on this specific host.

d. Continue loop until results of 1 are finished.

I am not sure how can I separate the code below so I don't have to include it on both if's clause, since it will run it no matter what the output is..

# Get utilization          

set utili_val [run_cli "sh int $ifname | inc load"]          

set precision_tcl 2       

#getting the value of txload        

{ [regexp {.+?txload (.+?)\/255} $utili_val match tx_val] }       

#calculate the txload percentage; if more than 80 percent send syslog err             

if [expr ($tx_val/255.00 * 100 >= 80.00 ) ]                    

      action_syslog priority err "ERROR: $ifname TXLOAD is: $tx_val; more than 80 percent"

I greatly appreciate your help and thanks,

John

I do not understand your question.  What code do you want to conditionalize?  The L2/L3 code?

Try this version.

Hi Joe,  

  Yes, that's what I meant since the $output is the same variable for L2 and L3 switches.

Anway when I tried to compile this script, it gives me this error.

Here's what I did..I am not sure why it did not pass thru the "if {![info exists output ] || $output == "" }"

LAB_CAT3560#copy tftp: flash:/policies

Address or name of remote host []? 10.10.10.3 Source filename []? switch_util.tcl

Destination filename [/policies/switch_util.tcl]?

Accessing tftp://10.10.10.3/switch_util.tcl

... Loading switch_util.tcl from 10.10.10.3 (via Vlan1): ! [OK - 3821 bytes]

LAB_CAT3560#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

LAB_CAT3560(config)#event manager directory user policy flash:/policies

LAB_CAT3560(config)#event manager policy switch_util.tcl

EEM Register event failed:wrong # args: no script following "{![info exists output" argument     while compiling "if {![info exists output ] || $output == "" }"

EEM configuration: failed to retrieve intermediate registration result for policy switch_util.tcl

LAB_CAT3560(config)#

Never Mind I just move the "}" on the same line after "if {![info exists output ] || $output == "" }"

And in regards running an EEM Policy Every Time a Device Boots should I include this on my script something like this or the policy will saved on startup-config....

::cisco::eem::event_register_timer cron cron_entry "@reboot"

For every five minutes, you want:

"*/5 * * * *"

faisal.jafary
Level 1
Level 1

Hi,

I am configurig my cisco devices to get the  Email notification alert if there has been a change made on a cisco device,

here is the script

event manager environment _email_server 172.16.28.186

event manager environment _email_to faisal.jafary@onmobile.com

event manager environment _email_from faisal.jafary@onmobile.com

event manager applet email_diff

event syslog pattern ".*%SYS-5-CONFIG.*"

action 1.0 info type routername

action 1.1 cli command "enable"

action 1.2 cli command "show archive config differences nvram:/startup-config system:/running-config"

action 1.3 mail server "$_email_server" to "$_email_to" from "$_email_from" subject "Configuration Change Alert (hostname:$_info_routername)" body "$_cli_result"

action 1.4 syslog msg "Configuration change notification sent to email server!"

this works just fine and sends the email once there has been a change made, however it does not sends the name of the logged in user in the email, is there a possibility to get the name of the logged in user in that email alert as well.

Thanks.

Well, the syslog message should state who made the last change.  If you are using EEM 3.0 or higher, you can extract that name with a regular expression:

action 1.25 regexp "by (.*) on" $_syslog_msg match user

action 1.26 puts "$user made the last change"

Hi Joseph,

Thanks for the immediate reply,

But the commands didnt work, it didnt give the name of the logged in user who made the last change,

below is the output which i recieved via email after I changed the hostname,

Contextual Config Diffs:

+hostname OM-RPS-MPLS

event manager applet email_diff

+action 1.25 regexp "by (.*) on" "$_syslog_msg" match user +action 1.26 puts "$user made the last change"

-hostname OM-RPS-MPLS-RTR

OM-RPS-MPLS#

Please let me know what can be done here.

My code was merely an example.  To get your email to include the name of the user, you need to specify the $user variable in your email message.  For example:

action 1.3 mail server "$_email_server" to "$_email_to" from  "$_email_from" subject "Configuration Change Alert  (hostname:$_info_routername)" body "User: $user , $_cli_result"

Hey Joseph it worked, this time i did get the name of the logged in user who made the recent change, but the only issue im having is that it sends the whole lot of things even for the smallest of changes made such as just a mere change in the hostname,

for eg i just changed the hostname and i got the below output with the eem applet commands which i ran as well.

Also could you please tell me if runing the eem scripts causes  high CPU Utilization or not.

below is the output,

***************************************************************************

User: faisal.jafary ,

Contextual Config Diffs:

event manager applet email_diff

+action 1.25 regexp "by (.*) on" "$_syslog_msg" match user +action 1.3 mail server "$_email_server" to "$_email_to" from "$_email_from" subject "Configuration Change Alert (hostname:$_info_routername)" body "User: $user , $_cli_result"

event manager applet email_diff

-action 1.3 mail server "$_email_server" to "$_email_to" from "$_email_from" subject "Configuration Change Alert (hostname:$_info_routername)" body "$_cli_result"

OM-RPS-MPLS-RTR#

**************************************************************************************

I am not into scripting or programming so i mite be making silly mistakes here, but i hope you can help me here.

Thanks for your help