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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Axeda Groovy Script: alarm Object

No ratings

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()

Comments

What is the difference between AlarmFinder and HistoricalAlarmFinder?

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

Version history
Last update:
‎May 25, 2016 11:43 AM
Updated by:
Labels (2)