Last active
October 5, 2020 07:26
-
-
Save ialiendeg/12ec6fdef243cf48bfbf41cc18bce50f to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
require 'yaml' | |
slack_cfg = YAML.load_file("/root/.slackrc.yml") | |
#uri = URI.parse("https://#{slack_cfg['team']}.slack.com/services/hooks/incoming-webhook?token=#{slack_cfg['token']}") | |
uri = URI.parse(slack_cfg['hook_url']) | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' => 'application/json'}) | |
request.body = { | |
"channel" => "#monit", | |
"username" => "[MONIT]", | |
"text" => "[#{ENV['MONIT_HOST']}] #{ENV['MONIT_SERVICE']} - #{ENV['MONIT_DESCRIPTION']}", | |
"mrkdwn" => true | |
}.to_json | |
response = http.request(request) | |
puts response.body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, simplicity is the best.