09-30-2015 09:09 PM
Hi,
I am trying to create a script that will send an email when a specific action occurs.
Everything works except for the sendemail portion.
I am knew to EEM scripting and may not understand certain concepts.
Please forgive my lack of knowledge on that part.
I did many google search and still can't seem to understand.
Part of my script that does not work :
::cisco::eem::event_register_none
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
I get the following error :
invalid command name "::cisco::eem::event_register_none"
Just adding those lines directly to (tcl) gives the same result.
I am sure I am missing a step.
Embedded Event Manager Version 4.00
I would also like to send as an attachment the "sh run config".
Thanks for your Help
10-01-2015 04:46 AM
Hi there,
You are attempting to load a specific tcl library '::cisco::eem::event_register_none', so the you need to prepend the line with so that it reads:
namespace import ::cisco::eem::event_register_none
That said you are already importing the specific library with the command below it. Just delete it and use:
namespace import ::cisco::eem::* namespace import ::cisco::lib::*
cheers,
Seb.
10-01-2015 08:36 AM
Hi,
After many tests, I finally found how this works.
Wanted to share to others who might go through the same process.
You need to create your file.
For this case It is CheckATA.tcl
You need to copy the file on your router using FTP or whatever method you wish.
For this I created the following directory:
2911-Router#cd flash0:
2911-Router#mkdir flash0:/Scripts/
Then you need to register it in the event manager policy :
2911-Router#config t
2911-Router(config)#event manager policy flash0:/Scripts/CheckATA.tcl
This places the file in the tmpsys:/eem_temp/ directory.
To verify the file is correct you need to do the following :
2911-Router#more tmpsys:/eem_temp/CheckATA.tcl
Then you need to register the policy in EEM :
2911-Router(config)#event manager policy CheckATA.tcl
To run it :
2911-Router#event manager run CheckATA.tcl
If you change the file, you need to recopy it to the correct folder and then you must remove the policy from the event manager and recreate it.
2911-Router(config)#no event manager policy CheckATA.tcl
2911-Router(config)#event manager policy CheckATA.tcl
Now my file works. I still have some minor bugs, but I should resolve it.
I am still wondering how to send attachments, but I will keep searching.
Thanks,
Stéphane
10-01-2015 02:10 PM
Hi,
This is now working. I have corrected all my little issues except for sending a file as attachment.
Here is what I have :
set mail_pre "Mailservername: $_email_server\n"
append mail_pre "From: $_email_from\n"
append mail_pre "To: $_email_to\n"
append mail_pre "Cc: \n"
# Get the router name
set var_hostname [info hostname]
append mail_pre "Subject: Config change on router: $var_hostname\n\n"
if [catch {cli_exec $cli1(fd) "show archive log config all"} _cli_result] {
error $_cli_result $errorInfo
} else {
append mail_pre "$_cli_result\n\n"
}
append mail_pre "MIME-Version: 1.0\n"
append mail_pre "Content-type: multipart/mixed; boundary=\"EEM_email_boundary\"\n"
append mail_pre "\n--EEM_email_boundary\n\n"
append mail_pre "\n--EEM_email_boundary\n"
append mail_pre "Content-Type: application/octet-stream\n"
append mail_pre "Content-Transfer-Encoding: Base64\n"
append mail_pre "Content-Disposition: attachment; filename=\"$var_hostname.conf\"\n\n\n"
if [catch {open "flash0:/$var_hostname.conf"} result] {
error $result $errorInfo
}
set fd $result
# Encode that data using the built-in base64 library.
set email_b64 [::base64::encode [read $fd]]
close $fd
# ------------------------------------------------------------------------
# Send the running config by email
# ------------------------------------------------------------------------
set mail_body_mime "\n--EEM_email_boundary--"
set mail_msg [format "%s%s%s" $mail_pre $email_b64 $mail_body_mime]
if [catch {smtp_send_email $mail_msg} result] {
error $result $errorInfo
}
I do get the email, but no attachment.The attachment is encoded in the body of the message and un readable.
Thanks for your help,
Stéphane
10-02-2015 01:49 PM
Hi,
Got this working.
Thanks,
Stéphane
09-26-2016 02:27 PM
Stephanie,
Would mind sharing your script? I am trying to get something going and am having some difficulties. My goal:
After wr mem, copy config to ftp server. (I am just using the archive function for this)
I am trying to build out an ftp daily test, and then email me if the test fails.
I would greatly appreciate any help that you are willing to provide.
Ken
ktwilli888@gmail.com
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