How can I get a count of the alarms that are active, unacked, and unshelved, since the system tag includes shelved alarms?
I've come up with this script to run inside an expression tag. Anyone else have ideas?
def getActiveUnackedUnshelvedCount():
'''
Get the count of active unacked alarms that are not shelved
Args:
n/a
Returns:
activeUnackedCount (integer) : Active, Unacked, Unshelved Count
'''
almPaths = [str(alm.path) for alm in system.alarm.getShelvedPaths() if alm]
shelvedCountPaths = []
for path in almPaths:
pathParts = path.split(':/')
partsDict = {}
for part in pathParts:
key, value = part.split(':', 1)
partsDict[key] = value
prov = partsDict.get('prov','')
tag = partsDict.get('tag','')
#alarm = partsDict.get('alm','')
fullAlmPath = '[' + prov + ']' + tag + '/Alarms.ShelvedCount'
shelvedCountPaths.append(fullAlmPath)
tagVals = system.tag.readBlocking(['[System]Gateway/Alarming/Active and Unacked']+shelvedCountPaths)
activeUnackedCount = tagVals[0].value
for i in range(1,len(tagVals)):
if tagVals[i].value:
activeUnackedCount = activeUnackedCount - 1
return activeUnackedCount
edit: just realized that I need to check if the alarm is active before subtracting it from the count. Script has not been updated yet.
Well,
I found that the ActiveAckCount
, ActiveUnackCount
, HasActive
, and HasUnacknowledged
properties of the Alarms tag do not populate as expected either, so I can't even check the activity before subtracting it because the individual alarm names may differ, and their may be more than one.
It seems to me that excluding shelved alarms in a tag from the tag's alarm summary properties is expected and, from my viewpoint, desirable. The whole point of shelving is to prevent that alarm from participating in the rest of the system.
Right, then why is it included in the system's Active and Unacked
count? If it wasn't I wouldn't have this issue.
Phil, how might I loop through each individual alarm under the Alarms summary tag to check the isActive
tag, without knowing the name of the alarm(s)?
Seems to me that is the bug.
Yeah, have to know that. Is available in a system.tag.getConfiguration()
call or a system.tag.query()
call, but you don't want to be calling those often.
that's kind of what I figured, so I'm a little stuck at the moment....
Reference this as I made some tweaks from an exchange resource, but this will summarize alarms and get counts, etc.
I suppose using query or config to get the name might actually be OK since it would only be for any shelved alarms, which should be a fairly limited list.
It looks like
system.alarm.queryStatus(state=["ActiveUnacked"], includeShelved=False)
is all that I need
Make sure you aren't calling that from the GUI unless it is in an async thread. That call can take a bit and will cause issues in your GUI unless you are careful.
only calling from an expression tag. Every 3 seconds.
If you're doing it from a lot of different locations/areas, it can also cause problems which is why I believe the script that I used from the Exchange and tweaked for some of my own use only has one place it calls it from then saves it to a global variable that all the areas filter results from.