# Active Alarms to CSV

**URL:** <https://forum.inductiveautomation.com/t/active-alarms-to-csv/17559>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [March 30, 2018, 5:28pm UTC](https://forum.inductiveautomation.com/t/active-alarms-to-csv/17559 "2018-03-30T17:28:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lautry](https://avatars.discourse-cdn.com/v4/letter/l/a8b319/32.png) [@lautry](https://forum.inductiveautomation.com/u/lautry)\
**Post date:** [March 30, 2018, 5:28pm UTC](https://forum.inductiveautomation.com/t/active-alarms-to-csv/17559/1 "2018-03-30T17:28:26Z")

</div>

Hello all,

I am trying to run a script that I have tried to implement in the Gateway Tag change, property change on a component, and more…  
The script is below:

```auto
from __future__ import with_statement
import csv, time, os
faultOccured = system.tag.read("Interface/NavigationBarTags/statusScannerIndicator").value
if(faultOccured==2 or faultOccured==3):
	with open("C:\Users\USER\Documents\HMI_Alarms\HMI_Alarms.csv", "a") as cosv:
		alarmTest=system.alarm.queryStatus(state=["ActiveUnacked"])
		t = time.localtime()
		timestamp = time.strftime('%b-%d-%H:%M:%S ', t)
		strAlarm="Reported Time: " + timestamp + alarmTest.toString()+"\n"
	
		csv_f = csv.writer(cosv)
		cosv.write(strAlarm)

```

I do not know why, but it will not run the script on anything but the Script Console. Perhaps the from **future** import with\_statement does not work with the rest of Ignition? I’m not sure.

If I run it on the script console, it runs appropriately… It allows me to apend a .csv with the active alarm status.

Any idea on why this only works on the script console, and if this is the case, an alternative way to have the same functionality?

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [March 30, 2018, 5:36pm UTC](https://forum.inductiveautomation.com/t/active-alarms-to-csv/17559/2 "2018-03-30T17:36:13Z")

</div>

You could move your code to the Script Library and call it from a Gateway Event Script. I just tested with 7.9.6 and this works for me.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [March 30, 2018, 6:14pm UTC](https://forum.inductiveautomation.com/t/active-alarms-to-csv/17559/3 "2018-03-30T18:14:17Z")

</div>

Does your gateway service account have access to that folder?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 30, 2018, 8:23pm UTC](https://forum.inductiveautomation.com/t/active-alarms-to-csv/17559/4 "2018-03-30T20:23:38Z")

</div>

And look in your gateway logs – there should be messages for the errors generated in the script.
