Skip to content

Instantly share code, notes, and snippets.

@ialiendeg
Last active October 5, 2020 07:26
Show Gist options
  • Save ialiendeg/12ec6fdef243cf48bfbf41cc18bce50f to your computer and use it in GitHub Desktop.
Save ialiendeg/12ec6fdef243cf48bfbf41cc18bce50f to your computer and use it in GitHub Desktop.
#!/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
@ialiendeg
Copy link
Author

Hi there! Thanks for answering me. I suppose I can use a different web hook, for example for teams..

I'm sorry, I lost the notification for this message. I suppose it is possible to use a different webhook, but I haven't tried myself. Maybe you had success... :)

@ialiendeg
Copy link
Author

it's the beauty indeed - simple and efficient one.

Yes, simplicity is the best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment