def notify(message, time, priority, category, host)
data = {
:message => message,
:time => time,
:priority => priority,
:category => category,
:host => host
}
uri = URI.parse(arg(:url))
http = Net::HTTP.new(uri.host, uri.port)
req = nil
res = nil
case arg(:format)
when :form
req = Net::HTTP::Post.new(uri.path)
req.set_form_data(data)
when :json
req = Net::HTTP::Post.new(uri.path)
req.body = data.to_json
end
res = http.request(req)
case res
when Net::HTTPSuccess
self.info = "sent webhook to #{arg(:url)}"
else
self.info = "failed to send webhook to #{arg(:url)}: #{res.error!}"
end
rescue Object => e
applog(nil, :info, "failed to send email to #{arg(:url)}: #{e.message}")
applog(nil, :debug, e.backtrace.join("\n"))
end