9.2 Scripting Functions in Automation Tasks

Automation events can trigger an alert when a network event occurs that might require intervention. Scripting capabilities are available to define more complex actions. Defining and Managing Automation Events in the Operations Center 5.6 Server Configuration Guide describes the automation features.

9.2.1 Accessing SLA Information

Table 9-2 lists the objects that are available when defining a script action for an SLA objective breach. It is possible to mine Agreement Name, Reason, Compliance, etc., from these objects:

Table 9-2 Objects for Accessing SLA Information

Object

Description

objectiveContext

This context provides information about the defined objective/offer.

computeContext

This real-time context provides information about the real time objective/offer instances.

var ObjectiveName = objectiveContext.getObjectiveType().getName()
var SLAName = objectiveContext.getOfferDefinition().getName()
var reason = computeContext.getObjectiveInstance().getReason()
var ObjectiveHealth = computeContext.getObjectiveInstance().getHealth()

In the following sample script, messages display in the formula trace file when an objective breach occurs:

formula.log.info( "SLA  = " + objectiveContext.getOfferDefinition().getName()) 
formula.log.info( "Objective  = " + objectiveContext.getObjectiveType().getName()) 
formula.log.info("Obj Health = " + computeContext.getObjectiveInstance().getHealth()); 
formula.log.info("Objective Breach Reason = " + computeContext.getObjectiveInstance().getReason());

9.2.2 Using Event Variables

All script-based automations have an event variable that represents the event that triggers the automation. Table 9-3 describes event variable fields.

Table 9-3 Event Variable Fields

Field

Description

sourceEvent

The name of the triggered automation event.

eventCondition

The current event condition.

priorCondition

The event condition before the automation event occurred.

eventType

The type of automation filter that triggered the event:

  • EventType_ConditionChange

  • EventType_AlarmAdded

  • EventType_AlarmRemoved

  • EventType_AlarmOperationPerformed

  • EventType_ElementOperationPerformed

  • EventType_AlarmChange

element

The element to which the triggered automation action is assigned.

createTime

The time the automation event occurred,

9.2.3 Sample Code

The following sample code shows the fields documented in Table 9-3:

package com.mosol.Formula.Automation;

import java.util.EventObject;
import com.mosol.ORB.Formula.ElementCondition;
import com.mosol.util.StringMap;


public class AutomationEvent extends EventObject
{
   public String what = null ;
   public Automation automation = null;
   public EventObject sourceEvent = null ;
   public ElementCondition eventCondition = null ;
   public ElementCondition priorCondition = null;
   public AutomationElement element = null ;
   public StringMap eventDataObjects = new StringMap() ;
   public int eventType = 0 ;
   public long createTime = System.currentTimeMillis();

   static public final int EventType_ConditionChange = 1 ;
   static public final int EventType_AlarmAdded = 2 ;
   static public final int EventType_AlarmRemoved = 3 ;
   static public final int EventType_AlarmOperationPerformed = 4 ;
   static public final int EventType_ElementOperationPerformed = 5 ;
   static public final int EventType_AlarmChange = 6;

   public AutomationEvent( String what,
                           Automation automation,
                           EventObject sourceEvent,
                           ElementCondition eventCondition,
                           AutomationElement element,
                           int eventType )
   {
      this( what, automation, sourceEvent, eventCondition, element, eventType, null );
   }

   public AutomationEvent( String what,
                           Automation automation,
                           EventObject sourceEvent,
                           ElementCondition eventCondition,
                           ElementCondition priorCondition,
                           AutomationElement element,
                           int eventType )
   {
      this( what, automation, sourceEvent, eventCondition, priorCondition, element, eventType, null );
   }

   public AutomationEvent( String what,
                           Automation automation,
                           EventObject sourceEvent,
                           ElementCondition eventCondition,
                           AutomationElement element,
                           int eventType,
                           String eventDataName,
                           Object eventData )
   {
      this( what, automation, sourceEvent, eventCondition, element, eventType, null );
      eventDataObjects.put( eventDataName, eventData );
   }

   public AutomationEvent( String what,
                           Automation automation,
                           EventObject sourceEvent,
                           ElementCondition eventCondition,
                           AutomationElement element,
                           int eventType,
                           StringMap eventDataObjects )
   {
      this(what, automation, sourceEvent, eventCondition, null, element, eventType, eventDataObjects);
   }
   public AutomationEvent( String what,
                           Automation automation,
                           EventObject sourceEvent,
                           ElementCondition eventCondition,
                           ElementCondition priorCondition,
                           AutomationElement element,
                           int eventType,
                           StringMap eventDataObjects )
   {
      super( sourceEvent.getSource() ) ;
      this.what = what ;
      this.automation = automation ;
      this.sourceEvent = sourceEvent ;
      this.eventCondition = eventCondition ;

      this.priorCondition = priorCondition ;
      this.element = element ;
      this.eventType = eventType ;
      if( eventDataObjects != null )
         this.eventDataObjects = eventDataObjects ;
   }

   public Object getEventObject( String key )
   {
      return eventDataObjects.get( key );
   }
}