Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion src/dogapi/http/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def unmute_monitor(self, monitor_id, scope=None):

class DowntimeApi(object):

def schedule_downtime(self, scope, start, end=None):
def schedule_downtime(self, scope, start, end=None, message=None):
"""
Schedule downtime over *scope* from *start* to *end*, where *start* and
*end* are POSIX timestamps. If *end* is omitted then the downtime will
Expand All @@ -188,10 +188,29 @@ def schedule_downtime(self, scope, start, end=None):
}
if end:
body['end'] = end
if message:
body['message'] = message
return self.http_request('POST', '/downtime', body,
response_formatter=lambda x: x['id'],
)

def update_downtime(self, downtime_id, scope=None, start=None, end=None, message=None):
"""
Update downtime parameters.
"""
body = {}
if scope:
body['scope'] = scope
if start:
body['start'] = start
if end:
body['end'] = end
if message:
body['message'] = message
return self.http_request('PUT', '/downtime/%s' % downtime_id, body,
response_formatter=lambda x: x['id'],
)

def get_downtime(self, downtime_id):
"""
Get the downtime identified by *downtime_id*
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/test_dog_http_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,19 @@ def test_monitor_muting(self):
def test_downtime(self):
start = int(time.time())
end = start + 1000
downtime_id = dog.schedule_downtime('env:staging', start, end)
downtime_id = dog.schedule_downtime('env:staging', start, end, "Message!")
dt = dog.get_downtime(downtime_id)
nt.assert_equal(dt['start'], start)
nt.assert_equal(dt['end'], end)
nt.assert_equal(dt['scope'], ['env:staging'])
nt.assert_equal(dt['message'], "Message!")

dog.update_downtime('env:prod', start + 1, end + 1, 'New Message!')
dt = dog.get_downtime(downtime_id)
nt.assert_equal(dt['start'], start + 1)
nt.assert_equal(dt['end'], end + 1)
nt.assert_equal(dt['scope'], ['env:prod'])
nt.assert_equal(dt['message'], "New Message!")

dog.cancel_downtime(downtime_id)

Expand Down