How to Generate a List of all Configured Alarms

Hi There,

How can one go about generating a list of all tags with configured alarms in Ignition Version 8? I did check the forums/previous posts but i cannot find a clear or definite answer on this.

Thank You!

You'll get most of the way with:

alarms = system.alarm.queryStatus(source=["*"])

You'll then have to do some processing to get the info out of that.

Be careful though - if theres a lot of tags you will probably want to do this in a separate thread!

1 Like

Thanks for the reply @jonathan.taylor

I did find this method earlier on some older posts, however, after experimenting with it i've noticed that it does not grab all the alarms.

There is another post below that mentions this as well:

Maybe a good feature request.

Yes I think the alarms that query gives are alarms that are enabled and have at some point been active; i’d need to do more testing to double check that though

1 Like

I think you’re right on that with respect to being enabled and at some point having been active.

Here is what we use. Put this in a project script or on a button, and call getAlarms(rootPath). It will return a list. You will want to run this from the gateway, as it is a recursive browse. Invoke with sendRequest or sendRequestAsync.

def getAlarms(tagPath):	

	from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser
	alarms = []
	def iterTagConfig(dictIn, folderIn = ''):
		keys = dictIn.keys()
		#Move tags and alarms to end of list.  I do not recall why, but it is really, really important.
		if 'tags' in keys:
			keys.append(keys.pop(keys.index('tags')))
		if 'alarms' in keys:
			keys.append(keys.pop(keys.index('alarms')))
			
		for key in keys:
			#If the value of dictIn[key] is a dict, then it is a folder like structure that has child tags.  Iterate through this
			if isinstance(dictIn[key], dict):
				iterTagConfig(dictIn[key])
			elif key == 'tags':
				for tag in dictIn[key]:
					if str(tag["path"]) != "_types_":
						iterTagConfig(tag, folderIn = folderIn + str(dictIn['path']) + '/' if folderIn else str(dictIn['path']))      
			elif key == 'alarms':
				#This is what we are looking for.  Each tag in this alarm item is an alarm, so we add them to the list.  Use qualified tag paths because they are exact, and I hear they make you look cooler.
				for tag in dictIn[key]:
					tp = TagPathParser.parseSafe(folderIn+"/"+str(dictIn['path']) if folderIn else str(dictIn['path']))
					qp = "prov:%s:/tag:%s:/alm:%s"%(tp.source,tp.toStringPartial(),tag["name"])
					alarms.append([qp])
					iterTagConfig(tag,folderIn = folderIn + str(dictIn['path']))	
	if tagPath:
		folder = tagPath
		#Root level browse
		nodes = system.tag.getConfiguration(folder, True)
	
		for item in nodes:
			iterTagConfig(item)
	
	return alarms	

5 Likes

I think you're missing + '/' in the else condition here

e.g.
iterTagConfig(tag, folderIn = folderIn + str(dictIn['path']) + '/' if folderIn else str(dictIn['path']) + '/')

Also, thanks again for this, saved me some time!!