12-18-2010 07:16 AM
hello all,
i'm using a router 877 at home and i really need to check out what this router do during the day.
So some time ago i configured it using some eem actions and sending to me email, without any problems.
Yesterday I changed my internet provider and now i need to use smtp autheticantion to send emails.
I read about how to authenticate, like username:password@host and also made a fast search here, without solve my problem.
I need to put as username the email of the provider like: mouse@host.com:mypassword@smtpserveraddress.com.
So, i want to know if someone had the same problem and solved it. Of course i couldn't use @ two times or eem would think that host.com is my smtp server! And right now is going in this way!
My IOS version is 15.1(2)T2, eem version is 3.1.
Hope someone could help me!
Thank you in advance.
Sandro
Solved! Go to Solution.
12-18-2010 09:27 AM
Here you go.
::cisco::eem::event_register_syslog occurs 1 pattern ".*LINEPROTO-5-UPDOWN.*FastEthernet3.*"
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
set mail_pre "Mailservername: myusername@providerDomain:mypassword@providerSMTP\n"
append mail_pre "From: myusername@providerdomain\n"
append mail_pre "To: myusername2@providerDomain2\n"
append mail_pre
append mail_pre "Subject: Check VOIP ATA\n\n"
append mail_pre "Please check VOIP ATA, something not working properly\n\n"
set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]]
if [catch {smtp_send_email $mail_msg} result] {
error $result $errorInfo
}
Save this to a file that ends with ".tcl" (e.g. interface-down-fritz.tcl), then copy it to your EEM policy directory on your router (i.e. the one specified in "event manager directory user policy"). Then register the policy with the command "event manager policy interface-down-fritz.tcl".
12-18-2010 08:20 AM
This is a known limitationwith SMTP AUTH and EEM. An enhancement request, CSCsv24106, was filed to allow for escaping the '@' in a username. However, I've looked over the code in 15.1(2)T, and it appears that the username with the '@' will be properly understood, provided you're using Tcl. If you use applets, then it will not work. If you post your applet, I can convert it to a Tcl policy for you.
12-18-2010 08:39 AM
Thank you Joseph for your reply.
Here it's a sample, i have other that look like this.
If you can give back an example i will learn tcl also
Thank you in advance!
Sandro
event manager applet interface-down-fritz
event syslog occurs 1 pattern ".*LINEPROTO-5-UPDOWN.*FastEthernet3.*"
action 1.0 mail server "myusername@providerDomain:mypassword@providerSMTP" to "myusername2@providerDomain2" from "myusername@providerdomain" subject "Check VOIP ATA" body "Please check VOIP ATA, something not working properly"
12-18-2010 09:27 AM
Here you go.
::cisco::eem::event_register_syslog occurs 1 pattern ".*LINEPROTO-5-UPDOWN.*FastEthernet3.*"
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
set mail_pre "Mailservername: myusername@providerDomain:mypassword@providerSMTP\n"
append mail_pre "From: myusername@providerdomain\n"
append mail_pre "To: myusername2@providerDomain2\n"
append mail_pre
append mail_pre "Subject: Check VOIP ATA\n\n"
append mail_pre "Please check VOIP ATA, something not working properly\n\n"
set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]]
if [catch {smtp_send_email $mail_msg} result] {
error $result $errorInfo
}
Save this to a file that ends with ".tcl" (e.g. interface-down-fritz.tcl), then copy it to your EEM policy directory on your router (i.e. the one specified in "event manager directory user policy"). Then register the policy with the command "event manager policy interface-down-fritz.tcl".
12-18-2010 09:36 AM
Thank you again! Hope you could help me with this one too, i understand now how to look for UPDOWN of ports, but not how to for a cronjob like this:
event manager applet sendmyip
event timer cron cron-entry "*/30 * * * *"
Is there or on cisco a reference for the first line command (i mean the check that will start the policy)?
I don't want to ask more, i prefer to learn
Anyway i will test it soon, i have to fix this quickly!
Sandro
12-18-2010 09:40 AM
12-18-2010 11:17 AM
Hello again,
i got this in my tests:
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: wrong 4th line format.
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: usage: Cc:
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: while executing
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: "smtp_send_email $mail_msg"
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: invoked from within
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: "$slave eval $Contents"
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: (procedure "eval_script" line 7)
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: invoked from within
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: "eval_script slave $scriptname"
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: invoked from within
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: "if {$security_level == 1} { #untrusted script
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: interp create -safe slave
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: interp share {} stdin slave
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: interp share {} stdout slave
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: ..."
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: (file "tmpsys:/lib/tcl/base.tcl" line 50)
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: Tcl policy execute failed:
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: wrong 4th line format.
09:10:34: %HA_EM-6-LOG: send-my-ip.tcl: usage: Cc:
I left the fourth line blank as you gave me. Maybe i have to put a Cc: without address? I looked in the other link for tcl eem and i think that declare the line it's mandatory.
Is that true?
Thank you!
12-18-2010 12:57 PM
Yes, the conversion left out the mandatory Cc: field. Change the empty append line to:
append mail_pre "Cc: \n"
Then that should work.
12-20-2010 03:01 AM
Hello again Joseph,
thank you again. Now it works correctly. I didn't try without any cc address, i putted the same as the sender for a test.
But do you use a program to convert an applet to a tcl?
Bye!
Sandro
12-20-2010 11:24 AM
Yes, we have a web-based tool internally we can use. I typically do it for simple applets as it saves me time typing :-).
12-20-2010 12:12 PM
Cool, i hope that a time cisco will share this with us too!
Bye!
10-16-2012 03:08 AM
Hi Joseph,
We aim to send email to our mail server once access-list changed, so I followed eveything as your instructed to send email from the router to our mail server.I have created a test directory and save scrip with.tcl then push it to router. We are getting the following error. could you look into my script and show us the correct way.
many thanks.
3845-Dial-A#sh event manager directory user policy
flash:/Test/access-list-changed.tcl
3845-Dial-A(config)#event manager policy flash:/Test/access-list-changed
Embedded Event Manager configuration: flash:/Test/access-list-changed does not have valid policy extension
3845-Dial-A(config)#event manager policy flash:/Test/access-list-changed.tcl
Register event failed:couldn't read policy file: permission denied
Embedded Event Manager configuration: failed to retrieve intermediate registration result for policy
flash:/Test/access-list-changed.tcl: Unknown error 0
::cisco::eem::event_register_syslog occurs 1 pattern "ip access-list extended"
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
set mail_pre "10.1.1.1:me@bank.com:M123@bank.com" SMTP\n"
append mail_pre "From: me@bank.com\n"
append mail_pre "To:admin@bank.com\n"
append mail_pre
append mail_pre "The ACL on this router have changed\n\n"
set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]]
if [catch {smtp_send_email $mail_msg} result] {
error $result $errorInfo
}
10-18-2012 07:28 PM
You need to configure:
event manager directory user policy flash:/Test
event manager policy access-list-changed.tcl
11-22-2012 07:58 AM
Hello Joseph,
I read your excellent guide and I thank you for your efforts!
I am not sure about couple of things though:
- @providerSMTP is it an IP address or a FQDN
Here is the current config:
event manager directory user policy "flash:/tcl"
event manager applet Email
event timer watchdog time 28800
action 1 syslog priority notifications msg "Manual backup completed"
action 2 policy Email.tcl
event manager policy Email.tcl
dir flash:tcl
Directory of flash:/tcl/
11 -rw- 665 Nov 22 2012 17:40:36 +02:00 Email.tcl
Is there anything else I forgot?
Many thanks!
11-22-2012 08:01 AM
It is best if the SMTP server is an IP address. However, in newer versions of IOS, both an IP and an FQDN will work (provided the device is configured with a DNS server).
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