Skip to content

Commit

Permalink
Merge pull request #67 from DataDog/add_host_muting
Browse files Browse the repository at this point in the history
Add methods + tests for host muting
  • Loading branch information
Arthur committed May 27, 2015
2 parents a4d3e1c + 83300e5 commit 2475833
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/dogapi/facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,18 @@ def get_all_downtimes(options = {})
@monitor_svc.get_all_downtimes(options)
end

#
# HOST MUTING
#

def mute_host(hostname, options = {})
@monitor_svc.mute_host(hostname, options)
end

def unmute_host(hostname)
@monitor_svc.unmute_host(hostname)
end

#
# SERVICE CHECKS
#
Expand Down
27 changes: 27 additions & 0 deletions lib/dogapi/v1/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,33 @@ def get_all_downtimes(options = {})
end
end

#
# HOST MUTING

def mute_host(hostname, options = {})
begin
params = {
:api_key => @api_key,
:application_key => @application_key
}

request(Net::HTTP::Post, "/api/#{API_VERSION}/host/#{hostname}/mute", params, options, true)
rescue Exception => e
suppress_error_if_silent e
end
end
def unmute_host(hostname)
begin
params = {
:api_key => @api_key,
:application_key => @application_key
}

request(Net::HTTP::Post, "/api/#{API_VERSION}/host/#{hostname}/unmute", params, nil, true)
rescue Exception => e
suppress_error_if_silent e
end
end
end

end
Expand Down
34 changes: 34 additions & 0 deletions tests/test_monitors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,40 @@ def test_downtime
dog.cancel_downtime(downtime_id)
end

def test_host_muting
dog = Dogapi::Client.new(@api_key, @app_key)
hostname = 'test.host'

# Reset test
dog.unmute_host(hostname)

message = "Muting this host for a test."
end_ts = Time.now.to_i + 60 * 60

res_code, res = dog.mute_host(hostname, :end => end_ts, :message => message)
assert_equal res_code, "200", res_code
assert_equal res["action"], "Muted", res["action"]
assert_equal res["hostname"], hostname, res["hostname"]
assert_equal res["message"], message, res["message"]
assert_equal res["end"], end_ts, res["end"]

# muting the same host multiple times should fail unless override is true
end_ts2 = end_ts + 60 * 15
res_code, res = dog.mute_host(hostname, :end => end_ts2)
assert_equal res_code, "400", res_code

res_code, res = dog.mute_host(hostname, :end => end_ts2, :override => true)
assert_equal res_code, "200", res_code
assert_equal res["action"], "Muted", res["action"]
assert_equal res["hostname"], hostname, res["hostname"]
assert_equal res["end"], end_ts2, res["end"]

res_code, res = dog.unmute_host(hostname)
assert_equal res_code, "200", res_code
assert_equal res["action"], "Unmuted", res["action"]
assert_equal res["hostname"], hostname, res["hostname"]
end

def test_service_checks
dog = Dogapi::Client.new(@api_key, @app_key)
status, response = dog.service_check('app.ok', 'app1', 1)
Expand Down

0 comments on commit 2475833

Please sign in to comment.