allAlarmData = system.alarm.queryJournal(journalName='BypassJournal', startDate=beginningOfDay, endDate=endOfDay, includeSystem=False)
dictOut = {}
# Set key names for datapoints associated with each UUID
keys = ['active', 'cleared', 'name']
for alarmRecord in allAlarmData:
eventTime = alarmRecord.get(CommonAlarmProperties.EventTime)
alarmActive = alarmRecord.get(CommonAlarmProperties.ActiveTime)
alarmCleared = alarmRecord.get(CommonAlarmProperties.ClearTime)
alarmName = alarmRecord.get(CommonAlarmProperties.DisplayPath)
uuid = alarmRecord.id
# GET LABEL
alarmLabel = alarmRecord.get(CommonAlarmProperties.Label)
Using for some reason only ever returned None. I also then tried alarmRecord.label but that returned u'Alarm'. I wonder if it has something to do with how I configured the alarm - it's in a UDT and is like this -
where CL.getalarmLabel does a .get on a top level dictionary object This works for viewing the alarm label in the status table and journal table but I seem to be doing it incorrectly in the script. I must be missing something simple but I can't figure it out. What is going wrong?
I was suspecting it has something to do with the runScript. I recall an issue where I tried to use a runScript to generate the body of an email in a scheduled report and it was emailing the text runScript("Blah")` instead of executing. It does seem odd since it is coming through correctly on my alarm status and journal tables. Not that reporting and alarms modules are related but that runScript is prone to wonkiness in certain contexts.
I am considering making a dataset and using a lookup expression instead and perhaps that will fair better as well.
It should be alarmLabel = alarmRecord.get(CommonAlarmProperties.Label) or alarmRecord.label right? That part is correct?
Here's my attempt using the alarmRecord.label
. The ones with CL 14, 5, 2 i would have expected something other than Alarm.
Feels weird since at this point its in the journal it's in a db and this should just be getting queried directly. So I suspect it's something in the script so here is my coworkers full script -
from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties
start = '2022-06-04 00:00:00'
end = '2022-06-06 00:00:00'
beginningOfDay = system.date.parse(start)
endOfDay = system.date.parse(end)
allAlarmData = system.alarm.queryJournal(journalName='BypassJournal', startDate=beginningOfDay, endDate=endOfDay, includeSystem=False)
dictOut = {}
# Set key names for datapoints associated with each UUID
keys = ['active', 'cleared', 'name', 'label']
for alarmRecord in allAlarmData:
# Get Data points
eventTime = alarmRecord.get(CommonAlarmProperties.EventTime)
alarmActive = alarmRecord.get(CommonAlarmProperties.ActiveTime)
alarmCleared = alarmRecord.get(CommonAlarmProperties.ClearTime)
# Note that I use displaypath instead of name. To each their own. ;)
# alarmName = alarmRecord.getName()
alarmName = alarmRecord.get(CommonAlarmProperties.DisplayPath)
alarmLabel = alarmRecord.label
# The UUID is what ties it all together.
uuid = alarmRecord.id
# Chech if the UUID exists. Make an entry for it if it does not.
if uuid not in dictOut.keys():
# Keys full of Nones.
dictOut[uuid] = {key:None for key in keys}
# Set the alarm name, if it doesn't exist
if not dictOut[uuid]['name']:
dictOut[uuid]['name'] = alarmName
if not dictOut[uuid]['label']:
dictOut[uuid]['label'] = alarmLabel
# Set the alarm active time, if it doesn't exist
if alarmActive and not dictOut[uuid]['active']:
dictOut[uuid]['active'] = alarmActive
# Set the alarm cleared time, if it doesn't exist
if alarmCleared and not dictOut[uuid]['cleared']:
dictOut[uuid]['cleared'] = alarmCleared
headers = ['Alarm Occured At', 'Alarm Cleared At', 'Alarm Name', 'Alarm Description']
rows = []
for values in dictOut.values():
rows.append([values[key] for key in keys])
# Create the dataset
dataset = system.dataset.sort(system.dataset.toDataSet(headers, rows), 'Alarm Occured At')
# Print to file etc
util.printDataSet(dataset)
You should also be able to use alarmRecord.properties to get a list of all properties on the record, which "should" be able to point you towards what actually has the value you're looking for.