81 lines
2.6 KiB
Plaintext
81 lines
2.6 KiB
Plaintext
import pprint, time
|
|
Logger = system.util.getLogger("alarm.summary")
|
|
provider = "[default]"
|
|
|
|
def initAlarmSummaries():
|
|
""" This function will reset all the alarm summary udt's in the system
|
|
|
|
"""
|
|
allActiveAlarmsTag = []
|
|
newValues = []
|
|
for t in system.tag.browse(provider, {"tagType":"UdtInstance", "typeId": "AlarmSummary", "recursive":True}):
|
|
allActiveAlarmsTag.append(t["fullPath"].toString() +"/ActiveAlarms")
|
|
newValues.append({})
|
|
|
|
system.tag.writeAsync(allActiveAlarmsTag, newValues)
|
|
|
|
def updateAlarmCount(srcPath, priority, state):
|
|
pass
|
|
|
|
|
|
def calcMaxPriority(levelPath):
|
|
""" Pass in the path level to determine the max priority and return the value
|
|
levelPath: string of the object level path without the /AlarmSummary/ActiveAlarms
|
|
"""
|
|
aggAlarmStatus = system.tag.readBlocking([levelPath+"/AlarmSummary/ActiveAlarms"])[0].value.toDict()
|
|
|
|
return determinePriority(aggAlarmStatus)
|
|
|
|
def determinePriority(tagValue):
|
|
""" Use this method to figure out the highest priority level of a tag. Useful with transforms from front-end
|
|
Args:
|
|
tagValue: dict/document of the expected structure of {srcPath:priority}
|
|
Returns:
|
|
maxState: int -1 for none, 0-Diag, 1-Low, 2- Med, 3- High, 4-Critical
|
|
"""
|
|
maxState = -1
|
|
for k, v in tagValue.iteritems():
|
|
maxState = v if v > maxState else maxState
|
|
|
|
return maxState
|
|
|
|
|
|
|
|
def syncAlarms():
|
|
"""
|
|
Timer based function to update all of the aggregate alarm tags.
|
|
|
|
"""
|
|
sublog = Logger.createSubLogger("syncAlarms")
|
|
start = time.time()
|
|
levelAlarmSummary = {} #{"alarmPath":[{srcAlarm:priority}]
|
|
for alm in system.alarm.queryStatus(priority=[0,1,2,3,4],state=['ActiveUnacked','ActiveAcked']):
|
|
srcPath = alm.getSource().toString()
|
|
mainTagPath = srcPath.split("/tag:")[1].split(":/alm")[0]
|
|
priorityVal = alm.getPriority().intValue
|
|
|
|
pathLevelsList = mainTagPath.split("/")
|
|
|
|
# Because alarms can exist outside of the /Alarms folder in the UDT, we will account for this
|
|
almOffset = -1
|
|
if "Alarms" not in pathLevelsList:
|
|
almOffset= 0
|
|
|
|
for i in range(1, len(pathLevelsList) + almOffset):
|
|
path = provider+"/".join(pathLevelsList[:i])+"/AlarmSummary/ActiveAlarms"
|
|
if path not in levelAlarmSummary.keys():
|
|
levelAlarmSummary[path]= {}
|
|
|
|
levelAlarmSummary[path][srcPath] = max([levelAlarmSummary[path].get(srcPath,0), priorityVal ])
|
|
|
|
# pprint.pprint(levelAlarmSummary)
|
|
writeTags, writeVals = [], []
|
|
for k, v in levelAlarmSummary.iteritems():
|
|
writeTags.append(str(k))
|
|
writeVals.append(v)
|
|
sublog.debug("%s - %s"%(writeTags, writeVals))
|
|
if len(writeTags) == len(writeVals) and len(writeTags) > 0:
|
|
system.tag.writeAsync(writeTags, writeVals)
|
|
|
|
|
|
sublog.trace("finished in %s sec"%(time.time() - start)) |