10.2 Entering Outages by JavaScript

JavaScript can be used to create outages via a client automation script or custom client operation. This can be useful when outage data is obtained from an external source, such as a service provider, on a regular or scheduled basis.

NOTE:Real-time breaches are not created for manual outages as they would for real-time outages. However breaches are simulated and included for manual outages in SLA reports. For more information, see Section 10.3, Understanding Manual Outages in Breach Reporting.

The following script snippet illustrates how a script automation can create outages based on alarm information. This script expects a start and end date as alarm columns (mDateTimeOpened and mDateTimeClosed) as these are required for a manually created outage. alarm is any alarm passed as a parameter when the automation script is executed. The element on which the outage is created is defined by alarm.element and is the affected element of the alarm.

formula.log.info("autooutage starts " );
dateformat="yyyy-MM-dd hh:mm:ss";
var formatter=new java.text.SimpleDateFormat(dateformat);

try {
} catch (Exception) {
     formula.log.error("Error parsing startdate " + Exception); 
     startdated=new Date();
try {
} catch (Exception) {
     formula.log.error("Error parsing enddate " + Exception); 
     enddated=new Date();

TTreason="res:" + alarm.getField('Description');

var alarmFields=new java.util.Hashtable;
alarmFields.put("myDate", new java.util.Date())
alarmFields.put("myOS", "Windows XP")
alarmFields.put("myID", "101")
var alarmFieldbyteArray = null    
var bos = new java.io.ByteArrayOutputStream();      
var oos = new java.io.ObjectOutputStream(bos);      
alarmFieldbyteArray = bos.toByteArray();
var from = new java.util.Date()      
var to = from.getTime() + 100000
// (required) params[0] -> dname as string (required)
// (required) params[1] -> from date as long
// (required) params[2] -> to date as long
// (required) params[3] -> type as int (0 = GENERATED, 1 = SUPPRESS, 2 = OUTAGE)
// (required) params[4] -> reason as string
// (optional) params[5] -> extra alarm columns/values as serialized HashTable key/value pairs. 

try {      
  myelement.perform( session, "Create|Outage", [], 
       [myelement.getDName(), startdated.getTime(), enddated.getTime(), 2, TTreason, alarmFieldbyteArray ])
} catch (Exception) {
   formula.log.error("Error adding outage 1 " + Exception); 
   try {      
      myelement.perform( server.automationSession, "Create|Outage", [], 
             [myelement.getDName(), startdated.getTime(), enddated.getTime(), 2, TTreason, alarmFieldbyteArray ])
   } catch (Exception) {
        formula.log.error("Error adding outage 2 " + Exception); 
formula.log.info("autooutage ends " + TTreason + " " +  alarm);