Last active
February 2, 2022 16:31
-
-
Save dante11235/3725ef87fd64bb5d9771897b48d5a6bd to your computer and use it in GitHub Desktop.
Keybase Zabbix Webhook
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
var Keybase = { | |
message: null, | |
sendMessage: function() { | |
var params = { | |
msg: Keybase.message, | |
}, | |
data, | |
response, | |
request = new HttpRequest(), | |
url = 'https://bots.keybase.io/webhookbot/------------------'; | |
request.addHeader('Content-Type: application/json'); | |
data = JSON.stringify(params); | |
// Remove replace() function if you want to see the exposed token in the log file. | |
Zabbix.log(4, '[Keybase Webhook] params: ' + data); | |
response = request.post(url, data); | |
Zabbix.log(4, '[Keybase Webhook] HTTP code: ' + request.getStatus()); | |
try { | |
response = JSON.parse(response); | |
} | |
catch (error) { | |
response = null; | |
} | |
if (request.getStatus() !== 200 || typeof response.ok !== 'boolean' || response.ok !== true) { | |
if (typeof response.description === 'string') { | |
throw response.description; | |
} | |
else { | |
throw 'Unknown error. Check debug log for more information.' | |
} | |
} | |
} | |
} | |
try { | |
var params = JSON.parse(value); | |
Keybase.message = params.Subject + '\n' + params.Message; | |
Keybase.sendMessage(); | |
return 'OK'; | |
} | |
catch (error) { | |
Zabbix.log(4, '[Keybase Webhook] notification failed: ' + error); | |
throw 'Sending failed: ' + error + '.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment