====Event Alerting Example====
import datetime
import traceback
import arditrigger
from arditrigger import trigger,data,when,changes,attach
@trigger #This is a trigger function
@changes #This gets called on every change
@data('{0}.Power') #This needs the 'Power' property from the attached asset
@attach('type','Wind Turbine') #This is connected to each of the turbines, in order
@when(lambda o: o.GTHist(float(o.Value()),2200,100)) #Trigger when the power becomes excessive.
def PowerSpike(o):
if o.Condition() == False:
#If the spike has ended....
if o.FirstRun() == False:
#If this isn't the first time this has been triggered...
rng = o.Range()
o.LogEvent(o.Name() + " Spike",(rng[1] - rng[0]).total_seconds())
o.Output(o.Name() + " Spike",0)
else:
o.Output(o.Name() + " Spike",1)
arditrigger.Start("ardiserverurl","default",outputconfig="output_config.json")
This example detects power spikes. It triggers **when** the power is more than 2200. \\
It's **attach**ed to all of the assets with a type of 'Wind Turbine'. \\
The function is called every time the value **changes**. \\
The //GTHist// function is used to prevent the alert from flickering on-and-off when the property is close to 2200. In this case, it will trigger when the value goes over 2200, and won't trigger again until the value drops back under 2100.
====Output Config====
[
{
"type": "value",
"method": "prometheus",
"port": 9306
},
{
"type": "event",
"method": "logfile",
"filename": "spikes.log"
}
]
====Results====
This configuration creates a log entry in the file **spikes.log** at the end of each power spike, when the power returns to normal.
It also reports a //live// value that can be read by a Prometheus server for recording, at **http://localhost:9306/prometheus**