Last active
June 30, 2017 17:21
-
-
Save Buzut/dd49ee9c9b589f1035296ef96e63698e to your computer and use it in GitHub Desktop.
Sensu handler for InfluxDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"handlers": { | |
"influxdb": { | |
"type": "pipe", | |
"comman": "/etc/sensu/handlers/influx.js" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/nodejs | |
// to be put in /etc/sensu/handlers/influx.js | |
const influxPort = 8090; | |
const dgram = require('dgram'); | |
const client = dgram.createSocket('udp4'); | |
let raw = ''; | |
process.stdin.on('readable', () => { | |
let chunk = process.stdin.read(); | |
if (chunk !== null) { | |
raw += chunk; | |
} | |
}); | |
process.stdin.on('end', () => { | |
let json = JSON.parse(raw); | |
let result = json.check.output; | |
client.send(result, influxPort, 'localhost', (err) => { | |
client.close(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment