Flávio Ferreira
Flávio Ferreira

Reputation: 183

Kapacitor configure Influxdb output to store message

I would like to store the message of an alert in influxDB using influxDBOut. Is is possible?

Here is my tick script

batch
    |query('SELECT mean(value) as value FROM "metrics"."autogen"."__MEASUREMENT__"')
        .period(15m)
        .every(5s)
        .groupBy(*)
        .fill(0)
    |alert()
        .id('[METRICS] - {{ .Name }}')
        .message('{{ .ID }} changed state to {{ .Level}} [{{ .Time }}] => The metric {{ index .Fields "value" }} in the last 15m.')
        .info(lambda: TRUE)
        .warn(lambda: "value" < __WARN_THRESHOLD__)
        .crit(lambda: "value" < __CRIT_THRESHOLD__)
        .stateChangesOnly()
        .levelField('Severity')
    |influxDBOut()
        .database('alerts')
        .retentionPolicy('autogen')
        .measurement('__MEASUREMENT__')
        .tag('Condition', 'Low')

Upvotes: 0

Views: 450

Answers (2)

Samuel Toh
Samuel Toh

Reputation: 19288

Q: I would like to store the message of an alert in influxDB using influxDBOut. Is is possible?

A: Michael definitely knows waayyy better than I do. Yes, there is no straight forward way out at the moment. However it doesn't mean that this is not do-able.

What you're trying to do here is a typical software dev problem.

  1. Open a file
  2. Read its content
  3. Format it
  4. Write it somewhere else.

You can handle this sort of problem in any scripting language that supports the highlighted points above. The only tricky thing is probably #4 as not every scripting language has a influxdb database driver, but still you can do curl commands to perform the writes.

What you could do is

  1. Modify your TICK script to output the alert to a file. See log() of alert node.
  2. Write a simple script to lookout for any new files written by the log() functionality.
  3. Parse the file

  4. format the data so that they can be inserted into a measurement

  5. setup a scheduler like unix's cron to periodically run your script.

Hope it helps.

Upvotes: 0

Michael Desa
Michael Desa

Reputation: 4747

Unfortunately there currently isn't a way to achieve a result like this. If this functionality is particularly important to you, I'd recommend opening up a feature request on Kapacitor detailing your use case.

Upvotes: 0

Related Questions