class Opsgenie
Public Class Methods
fetch_json(uri, params, req_type)
click to toggle source
# File lib/opsgenie.rb, line 15 def self.fetch_json(uri, params, req_type) uri = URI(uri) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true begin if req_type=='post' res = https.post(uri.path, params) else uri.query = URI.encode_www_form(params) if params res = Net::HTTP.get_response(uri) end if res.is_a?(Net::HTTPSuccess) return JSON.parse(res.body) else return false end rescue return false end end
new(api_key)
click to toggle source
# File lib/opsgenie.rb, line 10 def initialize(api_key) @api_key = api_key @url_prefix = 'https://api.opsgenie.com/v1/json/alert' end
Public Instance Methods
send_alert(message)
click to toggle source
# File lib/opsgenie.rb, line 37 def send_alert message params = "{ \"apiKey\":\"#{@api_key}\", \"message\":\"#{message}\" }" response = Opsgenie.fetch_json(@url_prefix, params, 'post') return response==false ? 'Alert could not be generated.':'Alert generated.' end
test_alert()
click to toggle source
# File lib/opsgenie.rb, line 43 def test_alert puts "Testing alert service." params = "{ \"apiKey\":\"#{@api_key}\", \"message\":\"testalert\" }" response = Opsgenie.fetch_json(@url_prefix, params, 'post') return response==false ? 'Alert could not be generated.':'Alert generated.' end