Can I create an alert in kapacitor which is triggered when the value is below a specific limit for more than 10 minutes

I want to create an alert for the system when the value is below specific limit. But I do not want it to throw alert every time it happens. I only want to create a alert when the value stays below the limit for a certain amount of time.
It could be something with the combination of threshold and relative alert where the value is below threshold AND the change in last 10 min is 0%.
But I am having difficulty in creating such alert.

Hello @ashish02,
Welcome!
I found some threads with code examples that might be useful to you.



Please let me know if you’re still having trouble after looking through these.
Thank you :).

image
Based on the thread you provided I create this relative alert. As visible in the graph the past value is 1 and current value is 0 thus the change is -1 which is less than 0. But I am not getting alert for this. Please help.

var db = ‘test’

var rp = ‘autogen’

var measurement = ‘kapacitor’

var groupBy =

var whereFilter = lambda: TRUE

var period = 10s

var every = 30s

var name = ‘Test-Alert’

var idVar = name

var message = ‘TEST TICK ALERT 10 minutes’

var idTag = ‘alertID’

var levelTag = ‘level’

var messageField = ‘message’

var durationField = ‘duration’

var outputDB = ‘chronograf’

var outputRP = ‘autogen’

var outputMeasurement = ‘alerts’

var triggerType = ‘relative’

var shift = 1m

0s

var crit = 0

var data = stream
|from()
.database(db)
.retentionPolicy(rp)
.measurement(measurement)
.groupBy(groupBy)
.where(whereFilter)
|window()
.period(period)
.every(every)
.align()
|max(‘new’)
.as(‘value’)

var past = data
|shift(shift)

var current = data

var trigger = past
|join(current)
.as(‘past’, ‘current’)
|eval(lambda: float(“current.value” - “past.value”))
.keep()
.as(‘value’)
|alert()
.crit(lambda: “value” < crit)
.message(message)
.id(idVar)
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
.slack()
.channel(‘TestGrafanaAlerts’)
.username(‘TICK’)

trigger
|eval(lambda: float(“value”))
.as(‘value’)
.keep()
|influxDBOut()
.create()
.database(outputDB)
.retentionPolicy(outputRP)
.measurement(outputMeasurement)
.tag(‘alertName’, name)
.tag(‘triggerType’, triggerType)

trigger
|httpOut(‘output’)