# Creating report from alarm data - getting user who acknowlegded alarm and when?

**URL:** <https://forum.inductiveautomation.com/t/creating-report-from-alarm-data-getting-user-who-acknowlegded-alarm-and-when/60450>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [June 7, 2022, 2:18pm UTC](https://forum.inductiveautomation.com/t/creating-report-from-alarm-data-getting-user-who-acknowlegded-alarm-and-when/60450 "2022-06-07T14:18:09Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 8, 2022, 6:22pm UTC](https://forum.inductiveautomation.com/t/creating-report-from-alarm-data-getting-user-who-acknowlegded-alarm-and-when/60450/6 "2022-06-08T18:22:04Z")

</div>

Thank you for clearing that up, that makes a lot of sense.

So given that, how can I better represent the time the event first started and when it was cleared of an alarm? Right now my script looks like

```auto
def generateAlarmDataForFullDay(day):
	"""
	Get's all alarms for a specified day and creates a report that is put into a mapped drive folder.
	Args:
		day: datetime object from a calendar component that will be used to determine what days to use in calculation
	Returns:
		DataSet - to be utilized by the reporting module
	"""
	logger = system.util.getLogger("Alarm Report Data Logger")
	beginningOfDay, endOfDay = dates.getMidnightToMidnight(day)
	allAlarmData = system.alarm.queryJournal(startDate=beginningOfDay, endDate=endOfDay, includeSystem=False)
	headers = ['Alarm Occured At', 'Alarm Cleared At', 'Alarm Name', 'User Logged In']
	rows = []
	for i, alarmRecord in enumerate(allAlarmData):
		alarmOccuredAt = alarmRecord.get(CommonAlarmProperties.EventTime)
		alarmClearedAt = alarmRecord.get(CommonAlarmProperties.ActiveTime)
		# Step 0 - get name of alarm
		alarmName = alarmRecord.getName()
		# Step 1 - Way to differentiate between start of alarm and clearing of alarm, determins alarmOccuredAt and alarmCleared at columns
		queryTimeStamp=None
		# This is when alarm was cleared
		if alarmClearedAt is None:
			alarmClearedAt = alarmOccuredAt
			alarmOccuredAt = None
			queryTimeStamp = alarmClearedAt
		# this is when alarm started
		elif alarmClearedAt is not None and alarmOccuredAt is not None:
			alarmClearedAt = None
			queryTimeStamp = alarmOccuredAt
			
		# Step 2 - Chance to determine who was logged in at time
		getUserQuery = "SELECT UserName, EventName, TimeStamp FROM event_log WHERE TimeStamp<? AND EventName IN ('Login','Logout') ORDER BY TimeStamp DESC LIMIT 1"
		userData = system.db.runPrepQuery(getUserQuery, [queryTimeStamp])
		for (username, eventName, TimeStamp) in userData:
			if eventName == 'Logout':
				userLoggedIn = "Auto-Logged In User"
			else:
				userLoggedIn = username
		rows.append([alarmOccuredAt, alarmClearedAt, alarmName, userLoggedIn])
	dataset = system.dataset.toDataSet(headers, rows)
	return dataset

```

Which gives me data in a report table that looks like

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/2/f28e72981a055cecbc884f3fd4bfe29b1b9b26d4.png)

I highlighted one instance, Label Head E-Stop Pressed occured and then 1 minute 28 seconds later was cleared. Is that actually true though based on my script? I am nervous I am misinterpreting the alarm objects. Tagging @JordanCClark @nminchin as I believe I have seen you both work a lot with alarms

---

_[View the full topic](https://forum.inductiveautomation.com/t/creating-report-from-alarm-data-getting-user-who-acknowlegded-alarm-and-when/60450)._
