lib/ragios-client.rb in ragios-client-0.0.5 vs lib/ragios-client.rb in ragios-client-0.0.6

- old
+ new

@@ -23,39 +23,55 @@ @username = username @password = password auth_session end - def add(monitor) + def create(monitor) api_request { RestClient.post "#{address_port}/monitors/", generate_json(monitor), http_request_options } end def find(monitor_id) api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/", auth_cookie } end - def all - api_request { RestClient.get "#{address_port}/monitors/", auth_cookie } + def all(limit = nil) + params = limit ? "?take=#{limit}" : "" + api_request { RestClient.get "#{address_port}/monitors#{params}", auth_cookie } end def stop(monitor_id) api_request { RestClient.put "#{address_port}/monitors/#{monitor_id}",{:status => "stopped"}, http_request_options } end - def restart(monitor_id) + def start(monitor_id) api_request { RestClient.put "#{address_port}/monitors/#{monitor_id}",{:status => "active"},http_request_options } end def delete(monitor_id) api_request { RestClient.delete "#{address_port}/monitors/#{monitor_id}", auth_cookie } end def where(options) - api_request { RestClient.get "#{address_port}/monitors?#{URI.encode_www_form(options)}", auth_cookie } + api_request { RestClient.get "#{address_port}/monitors/attributes?#{URI.encode_www_form(options)}", auth_cookie } end def update(monitor_id, options) api_request { RestClient.put "#{address_port}/monitors/#{monitor_id}",generate_json(options), http_request_options } end - + def events(monitor_id, startdate, enddate, limit=nil) + api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/events", {params: options(startdate, enddate, limit)} } + end + def events_by_type(monitor_id, type, startdate, enddate, limit=nil) + api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/events_by_type/#{type}", {params: options(startdate, enddate, limit)} } + end + def events_by_state(monitor_id, state, startdate, enddate, limit=nil) + api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/events_by_state/#{state}", {params: options(startdate, enddate, limit)} } + end def test(monitor_id) api_request { RestClient.post "#{address_port}/tests", {:id => monitor_id}, http_request_options } end private + def options(startdate, enddate, limit = nil) + options = {} + options[:start_date] = startdate + options[:end_date] = enddate + options[:take] = limit if limit + options + end def api_request response = yield parse_json(response) rescue => e raise_error(e)