*------------------------------------------------------------------ Description: Alarm counter tools: increase counter, reset counter, get thresholds... Created by : Marco Incalcaterra Created on : 23 July 2017 Modified by: Modified on: ------------------------------------------------------------------*/ // This function walks object tree recursively starting from given root sub ResetAlarmCounterOnAllNodes(rootObject, name) { // Walk all child objects foreach(o : GetObjectChildren(rootObject)) { if (classof(o) == "Node") { // Process node object counter = int32(GetCustomAttribute(o, name)); timer = int64(GetCustomAttribute(o, name . "_date")); if (counter > 0 && (time() - timer) > GetTimeFrameFromPersistentStorage(name)) { trace(6, "ResetAlarmCounter on node: " . o); SetCustomAttribute(o, name, 0); SetCustomAttribute(o, name . "_date", time()); } } else if (classof(o) == "Container") { // For all other objects, go down the tree ResetAlarmCounterOnAllNodes(o, name); } } } sub IncreaseAlarmCounter(node, name) { trace(6, "IncreaseAlarmCounter on node: " . node); counter = int32(GetCustomAttribute(node, name)); if (counter == 0) SetCustomAttribute(node, name . "_date", time()); SetCustomAttribute(node, name, ++counter); } sub IsAlarmCounterBelowThreshold(node, name) { return GetCustomAttribute(node, name) < GetThresholdFromPersistentStorage(name); } sub IsAlarmCounterEqualToThreshold(node, name) { return GetCustomAttribute(node, name) == GetThresholdFromPersistentStorage(name); } sub IsAlarmCounterAboveThreshold(node, name) { return GetCustomAttribute(node, name) > GetThresholdFromPersistentStorage(name); } // Gets the threshold for specific event name from persistent storage (to be implemented...) sub GetThresholdFromPersistentStorage(name) { return 50; } // Gets the time frame for specific event name from persistent storage (to be implemented...) sub GetTimeFrameFromPersistentStorage(name) { return 3600; }