module Xcal module Parktronic module Routes module Alarms # Fetches latest alarms # # Accepted attributes: # +page+ set page, defaults to 1 # +per_page+ set per page value, defaults to 10 def get_paged_alarms(args = {}) args.merge!(:access_token => access_token) response = http.get("/#{api_version}/alarms?#{URI.encode_www_form(args)}") generic_response = Xcal::Parktronic::GenericResponse.new(response.body) response.code == '200' ? generic_response.alarms.map(&:alarm) : generic_response # TODO Add caching end alias :alarms :get_paged_alarms # Fetches alarm with specific ID # # Accepted attributes: # +id+ alarm ID def get_alarm(id) response = http.get("/#{api_version}/alarms/#{id}?access_token=#{access_token}") generic_response = Xcal::Parktronic::GenericResponse.new(response.body) response.code == '200' ? generic_response.alarm : generic_response # TODO Add caching end alias :alarm :get_alarm # Posts new alarm # # Alarm argument should be a hash of Alarm + Events data. # # Example of alarm data: # # +alarm+ : # { # :name => 'alarm name', # :originating_system => 'Source System', # :impact_level => 'low', # :tag_list => %w(taga tagb) # } # # Example of events array: # +events+ : # [ # { # :subject => 'EventSubj', # :description => 'EventDesc', # :host_impacted => 'host', # :initiated_at => '2013-11-22T01:00:24Z', # :service_impacted => 'EventSvc', # :incident_status => 'CRITICAL' # } # ] # def post_alarm(alarm = {}, events = []) request = Net::HTTP::Post.new("/#{api_version}/alarms", 'Content-Type' => 'application/json') request.body = { access_token: access_token, alarm: alarm, events: events }.to_json response = http.start { |net| net.request(request) } Xcal::Parktronic::GenericResponse.new(response.body) end end end end end