Sending Sensu data to influx db fails

343 views Asked by At

I have been trying to send Data from Sensu to Influx DB. I created DB for Sensu, and also updated to listen on port 8090 in my case. User login looks fine on influxdb.
I configured almost everything similar to this link https://libraries.io/github/nohtyp/sensu-influxdb

I am not getting any success, and not seeing any data in the database .. Anyone tried this ?

1

There are 1 answers

0
Roshan On

You can also use the custom script in case default configuration is not working. it gives the options to write only the data you want to save, before running the script, install InfluxDBClient (sudo apt-get install python-influxdb)

from influxdb import InfluxDBClient
import fileinput
import json
import string
import datetime

json_body = " "

for line in fileinput.input():
   json_body = json_body + string.replace(line, '\n', ' ')

json_body = json.loads(json_body)

alert_in_ip = str(json_body["client"]["name"])
alert_in_ip = 'ip-' + string.replace(alert_in_ip, '.', '-')
alert_type = json_body["check"]["name"]
status = str(json_body['check']['status'])
time_stamp =(datetime.datetime.fromtimestamp(int(json_body["timestamp"])).strftime('%Y-%m-%d %H:%M:%S'))

json_body = [{ "measurement": alert_type,
    "tags": {
        "host": alert_in_ip
    },
    "time": time_stamp,
    "fields": {
        "value": int(status)
    }
}]

client = InfluxDBClient('localhost', 8086, 'root', 'root', 'sensu')

client.write_points(json_body)

And call the above script from your handler.

For example:

"sendinflux":{
               "type": "pipe",
               "command": "echo $(cat) | /usr/bin/python /home/ubuntu/save_to_influx.py",
               "severites": ["critical", "unknown"]
 }

Hope it helps!!