Get Tags based on tag attribute

I’m aware of using a Tag Driven Provider to query tags from an external database; however, due to scale, this isn’t a good option for us. Other option I tried is system.tag.browseTags and using the result set to continue filtering. This method crashed if there are too many tags. Basically I need to know all the tags that have alarms enabled or tags that have history enabled.

Having a very large tags system is the cause of the problem. What other options do I have?

[quote=“son122”]I’m aware of using a Tag Driven Provider to query tags from an external database; however, due to scale, this isn’t a good option for us. Other option I tried is system.tag.browseTags and using the result set to continue filtering. This method crashed if there are too many tags. Basically I need to know all the tags that have alarms enabled or tags that have history enabled.

Having a very large tags system is the cause of the problem. What other options do I have?[/quote]

how many tags do you have?

I had wrote a short script to do this kind of thing when someone requested in the past.
inductiveautomation.com/forum/v … 25&t=13497

also, how are your tags structured? is it alot of the same tag types in separate folder or just alot of different random tagnames?

one option that you could do is export them out in xml and see if you can figure out a way to filter them in the xml file.

another way would be to export them out in csv, then import the folder and tagname into a database table. then you could build a readAll script that looks at the alrm and history configs for each tag and builds you a list of tags with history/alarming setup.

Thanks. Over 100K.
Still refining the tag structure to something more simpler, but the problem is there are a lot of moving pieces. Just changing structure breaks everything.

I like the idea of exporting them out to a database. One concern is syncing this process so that it is more automated. Otherwise, every time we add/delete/move a tag, the database is no longer feasible and need to be rerun all over again.

You can get the tags that have historical tracking from the sqlth_te table:

SELECT * FROM sqlth_te

For the alarms, diat150’s script is a nice one, but it uses system.tag.browseTags, which you say you’re having issues using.

You might want to consider giving Nick Mudge’s Power Scripting module a try. Part of its functionality is that you can query the internal database (and the mutable datasets are pretty nice too! :wink: ) I believe the module runs the usual two hours in trial mode. $200 US if you decide to keep it.

Here are two variants of a script using the module:

[code]#Get List of tags ID with alarm configurations
alarmTagIDquery = “SELECT DISTINCT TAGID FROM SQLTAGALARMPROP”
alarmTagIDResult = pa.ignition.db.runPrepInternalDBQuery(alarmTagIDquery)

#Convert it to a list
alarmTagIDList=[]
for row in alarmTagIDResult:
alarmTagIDList.append(row[0])

#Query the tags
tagQuery = “SELECT * FROM SQLTAG”
tagResult = pa.ignition.db.runPrepInternalDBQuery(tagQuery)

#Filter the tag dataset againg the alarm tagID list
tagResult.filterRows(lambda row: row[0] in alarmTagIDList )
print tagResult
[/code]

[code]#Get List of tags ID with alarm configurations
alarmTagIDquery = “”“SELECT DISTINCT TAGID FROM SQLTAGALARMPROP”""
alarmTagIDResult = pa.ignition.db.runPrepInternalDBQuery(alarmTagIDquery)

#Convert it to a list
alarmTagIDList=[]
for row in alarmTagIDResult:
alarmTagIDList.append(row[0])

#Make a string of the list to use in tag query
listString = ‘,’.join(str(e) for e in alarmTagIDList)

#Query the tags
tagQuery = “SELECT * FROM SQLTAG WHERE SQLTAG_ID IN(”+listString+")"
tagResult = pa.ignition.db.runPrepInternalDBQuery(tagQuery)

print tagResult[/code]