Alarm Journal Query - Fastest Way to get Event Timestamps

I am trying to get historical alarm data. I'm doing it with the Alarm Journal Query (system.alarm.queryJournal) to avoid different syntaxes and compatibilities across varying databases. I am trying to get the Active, Acknowledged, and Cleared timestamps. However, these timestamps are spread across multiple events. I'm running into performance issues as I am trying to scale this up, for example:

  1. Get all the UUIDs for the time range (at least 30 days, which is could be easily thousands of events)
  2. Get a list of all the unique UUIDs (which is likely still thousands)
  3. Find all the events that match a specific UUID (which is generally 3: active, acknowledge, clear)
  4. Find all the timestamps from the events for my specific UUID
  5. Loop back to Item #3 until we step through all of our UUIDs and get all of our information (once again easily need to loop thousands of times because of Item #2)

Is there an easier or more efficient way of doing this?

Just add .getDataset() to the end of your query. This will reduce the alarm objects to a single and more managable dataset object that has the following seven columns: UUID, Qualified Path, Display Path, TimeStamp, State, Priority, and IsSystemEvent. From there, the unneeded columns could be removed, and the dataset could be sorted by UUID or EventTime.

Here is a code example:

endDate = system.date.now()
startDate = system.date.addDays(endDate, -30)
columnsOfInterest = ['EventId', 'EventTime', 'EventState']
dataset = system.alarm.queryJournal(startDate = startDate, endDate = endDate).getDataset()
filteredSet = system.dataset.filterColumns(dataset, columnsOfInterest)
sortedData = system.dataset.sort(filteredSet, 0, True)

Here is the result:
image

With this approach, the event states come through as integers. If the string values are needed, they will have to be converted according to this table:
image

2 Likes