MAIL SENDER
From TDiWiki
This script is designed to create an email alert when an Event occurs. The script must be run from an Event Automatic Action.
Version Info: This script makes use of the libPISMTP plugin. ConsoleWorks 4.6 (or later) is required to use the libPISMTP plugin!
Contents |
[edit] Script Properties
Name: MAIL_SENDER
Description: This script will create an email alert when an Event occurs.
Profile: CONSOLE_MANAGER
Timeout: 30 (seconds)
[edit] Run Type
Run as Event Automatic Action
[edit] Script Text
// * Copyright 1999-2012 TDi Technologies, Inc. All rights reserved. *
// * The information in this software is subject to change without *
// * notice and should not be construed as a commitment by TDi. *
// * Created: 2/15/2012 *
loadPlugin("SMTP");
if (action.type == "NEW") {
evtOccName = action[action.type]; // get the name of the event occurence that triggered the script
consoleName = action.console; // get the name of the console the event occurred on
myConsole = Console.get(consoleName);
myEvtOcc = EventOccurrence.get(evtOccName);
myEvent = Event.get(myEvtOcc.actname);
myServer = ServerConfig.get("meta");
// get and format the Event time
var date = new Date(myEvtOcc.acttime*1000);
var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var month = months[date.getMonth()];
var day = date.getDate();
var year = date.getFullYear();
var hours = ("0"+date.getHours()).slice(-2); // add leading zero
var minutes = ("0"+date.getMinutes()).slice(-2); // add leading zero
var seconds = ("0"+date.getSeconds()).slice(-2); // add leading zero
var timestamp = month+" "+day+" "+year+" "+hours+":"+minutes+":"+seconds;
// build the email message
var msg = new Object();
msg.CWServer = "cwserver.domain.com"; // *** put your ConsoleWorks server host name here
msg.server = "mailserver.domain.com"; // *** put your SMTP mail server host name here
msg.fromAddress = "alert@consoleworks.com"; // *** put the from address here
msg.toAddresses = new Array();
msg.toAddresses[0] = "email@inbox.com"; // *** put your to address here
msg.toAddresses[1] = "another.email@inbox.com"; // *** add additional to addresses as needed (remove if not needed)
msg.subject="ConsoleWorks Event: "+myEvtOcc.actname+" has occured on "+consoleName;
msg.body = "A ConsoleWorks Event has occurred.\n";
msg.body += "SERVER: "+ myServer.serverhost + "\n";
msg.body += "PORT: "+ myServer.serverport + "\n";
msg.body += "CONSOLE: "+ myEvtOcc.console + "\n";
msg.body += "ALIAS: "+ myConsole.alias + "\n";
msg.body += "EVENT NAME: "+ myEvtOcc.actname + "\n";
msg.body += "SEQUENCE: " + evtOccName + "\n";
msg.body += "DESCRIPTION: " + myEvtOcc.description + "\n";
msg.body += "SUBSYSTEM: " + myEvent.subsystem + "\n";
msg.body += "CLASS: "+ myEvent.class + "\n";
msg.body += "TIME: " + timestamp + "\n";
msg.body += "PRIORITY: " + myEvtOcc.severitysort + "\n";
msg.body += "SEVERITY: " + myEvtOcc.severity + "\n";
msg.body += "PATTERN: " + myEvent.pattern + "\n";
msg.body += "LINES ABOVE: " + myEvent.lines_above + "\n";
msg.body += "LINES BELOW: " + myEvent.lines_below + "\n";
msg.body += "CONTEXT BEGIN>\n" + myEvtOcc.evtcontext + "\n<Context END\n";
msg.body += "REGEX BEGIN>\n" + myEvtOcc.regexcontext + "\n<REGEX END";
SMTPMailer.send(msg);
}else{
log("CONWRKS", "Error: This is script is intended to be run as an Automatic Action.");
}
[edit] Additional Editing
This script does require you to make some edits before it can be used. After copying the script text into your CWScript inside ConsoleWorks, locate the lines that are marked with "// ***" and follow the instructions that are found there.
[edit] Related Resources
To have this script run as an Event Action, you need to create an Automatic Action to run it. Please see our article on Actions for more information.
