02-06-2009 06:58 AM
How about a forum dedicated to Tcl scripting and using Embedded Event Manager?
All useful for testing and debugging.
06-09-2011 12:49 PM
This is unreadable. Can you reformat or repost?
06-09-2011 12:51 PM
I read the attached code, and this looks okay.
06-13-2011 07:52 AM
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
06-13-2011 11:38 PM
For IPBASE, you'll need 12.2(55)SE or higher. With IPSERVICES, your current version of code is okay.
06-16-2011 12:56 PM
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
06-17-2011 01:06 AM
06-17-2011 08:28 AM
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)#
06-17-2011 09:43 AM
Never Mind I just move the "}" on the same line after "if {![info exists output ] || $output == "" }"
06-17-2011 01:42 PM
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"
06-17-2011 01:52 PM
For every five minutes, you want:
"*/5 * * * *"
01-09-2012 05:30 AM
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.
01-09-2012 08:24 AM
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"
01-09-2012 10:49 PM
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.
01-09-2012 11:03 PM
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"
01-10-2012 07:15 AM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide