Tags with alarms listing from database query

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

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.

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.

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…

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

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

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

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.

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?

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’

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!!

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.

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.

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

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!!

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)
2 Likes

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?

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

1 Like

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

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?

1 Like

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

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.

1 Like