Alarm active duration in reporting module

Hi,
I would like to display the active duration of alarms in a report, however when I used the activeDuration available under the alarm journal query I get times that are increasing even though alarms are cleared. It looks like maybe it’s giving me the time since it was active, rather than the amount of time it was active for. I’ve tried using cleartime- activetime to get the duration but this doesn’t work either as they don’t appear in the same row in sql. I’ve had a play around at the sql end but am not having any joy there either (though my sql skills are pretty basic)
Is there anyway of getting the active duration out easily?

1 Like

I don’t know if there’s a built-in or recommended method but this script could get you started.

# Query the alarm journal (change filter options as required)
events = system.alarm.queryJournal()

# Get a dict where the key is alarm id and the value is a list of corresponding events.
alarms = {}
for e in events:
	if e.id in alarms: alarms[e.id].append(e)
	else: alarms[e.id] = [e]

# Get the active duration for each alarm id
for id in alarms:
	actTime = None
	clrTime = None
	alarmEvents = alarms[id]
	for e in alarmEvents:
		# Get active time
		d = e.activeData
		if d != None:
			actTime = d.timestamp
		# Get cleared time
		d = e.clearedData
		if d != None:
			clrTime = d.timestamp
	# Calculate active duration
	if actTime != None and clrTime != None:
		dp = alarmEvents[0].getDisplayPathOrSource()
		print dp, '->', (clrTime - actTime) / 1000, 'seconds'
2 Likes

Won’t a keychain expression work in this case? I am having the same issue as above and am curious as to why a Alarm Journal query as a client shows the active duration properly yet the reporting module doesn’t

1 Like