Networking

Send e-mail with your Cisco router

Did you know your Cisco router could send you an e-mail? Until recently, I would have said that it wasn't possible, but today, I'll show you how to do it. And we won't stop there: I'll tell you where to find some other scripts that you can use on your Cisco router.

Did you know your Cisco router could send you an e-mail? Until recently, I would have said that it wasn't possible, but today, I'll show you how to do it. And we won't stop there: I'll tell you where to find some other scripts that you can use on your Cisco router. Let's see how the Cisco IOS Tool Command Language (TCL) can make your Cisco administration easier.

A while ago, I wrote an article introducing TCL -- "Get to know Cisco's Tool Command Language (TCL)" -- and I told you how you can create your own scripts using TCL. To run TCL, your router needs to be running Cisco IOS 12.3(2)T or later.

While TCL offers many uses for your Cisco router, it needs to be able to communicate with the Cisco IOS. Traditionally, when an event happens on a Cisco router, it sends that event to a management station on your network for some subsequent action. However, with Cisco's introduction of the Embedded Event Manager (EEM), Cisco routers now have more intelligence and can take actions on their own.

Cisco originally released EEM 1.0 in IOS versions 12.0(26)S and 12.3(4)T. Today, with IOS versions 12.4(2)T, 12.2(31)SB3, 12.2(33)SRB, we're up to EEM version 2.2, and we've gained many features along the way. To learn more, check out Cisco's Embedded Event Manager Overview.

I suspect that TCL and EEM sound only moderately interesting to most of you because, like any scripting language, it can be difficult to envision what you can do with it. To help you understand the power of EEM, Cisco has created the Embedded Event Manager (EEM) Scripting Community.

Thanks to this site, you can not only download many useful scripts, but you can also submit your own to share with other Cisco users. Kudos to Cisco for this excellent resource!

Send e-mail with your router

To better understand the uses of TCL and EEM, let's look at an example. Here's a simple demonstration of how a router can send an e-mail that contains the output of the show version command.

First, I went to the EEM Scripting Community and downloaded the Send Email script. I unzipped the script and ended up with a simple text file called Sendmail.tcl.

Next, I stated my TFTP server on my PC, and I used TFTP on the router to transfer the modified script from my PC to the router's flash. Figure A shows you what it looked like.

Figure A

Figure A

Next, I ran the following command while in Global Configuration Mode:

Router(config)# event manager directory user policy flash:
Then, according to the instructions included in the script's comments, I set the following environmental variables on the router to fit my particular configuration (still in Global Configuration Mode), as shown in Figure B:
Router(config)#

event manager environment _email_server 10.10.10.10

Router(config)#

event manager environment _email_from router-123@cisco.com

Router(config)#

event manager environment _email_to noc@cisco.com

Figure B

Figure B

Next, I registered the script using the following command:

Router(config)# event manager policy sendmail.tcl
Finally, I ran the script using the event manager run sendmail.tcl command. If all goes well, there's no output. Figure C shows the e-mail message.

Figure C

Figure C

You can also modify this script to run on triggered events. For example, there's a script called showtech that you can use to e-mail the output from the show tech-support command directly to Cisco or to yourself. For more information, check out Cisco's video tutorials on using TCL/EEM router scripts.

More uses for TCL and EEM

While this article has focused on using TCL and EEM to send an e-mail with your router, I want to stress that there are so many more practical uses for TCL and EEM with the Cisco IOS. For example, one of the most useful things you can do with TCL and EEM is use a set of diagnostic scripts dubbed IOS Service Diagnostics. Such scripts are available for OSPF, BGP, and QoS.

With these scripts running on your router, when abnormal events occur (such as losing an OSPF Neighbor), your router can automatically attempt to diagnose the issue, perhaps take action to solve it, or, if nothing else, notify you of the issue along with all of the relevant information needed to resolve it. In other words, the scripts can provide for a shorter Mean Time To Repair (MTTR) -- which equates to cost savings. In addition, the scripts can increase network uptime, quickly identify root causes, and automatically collect network troubleshooting data.

Here are some of the other interesting scripts available:

  • Memory Health
  • Power and Temperature Health
  • Composite Device Health -- Interface Errors
  • HSRP State Change
  • L3 Path Failure Detection -- EIGRP Neighbor Change
  • VPN Failure Detection
  • WAN Load Alarm

Conclusion

According to Cisco's IOS Service Diagnostic Web site, Cisco plans on introducing a management interface to help administrators manage these types of scripts on Cisco routers. I look forward to trying that out as soon as it's available. In the meantime, we have a lot of powerful scripts available to test and learn about. In fact, you could even write your own!

What do you want your router to troubleshoot or notify you about today? Add your ideas in this article's discussion.

Want to learn more about router and switch management? Automatically sign up for our free Cisco Routers and Switches newsletter, delivered each Friday!

15 comments
isharief
isharief

great article , very powerful tool & an experiended writer , now is there a script to change static routes upon a failure of serial interface

BBPellet
BBPellet

Now all cisco needs to do is be able to alert the coffee pot that my cup is low! :)

madhukar_m
madhukar_m

I configured router as per instructed , but i am not able to receive mails, even mails are not in my smtp server que. how to check on router. Mm

dpsdevda
dpsdevda

firwall ipx 527 configuration comend $ backup of router for 3600 serirse

nacht
nacht

Why on earth would you want your router to do anything but routing? If you're in a business environment, you should be monitoring your router with something else (syslog anyone?) Not to mention the vulnerabilities that are opened as you add more and more functions to your device. Running scripts on a router sounds like a terrible idea, akin to running antivirus, antispam, and who knows what else on a firewall. If a device is performing functions other than its primary one, it's probably not doing anything perfectly.

pkianka
pkianka

This is a nice sounding feature that I didn't know was available. I'd be interested in using this to alert me when a router with two connections to the Internet has failed from one to the other using the IP SLA monitor feature.

agonza07
agonza07

You can also set up much simpler emails. For example, I have some where it let's me know if an interface went down, or if someone made a configuration change: event manager applet test event syslog pattern ".*CONFIG_I.*" action 1.0 mail server "mail.whateveremailserver.com" to "dude@test.com" from "CiscoRouter@BranchOffice.com" subject "Test message" body "Someone made configuration changes" If an interface went down I just watch the console output by: event syslog pattern ".*UPDOWN.*Serial0/0/0:0.*changed state to down"

khansen
khansen

There are a few things I'd like to do with TCL on their desktop line (i.e. 3750, 2960, etc) that would come in handy.

wratholix
wratholix

After some reading up on these i really like the scripts. i was not aware of it before.

robo_dev
robo_dev

And loading CISCO IOS on a coffee maker would require you to purchase the appropriate license for that feature set. It would take fourteen hours of work to configure the device produce one cup of coffee. The coffee maker would either make no coffee at all, or replicate hundreds of pots of coffee on all the machines on the network, until the coffee supplies were exhausted. The coffee maker would cost $14,000 and only come in one color, teal blue.

jtmapsuk
jtmapsuk

There is quite a lot a bussiness can benefit from the EEM feature. In my building we have more than 1500 plasma screens running IPTV. We now use EEM scripts to shut down the IPTV ports on the edge switches for 10 minutes every night so the TVs automatically shut down when they lose the IP signal. This saves energy and we didnt have to pay for some fancy gizmo to turn the TVs off every night.

jtmapsuk
jtmapsuk

Cisco supports EEM on 3750 switches (IOS 12.2(34) and above. I've used IOS based EEM on 3750 and 4500 LAN switches for varous things including sending e-mail when an event is triggered. TCL and EEM are very powerfull tools and I hope Cisco will in the near future include additional events supported by the easier IOS based EEM.

BBPellet
BBPellet

ROFLAO....ok...I deserved that one!

douglasemc
douglasemc

this might be an out of place question but, how can you configure an ASA 5500 to send you notification emails

Camputech
Camputech

I have a cisco 3750 with 12.2)50SE2 and i am not able get this script running. "event manger directory" command is not avaliable. any suggestions?

Editor's Picks