Setting Up Email Alerts in ManageWise the Old-Fashioned Way
Novell Cool Solutions: Trench
By Randy Bender
Digg This -
Posted: 18 Jun 2003
As you may know, ZENworks for Servers will now send alerts via e-mail (you configure it when working with the Alarm Disposition), but that's a fairly new enhancement and may not be available to all of you yet. Here's how Randy Bender set up alarms in the old days.
Important Update: Be sure you change Randy's e-mail address to your own in the batch file if you try this tip. Randy reports that someone must be using this tip because he keeps getting messages from Managewise@console.com...
Here is how I setup e-mail alerting in ManageWise using a DOS batch file and a terminal emulation program called Tera Term Pro. I also included Tera Term Pro and some sample files in the zipfile.
My notes were dated February 2000, I wish I would have thought to post this a couple of years ago...
I originally created this solution to enable ManageWise to send alerts via e-mail without having to purchase an expensive third-party add-on product. By configuring the alarm disposition table, ManageWise (and ZENWorks for Servers) allows you to launch a program when it captures an alert.
This solution is created with a DOS batch file and a free terminal emulator program called Tera Term Pro. Tera Term is a nice utility that allow you to connect to any host through any port. It also allows you to execute a script when it connects to the host.
First I will describe the flow of the solution (I will list the details next).
- Network component sends an SNMP trap to the console.
- The console captures the trap and looks in the Alarm Disposition table to see if there are any actions specified for this event.
- The Alarm Disposition table is configured to launch a DOS batch file. It also sends the appropriate information as parameters; %o (Object id), %v (seVerity), %t (alarm Type), and %s (alarm Summary).
- The batch file, called sendalarm.bat, is executed from the workstation which is running the console. The function of this program is to create three small text files called FROM.TXT, SUBJECT.TXT and SUMMARY.TXT. These files are used by in the Tera Term script when sending the e-mail.
- After sendalarm.bat creates the necessary files, it launches ttermpro.
- Tera Term connects to an SMTP server by telnet to port 25. It is also configured to run a script called alarm.ttl ('ttl' is short for "Tera Term Language"). This simple script send the appropriate commands to the SMTP server to spoof an e-mail message which includes a description of the alarm.
Here are the details of the batch file and Tera Term script.
Sendalarm.bat is the batch file that is defined in the alarm disposition table and executed by the console. This is the process that creates the format of the e-mail and calls the terminal application (Tera Term) which sends the e-mail. It creates three files; FROM.TXT, SUBJECT.TXT and SUMMARY.TXT which are used in the Tera Term script when sending the e-mail.
The alarm disposition is configured to send the appropriate parameters also: C:\MW\NMS\BIN\SENDALARM.BAT %o %v "%t" "%s". The quotes were needed around %t and %s since these variables were strings and if the quotes were not included, the batch file would see each word in the string as a separate variable.
Rem ***** SENDALARM.BAT
Rem ***** Parameters:
Rem ***** %1: Object ID
Rem ***** %2: Severity code
Rem ***** %3: Alarm Type
Rem ***** %4: Alarm Summary
Rem ***** Start out in the correct directory.
Rem ***** Create a FROM: line to indicate the affected object *****
Rem ***** Erase the previous FROM.TXT file
Rem ***** Each managed node in the network is assigned a numeric ID
Rem ***** when its discovered. This number is used to identify the
Rem ***** name of the node that is sending the alert. These IDs are
Rem ***** assigned randomly and the only way to determine what ID
Rem ***** is assigned to a particular node is to look in the node database
Rem ***** or by trial and error (I set an alarm for loading an NLM and
Rem ***** setup a batch file to simple report the Object ID).
if '%1'=='173' goto server1
if '%1'=='728' goto server2
if '%1'=='3' goto server3
Rem ***** Use the default of "managewise" if id not found. *****
echo ManageWise > from.txt
echo From: SERVER1 > From.txt
echo From: SERVER2 > From.txt
echo From: SERVER3 > From.txt
Rem ***** Create txt file containing the Alarm Summary
Rem ***** Erase the previous SUMMARY.TXT file
Rem ***** Echo the contents of the fourth parameter passed into this file.
echo %4 > summary.txt
Rem ***** Create the Subject line *****
Rem ***** Erase the previous FROM.TXT file
Rem ***** Start with a default error condition *****
echo Error with MW severity code > Subject.txt
Rem ***** Echo appropriate error level as the subject line
Rem ***** These error codes (1-5) are system defaults.
if '%2'=='1' goto unknown
if '%2'=='2' goto info
if '%2'=='3' goto minor
if '%2'=='4' goto major
if '%2'=='5' goto critical
Rem ***** The subject line of the e-mail will be the error level of the
Rem ***** alert followed by the type of alert.
echo Subject: Unknown Alert: %3 > Subject.txt
echo Subject: Informational Alert: %3 > Subject.txt
echo Subject: Minor Alert: %3 > Subject.txt
echo Subject: Major Alert: %3 > Subject.txt
echo Subject: Critical Alert: %3 > Subject.txt
Rem ***** Run Tera Term to send the alert *****
Rem ***** Enter the IP address of the SMTP host and specify port 25
Rem ***** for the connection. "/m=alarm" specifies that the "alarm.ttl"
Rem ***** script is to be used by Tera Term upon connection.
ttermpro 192.168.1.1:25 /m=alarm
ALARM.TTL is a Tera Term macro file (ttl = Tera Term Language). This file scripts the commands necessary to send the message to your SMTP server. The "sendln", "sendfile" and "closet" commands are part of the Tera Term language. The "helo", "mail from:", "rcpt to:", "data", and "." are RFC compliant SMTP commands. Essentially, Tera Term is sending the appropriate SMTP commands to the e-mail server to create and send the message.
The only way that I found to supply unique data to this script was to create the messages in files (subject.txt, from.txt, summary.txt) and use Tera Term's "sendfile" command.
This is where you setup additional recipients of the e-mail (add/delete sendln 'rcpt to:<user>').
sendln 'helo Managewise.AppNet'
sendln 'mail from:<com.console@ManageWise>'
sendln 'rcpt to:<email@example.com>'
sendln 'rcpt to:<firstname.lastname@example.org>'
sendfile 'c:\sa\Subject.txt' 0
sendfile 'c:\sa\From.txt' 0
Sendfile 'c:\sa\summary.txt' 0
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com