6.2 Getting and Setting Alarm Properties

To access a list of properties or fields published by the underlying data source to the alarm, use the properties property of the alarm. For example:

// Print out all the alarm's of the elements tree
var al = element.alarms;

formula.log.info("Alarm count: " + al.length);
for (var i = 0; i < al.length; ++i ) {
    formula.log.info( 'Alarm properties of: ' + al[i] )
    for (var p in al[i].properties) {
      formula.log.info( '   ' + p + ': ' + al[i][p] )
    }
}

To get any property set by the underlying management system, use either the dot notation alarm.property or the array notation alarm[property]. The array notation might be necessary if the property name itself is a reserved word of JavaScript, such as “class”, “in”, or “function.” For example:

var alarm = formula.Elements.alarms[0] // Assume at least one!
writeln( 'Alarm: ' + alarm + ' is attached to ' + alarm.element )

To set a property, assign a value to the right-hand portion of an assignment operation. The two ways to denote property accessors are using dot (.) notation and using array notation ([]). Assigning a property to an alarm exposed in Operations Center scripting engine might result in an actual transaction against a managed resource.

An example:

// Warning, this adds some random field values to a random alarm
// DO NOT use on a production system!
try
{
   var alarm = formula.Elements.alarms[0] // Assume at least one!
   alarm.foo = 'bar'
   alarm[ 'class' ] = 'Zinger'
}
catch( Exception )
{
   formula.log.warn( 'Could not modify alarm: ' + Exception )
}