# Tags with alarms listing from database query

**URL:** <https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626>\
**Category:** Ignition\
**Created:** [September 11, 2018, 6:13pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626 "2018-09-11T18:13:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [September 11, 2018, 6:13pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/1 "2018-09-11T18:13:10Z")

</div>

Forgive me if this has been asked before…I couldn’t find this question posted previously and did not figure it out browsing the database tables.

I would like to use a SQL query to obtain a listing of tags configured with alarms (we are re-evaluating our priority scheme and desire to utilize Excel spreadsheets for analysis).

I’ve very comfortable with SQL…just need to know where this information is located within the Ignition schema.,

Thanks in advance for any assistance!

John

---

<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:** [September 11, 2018, 6:50pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/2 "2018-09-11T18:50:37Z")

</div>

It’s not. Or rather, it’s in Ignition’s internal DB, not any DB connection. The supported way to get comprehensive information about tags would be to export the entire tag hierarchy as XML. From the designer’s tag browser.

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [September 11, 2018, 7:01pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/3 "2018-09-11T19:01:35Z")

</div>

Its not easy to get. You could export as @pturmel said, however if you use any bindings for priority, enabled etc - they will not be evaluated. I’ve been trying to do something like this for a while and unfortunately haven’t found something reliable that will find all alarms, enabled or not, and will give their evaluated statuses.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [September 11, 2018, 7:38pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/4 "2018-09-11T19:38:31Z")

</div>

seems like you could use a combination of the browseTags and getAlarmStates functions to accomplish what you want. But like what was said already, if you have a binding on your priority, that will be an issue.

Here is a start for you…

```auto
tags = system.tag.browseTagsSimple("5000-003","ASC")
for tag in tags:
	try:	
		tagDefs = system.tag.getAlarmStates(tag.path)
		for tagDef in tagDefs:    
		    for prop in tagDef.getAlarmProperties():
		    	if prop.property == 'priority':
		    		print tag.path, tagDef.alarm, prop.value
	except:
		print tag

```

---

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [September 12, 2018, 2:12pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/5 "2018-09-12T14:12:09Z")

</div>

Thanks for the answers. I did try a tag export but did not see a field which would denote an alarm is set on the tag. Rather, I see a complete tag listing. How would I filter this so I can work with just tags with alarms?

Thanks again,

John

---

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [September 12, 2018, 2:14pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/6 "2018-09-12T14:14:04Z")

</div>

> [@diat150](#):
>
> tags = system.tag.browseTagsSimple("5000-003","ASC")  
> for tag in tags:  
> try:   
> tagDefs = system.tag.getAlarmStates(tag.path)  
> for tagDef in tagDefs:  
> for prop in tagDef.getAlarmProperties():  
> if prop.property == 'priority':  
> print tag.path, tagDef.alarm, prop.value  
> except:  
> print tag

Thank you. While I am good with SQL I'm still learning scripting with Ignition. Where would I run this code to get output?

Sorry for the newbie question. I appreciate your patience!

John

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [September 12, 2018, 2:28pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/7 "2018-09-12T14:28:21Z")

</div>

I built it in the script console, but you can run it on a button if you want to do other stuff. You could easily modify to put everything into a dataset and put into a table… or export as a csv.

I would start out by just trying one folder at a time. Replace 5000-003 with your folder name.

---

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [September 12, 2018, 2:56pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/8 "2018-09-12T14:56:07Z")

</div>

Thanks again. I do get output this way but don’t see anything which would denote the priority field. We’re trying to make better use of the priorities for report and messaging purposes, and it would be of great help to see what tags are alarmed and if alarmed…what priority they might be…

Is this something I should be perhaps contact support about?

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [September 12, 2018, 3:04pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/9 "2018-09-12T15:04:36Z")

</div>

You should see an output like this, tagname, alarm name, then priority. I put apostrophe to kind of show the breaks.

‘5000-003/Volts’ ‘High High Alarm’ ‘Critical’  
‘5000-003/Volts’ ‘Low Low Alarm’ ‘Critical’  
‘5000-003/Volts’ ‘Low Alarm’ ‘High’  
‘5000-003/Volts’ ‘High Alarm’ ‘High’

---

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [September 12, 2018, 3:48pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/10 "2018-09-12T15:48:40Z")

</div>

Ahh…I see it now! I added “,” to your print statement to further assist in a Excel copy/paste.

I wonder how difficult it would be start at the tag root folder and iterate through the entire tag tree?

Thank you again!!

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [September 12, 2018, 3:54pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/11 "2018-09-12T15:54:20Z")

</div>

how many tags do you have? shouldnt be hard. look at the documentation for the scripting system.tag.browseTagsSimple and it should explain what to do.

---

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [September 12, 2018, 3:57pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/12 "2018-09-12T15:57:32Z")

</div>

I have around 2,400 tags…although many of them are not alarmed. I’ll look through the literature (with your suggestion) and work through it. I’m also planning on speaking with support to perhaps find the ‘best’ way to do this.

I’ll report back on our progress. Thank you.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [September 12, 2018, 4:02pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/13 "2018-09-12T16:02:01Z")

</div>

that shouldnt be bad. It would probably take 5-10 minutes to run the script.

---

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [September 13, 2018, 5:44pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/14 "2018-09-13T17:44:56Z")

</div>

For everyone’s future reference, I worked with Kevin at Inductive and we (he) came up with this script which does what I asked. Simply replace the sample file path with your own. This script outputs a CSV file.

Many thanks for all the help here…much appreciated!!

```auto
import xml.etree.ElementTree as ET

def DFS(root, tagpath):

	if 'path' in root.attrib and 'name' in root.attrib:
		
		name = root.attrib['name']
		path = root.attrib['path']
		
		if path != "": tagpath += path + '/'
		if name != "": tagpath += name + '/'
		
		for child in root:
			DFS(child, tagpath)

	elif root.tag == "Alarms":
		for alarm in root:
			alarmName = alarm.attrib['name']
			alarmPriority = 1	
			
			# If the alarm doesn't have a priority property,
			# it's implied to have an priority of 1
			for prop in alarm:
				if prop.attrib['name'] == 'priority':
					alarmPriority = int(prop.text)
					
			data.append([tagpath, alarmName, alarmPriority])
			
		
def recurse(root):
	for child in root:
		DFS(child, '')
		
		
filepath = r" **C:\Users\sample_user\Documents\tags_all.xml**"
tree = ET.parse(filepath)
root = tree.getroot()

header = ['tag Path', 'alarm', 'priority']
data = []

root[0].attrib
recurse(root)

dataset = system.dataset.toDataSet(header, data)
system.dataset.exportCSV('alarm priorities.csv', 1, dataset)

```

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [September 13, 2018, 5:53pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/15 "2018-09-13T17:53:27Z")

</div>

I’m interested in this but I think your formatting got messed up after def recurse(root), could you take a look? Looks like the two lines after that should be indented, is that correct?

---

<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:** [September 13, 2018, 6:08pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/16 "2018-09-13T18:08:15Z")

</div>

I just edited it for you @jkelleyus. Instead of using Blockquotes you just needed a triple back quote before and after the snippet.

---

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [September 13, 2018, 6:24pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/17 "2018-09-13T18:24:58Z")

</div>

Thank you, sir!!! Appreciate the help and advice…

---

<div class="post-metadata">

**Author:** ![vcgasman](https://avatars.discourse-cdn.com/v4/letter/v/ecc23a/32.png) [@vcgasman](https://forum.inductiveautomation.com/u/vcgasman)\
**Post date:** [September 23, 2019, 9:02pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/18 "2019-09-23T21:02:45Z")

</div>

I’m trying to run this on a tag export from a 8.04 system. The script runs and creates the xml file but it is empty with the exception of the header columns. I see in the export that the “Alarms” property is listed as a Compound Property. Is this causing my empty file perhaps?

---

<div class="post-metadata">

**Author:** ![Diego\_Aaron\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@Diego\_Aaron\_Gonzalez](https://forum.inductiveautomation.com/u/Diego_Aaron_Gonzalez)\
**Post date:** [October 12, 2022, 1:36am UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/19 "2022-10-12T01:36:11Z")

</div>

hello @jkelleyus, I'm new to ignition, do you know if this code can retrieve tags with alarms and put it into a power table to be edited?

thanks

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 12, 2022, 12:27pm UTC](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626/20 "2022-10-12T12:27:01Z")

</div>

It can, but you'll need to modify it a bit:  
Instead of exporting to an xml, you can use `system.tag.getConfiguration`. Pass it `recursive=True` if you have folders or UDTs.  
Note that you can use `getConfiguration` on UDTs as well: `system.tag.getConfiguration("[provider]_types_")`

Then, instead of exporting the dataset to a CSV, send it to your table.  
Or bind the whole thing to the table, which should also work.

This is all assuming the script works as expected, I didn't go into its details.  
If you're having trouble with it, I'll take a closer look.

[Next page](https://forum.inductiveautomation.com/t/tags-with-alarms-listing-from-database-query/19626.md?page=2)
