-
-
Save jsnfwlr/cce731c8aa18f11169dc7e56ca23de1c to your computer and use it in GitHub Desktop.
Monit -> Pushover bridge
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' | |
re = Regexp.new('\bService\s*(?<svc>[^$]+)^$^\s*Date:\s*(?<date>.*?)$[\r\n]{1,2} | |
^\s*Action:\s*(?<action>.*?)$[\r\n]{1,2} | |
^\s*Host:\s*(?<host>(?<node>[^.]+).*?)$[\r\n]{1,2} | |
^\s*Description:\s*(?<desc>.*?)$', Regexp::MULTILINE|Regexp::EXTENDED) | |
# Take mail straight from STDIN | |
msg = ARGF.read | |
m = re.match(msg) || exit | |
uri = URI.parse("https://api.pushover.net/1/messages.json") | |
http = Net::HTTP.new(uri.host, uri.port) | |
# Oh our root certs are so old :( | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
http.use_ssl = uri.to_s[4] == 's' | |
priority = 0 | |
if /Does not exist mysql/ =~ msg | |
priority = 2 | |
end | |
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' => 'application/json'}) | |
request.set_form_data({ | |
"priority" => priority, | |
"expire" => 3600, | |
"retry" => 120, | |
"token" => "INSERT YOUR TOKEN", | |
"user" => "INSERT YOUR USER", | |
"message" => "[#{m[:node]}] #{m[:svc]} #{m[:action]} - #{m[:desc]}" | |
}) | |
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