Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow additional options to be passed to monitor API calls #125

Merged
merged 1 commit into from
Apr 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions lib/dogapi/v1/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def update_monitor(monitor_id, query, options)
end

def get_monitor(monitor_id, options = {})
extra_params = options.clone
# :group_states is an optional list of statuses to filter returned
# groups. If no value is given then no group states will be returned.
# Possible values are: "all", "ok", "warn", "alert", "no data".
extra_params = {}
extra_params[:group_states] = options[:group_states].join(',') if options[:group_states]
extra_params[:group_states] = extra_params[:group_states].join(',') if extra_params[:group_states]

request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/#{monitor_id}", extra_params, nil, false)
end
Expand All @@ -39,27 +39,16 @@ def delete_monitor(monitor_id)
end

def get_all_monitors(options = {})
extra_params = {}
extra_params = options.clone
# :group_states is an optional list of statuses to filter returned
# groups. If no value is given then no group states will be returned.
# Possible values are: "all", "ok", "warn", "alert", "no data".
if options[:group_states]
extra_params[:group_states] = options[:group_states]
extra_params[:group_states] = extra_params[:group_states].join(',') if extra_params[:group_states].respond_to?(:join)
end
extra_params[:group_states] = extra_params[:group_states].join(',') if extra_params[:group_states].respond_to?(:join)

# :tags is an optional list of scope tags to filter the list of monitors
# returned. If no value is given, then all monitors, regardless of
# scope, will be returned.
if options[:tags]
extra_params[:tags] = options[:tags]
extra_params[:tags] = extra_params[:tags].join(',') if extra_params[:tags].respond_to?(:join)
end

# :name is a string to filter monitors by name
if options[:name]
extra_params[:name] = options[:name]
end
extra_params[:tags] = extra_params[:tags].join(',') if extra_params[:tags].respond_to?(:join)

request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor", extra_params, nil, false)
end
Expand Down Expand Up @@ -104,13 +93,7 @@ def cancel_downtime(downtime_id)
end

def get_all_downtimes(options = {})
extra_params = {}
if options[:current_only]
extra_params[:current_only] = options[:current_only]
options.delete :current_only
end

request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime", extra_params, nil, false)
request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime", options, nil, false)
end

#
Expand Down