kapacitor icon indicating copy to clipboard operation
kapacitor copied to clipboard

TickScript deadman groupby nil value

Open enzdal opened this issue 1 year ago • 0 comments

Hi all, I have a strange problem with the deadman type alert. I defined a groupby condition on a tag that by the time the script is deployed the data hasn't arrived yet, so a "nil" error is thrown. Is there a way to ignore when the bucket is empty and not throw this kind of error? This is the current script:

var db = 'test-db'

var rp = 'test-rp'

var measurement = 'my-test'

var groupBy = ['unique-field']

var whereFilter = lambda: ("condition" == 'false') AND ("description" == 'my-desc')

var period = 1m

var name = 'Dead-unique'

var idVar = name + '-{{.Group}}'

var message = ''

var idTag = 'alertID'

var levelTag = 'level'

var messageField = 'message'

var durationField = 'duration'

var outputDB = 'alarms-db'

var outputRP = 'alarms-rp'

var outputMeasurement = 'alerts'

var triggerType = 'deadman'

var threshold = 0.0

var data = stream
    |from()
        .database(db)
        .retentionPolicy(rp)
        .measurement(measurement)
        .groupBy(groupBy)
        .where(whereFilter)

var trigger = data
    |deadman(threshold, period)
        .message(message)
        .id(idVar)
        .idTag(idTag)
        .levelTag(levelTag)
        .messageField(messageField)
        .durationField(durationField)
        .stateChangesOnly()

trigger
    |eval(lambda: "emitted")
        .as('value')
        .keep('value', messageField, durationField)
    |eval(lambda: float("value"))
        .as('value')
        .keep()
    |influxDBOut()
        .create()
        .database(outputDB)
        .retentionPolicy(outputRP)
        .measurement(outputMeasurement)
        .tag('alertName', name)
        .tag('triggerType', triggerType)

trigger
    |httpOut('output')

and this is the error with nil value:

{
   "id": "Dead-unique-nil",
   "message": "",
   "details": "....",
   "duration": 0,
   "level": "CRITICAL",
   "data": {
      "series": [
         {
            "name": "stats",
            "columns": [
               "time",
               "emitted"
            ],
            "values": [
               [
                  "2023-03-13T11:01:00Z",
                  0
               ]
            ]
         }
      ]
   },
   "previousLevel": "OK",
   "recoverable": true
}

enzdal avatar Mar 13 '23 11:03 enzdal