Created
July 29, 2016 08:39
-
-
Save MichaelErmer/f89ddd644299a985d4120f220407f081 to your computer and use it in GitHub Desktop.
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/ruby | |
require 'net/https' | |
require 'json' | |
slack_webhook_url="" | |
slack_enabled=true | |
def log(message) | |
open('/var/log/monit.log', 'a') { |f| | |
f.puts message | |
} | |
end | |
if slack_enabled | |
begin | |
uri = URI.parse(slack_webhook_url) | |
Net::HTTP.start(uri.host, uri.port, {use_ssl: true}) { |http| | |
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' => 'application/json'}) | |
request.body = { | |
:text => "[#{ENV['MONIT_HOST']}] #{ENV['MONIT_SERVICE']} - #{ENV['MONIT_DESCRIPTION']}" | |
}.to_json | |
response = http.request(request) | |
log("Response from Slack [#{response.code}] [#{response.body}]") | |
} | |
rescue Exception => e | |
log("Exception while calling Slack [#{e.message}]") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment