diff --git a/lib/dogapi/v1/monitor.rb b/lib/dogapi/v1/monitor.rb index 6ec36250..5ecfdf42 100644 --- a/lib/dogapi/v1/monitor.rb +++ b/lib/dogapi/v1/monitor.rb @@ -52,10 +52,7 @@ def get_monitor(monitor_id, options = {}) # :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] - params[:group_states] = options[:group_states].join(',') - options.delete :group_states - end + params[:group_states] = options[:group_states].join(',') if options[:group_states] request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/#{monitor_id}", params, nil, false) rescue Exception => e @@ -87,8 +84,16 @@ def get_all_monitors(options = {}) # 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] - params[:group_states] = options[:group_states].join(',') - options.delete :group_states + params[:group_states] = options[:group_states] + params[:group_states] = params[:group_states].join(',') if params[:group_states].respond_to?(:join) + end + + # :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] + params[:tags] = options[:tags] + params[:tags] = params[:tags].join(',') if params[:tags].respond_to?(:join) end request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor", params, nil, false) diff --git a/tests/test_monitors.rb b/tests/test_monitors.rb index e8dbb3c1..58a739b3 100644 --- a/tests/test_monitors.rb +++ b/tests/test_monitors.rb @@ -38,17 +38,26 @@ def test_metric_alerts query1 = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100" query2 = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 200" + query3 = "avg(last_1h):sum:system.net.bytes_rcvd{host:host1} > 200" monitor_id1 = dog.monitor('metric alert', query1)[1]['id'] monitor_id2 = dog.monitor('metric alert', query2)[1]['id'] + monitor_id3 = dog.monitor('metric alert', query3)[1]['id'] status, monitors = dog.get_all_monitors(:group_states => ['alert', 'warn']) monitor1 = monitors.map{|m| m if m['id'] == monitor_id1}.compact[0] monitor2 = monitors.map{|m| m if m['id'] == monitor_id2}.compact[0] assert_equal monitor1['query'], query1, monitor1['query'] assert_equal monitor2['query'], query2, monitor2['query'] + status, monitors = dog.get_all_monitors(:tags => ['host:host1']) + monitor3 = monitors.map{|m| m if m['id'] == monitor_id3}.compact[0] + assert_equal monitor3['query'], query3, monitor3['query'] + assert_equal nil, monitors.map{|m| m if m['id'] == monitor_id1}.compact[0] + assert_equal nil, monitors.map{|m| m if m['id'] == monitor_id2}.compact[0] + dog.delete_monitor(monitor_id1) dog.delete_monitor(monitor_id2) + dog.delete_monitor(monitor_id3) end def test_checks