cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Axeda Groovy Script: alarm Object

nishanair
12-Amethyst

Axeda Groovy Script: alarm Object

When an Expression Rule of type Alarm, AlarmExtendedDataChange, AlarmSeverityChange or AlarmStateChange calls a Groovy script, the script is provided with the implicit object alarm.  This example shows how the alarm object can be used.

This Expression Rule uses the CountAlarmsSinceHours Groovy script to check the number of alarms in the past number of hours, and escalate the alarm if more than three alarms have occurred:

IF    ExecuteCustomObject("CountAlarmsSinceHours", 1) < 3

THEN SetAlarmState("ACKNOWLEDGED", "Less than three alarms in the past hour")

ELSE  SetAlarmState("ESCALATED", "THREE OR MORE alarms in the past hour")

Here is the definition of the CountAlarmsSinceHours Groovy script.  The script uses the parameter 'hours' passed from the expression rule and the implicit object 'alarm'.  It returns the number of times the current alarm has occurred within 'hours' hours.

import com.axeda.drm.sdk.Context

import com.axeda.drm.sdk.data.HistoricalAlarmFinder

import java.util.Calendar

import com.axeda.common.sdk.jdbc.DateQuery

// get Date object for an hour ago

Calendar cal = Calendar.getInstance()

cal.add(Calendar.HOUR, -parameters.hours.toInteger())

Date sinceTime = cal.getTime()

HistoricalAlarmFinder findAlarms = new HistoricalAlarmFinder (Context.create())

findAlarms.device = alarm.device

findAlarms.setAlarmName(alarm.name)

findAlarms.date = DateQuery.after(sinceTime)

List matchingAlarms = findAlarms.findAll()

2 REPLIES 2

What is the difference between AlarmFinder and HistoricalAlarmFinder?

ckaminski
13-Aquamarine
(To:nishanair)

AlarmFinder finds currently active alarms, HistoricalAlarmFinder reaches back into history by criteria.

If you're running Axeda Platform version 6.5+, I highly recommend using the V2 API AlarmBridge instead.

Documentation can be found on your instance:

Other examples of the V2 API can be found on Community.  A good example:

More Data with the V2/REST APIs!!

Regards,

-Chris Kaminski

Announcements