Skip to content

Instantly share code, notes, and snippets.

@msaladna
Created June 6, 2018 03:22
Show Gist options
  • Save msaladna/b90c1bad7cb407cad09f24b08ca0460c to your computer and use it in GitHub Desktop.
Save msaladna/b90c1bad7cb407cad09f24b08ca0460c to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'net/https'
PO_TOKEN={{ PUSHOVER_TOKEN }}
PO_USER={{ PUSHOVER_USER }}
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|Too many/ =~ 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" => PO_TOKEN,
"user" => PO_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