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 |
Hi!. You can do it like this (in monit config file):
...
# Check swap usage
if swap usage > 60% then exec /root/slack_monit_alert.rb
...
# Check device free space
check device root with path /
if SPACE FREE < 1 GB then exec /root/slack_monit_alert.rb
...
# Check service availability
check process nginx matching nginx
start program = "/bin/systemctl start nginx"
stop program = "/bin/systemctl stop nginx"
if failed port 80 protocol http with timeout 20 seconds then exec /root/slack_monit_alert.rb
else if succeeded for 2 cycle then exec /root/slack_monit_alert.rb
Hi there! Thanks for answering me. I suppose I can use a different web hook, for example for teams..
it's the beauty indeed - simple and efficient one.
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... :)
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
Hi there! How to use it with monit?