influxdata / kapacitor

Open source framework for processing, monitoring, and alerting on time series data
MIT License
2.31k stars 492 forks source link

Alerta Integration: Variables not being evaluated within services() declaration #1556

Closed davestephens closed 7 years ago

davestephens commented 7 years ago

I have the following TICKscript:

var db = 'telegraf'
var rp = 'autogen'
var measurement = 'win_services'
var groupBy = []
var whereFilter = lambda: ("service_name" == 'super-duper-service')
var name = 'super-duper-service check'
var idVar = name + ':{{.Group}}'
var message = '{{ index .Tags "service_name" }} is {{.Level}} '
var idTag = 'alertID'
var levelTag = 'level'
var messageField = 'message'
var durationField = 'duration'
var outputDB = 'chronograf'
var outputRP = 'autogen'
var outputMeasurement = 'alerts'
var triggerType = 'threshold'
var crit = 4

var data = stream
    |from()
        .database(db)
        .retentionPolicy(rp)
        .measurement(measurement)
        .groupBy(groupBy)
        .where(whereFilter)
    |eval(lambda: "state")
        .as('value')

var trigger = data
    |alert()
        .crit(lambda: "value" < crit)
        .stateChangesOnly()
        .message(message)
        .id(idVar)
        .idTag(idTag)
        .levelTag(levelTag)
        .messageField(messageField)
        .durationField(durationField)
        .alerta()
        .resource('{{ index .Tags "host" }}')
        .event('NotRunning')
        .environment('{{ index .Tags "environment" }}')
        .services('{{ index .Tags "service_name" }}')

trigger
    |influxDBOut()
        .create()
        .database(outputDB)
        .retentionPolicy(outputRP)
        .measurement(outputMeasurement)
        .tag('alertName', name)
        .tag('triggerType', triggerType)

trigger
    |httpOut('output')

The services() section of the Alerta config is being passed through to Alerta as a string rather than being evaluated beforehand. This is what Alerta receives:

  "service": [
    "{{ index .Tags \"service_name\" }}"
  ],

There was a similar issue fixed last year that affected the environment field: https://github.com/influxdata/kapacitor/issues/306.

Am assuming that this a bug rather than me doing something daft - would appreciate any guidance. Thanks in advance!

nathanielc commented 7 years ago

This looks like a duplicate of https://github.com/influxdata/kapacitor/issues/1543 which was fixed in #1545