How to Generate a List of all Configured Alarms

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	

6 Likes