Operations Center - EMail Selected Alarms

Operations Center - EMail Selected Alarms

While setting up an automation to automatically email out notifications that a particular service has turned critical or a new critical alarm was received is useful, there are other situations where it would be useful to email data from NOC in an adhoc manner.  Sometimes sending the alarm (as an example) is not enough, you would like to provide some other details in the email.  To do this, it would be useful to have the email client open up and automatically and fill in the email with some of the details such as the alarm data.  This blog covers how to create a right-click operation to email one or more alarms.

There have been ways to send emails via java for a long time.   When java 6 was released a new Desktop class was provided that can launch the default browser, email client, as well as opening properly registered files.   For this blog, I will leverage the launching of the email client.

The core of the java script is to get hold of the desktop object:

var desktop = java.awt.Desktop.getDesktop();

then open email:

desktop.mail( uri );

Before we can do that, we need to build the mail message ("uri").   The basic format of the mail message is email address, a subject and the body of the email.  Other options such as CC are available.  Here is an example of what the "uri" variable should look like:

mailto:joe@example.com?cc=bob@example.com&body=hello

For a clientscript right-click on an alarm, the script is automatically provided an "alarms" variable, this is an array of all of the alarms selected.  The first step is to walk through the array of alarms via a for loop.   In my example below, I walk through all of the possible alarm fields.  You may want to change that to pull specific fields.

There is also something specific to email, it has challenges with specific characters in the email.   Due to this I opted to use encode() to clean up the email.  There are probably better ways to clean up the email to exclude special characters, but for the purpose of this blog, this works fine.

//declare a carriage return and line feed
var crlf = "%0D%0A"

//The beginning part of the email such as email address and subject
var msg = "mailto:some@here.com?subject=Operations_Center_Email&body="

//for loop to walk through all of the selected alarms
for( var i=0; i<alarms.length; i++ )
{
//for loop to walk through all of the fields within a single alarm
for( p in alarms[i].properties )
{
//concatenate onto the msg variable the field column name p and value and a cr
msg+= java.net.URLEncoder.encode(p + "=" + alarms[i][p]) + crlf;
}
}

// set up msg, get desktop, call for email client
var uri = java.net.URI( msg );
var desktop = java.awt.Desktop.getDesktop()
desktop.mail( uri )


When you run this as a clientscript right click, the next thing that should happen is that email should open in compose mode (IE: new message), it will be addressed to some@here.com, contain a subject as well as show the individual alarm column names and values in the body of the email message.   You can then edit the email further and hit send.

There are obviously several ways things can be done when leveraging java.   The intent is to provide a example as well as an idea.   Play with it on your Development system.   Any feedback via comments on the blog is appreciated.

- Tobin

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-11-15 18:07
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.