Skip to content

Commit

Permalink
Moving the base url to a helper method, using the same resource ids o…
Browse files Browse the repository at this point in the history
…utput

across all datadog resources to be consistent
  • Loading branch information
AmineChikhaoui committed Feb 27, 2017
1 parent fd000bd commit 2f7a030
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
5 changes: 4 additions & 1 deletion nixops/datadog_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ def get_template_variables(defn):
tvariable['prefix'] = var['prefix']
tvariable['default'] = var['default']
template_variables.append(tvariable)
return template_variables
return template_variables

def get_base_url():
return "https://app.datadoghq.com/"
11 changes: 9 additions & 2 deletions nixops/resources/datadog-monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self, depl, name, id):
nixops.resources.ResourceState.__init__(self, depl, name, id)
self._dd_api = None
self._key_options = None
self._monitor_url = nixops.datadog_utils.get_base_url()+"monitors#"

def _exists(self):
return self.state != self.MISSING
Expand All @@ -52,11 +53,17 @@ def show_type(self):

@property
def resource_id(self):
return "https://app.datadoghq.com/monitors#{0}".format(self.monitor_id) if self.monitor_id else None

return self._monitor_url + self.monitor_id if self.monitor_id else None
def get_definition_prefix(self):
return "resources.datadogMonitors."

def get_physical_spec(self):
return {'url': self._monitor_url + self.monitor_id } if self.monitor_id else {}

def prefix_definition(self, attr):
return {('resources', 'datadogMonitors'): attr}

def connect(self, app_key, api_key):
if self._dd_api: return
self._dd_api, self._key_options = nixops.datadog_utils.initializeDatadog(app_key=app_key, api_key=api_key)
Expand Down
13 changes: 9 additions & 4 deletions nixops/resources/datadog-screenboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ def __init__(self, depl, name, id):
nixops.resources.ResourceState.__init__(self, depl, name, id)
self._dd_api = None
self._key_options = None
self._screen_url = nixops.datadog_utils.get_base_url()+"screen/"

def show_type(self):
s = super(DatadogScreenboardState, self).show_type()
return s

@property
def resource_id(self):
r = self.board_title
if self.screenboard_id: r = "{0} [ {1} ]".format(r, self.screenboard_id)
return r
return self._screen_url + self.screenboard_id if self.screenboard_id else None

def get_physical_spec(self):
return {'url': self._screen_url + self.screenboard_id } if self.screenboard_id else {}

def prefix_definition(self, attr):
return {('resources', 'datadogScreenboards'): attr}

def get_definition_prefix(self):
return "resources.datadogScreenboards."
Expand Down Expand Up @@ -121,4 +126,4 @@ def _destroy(self):

def destroy(self, wipe=False):
self._destroy()
return True
return True
7 changes: 3 additions & 4 deletions nixops/resources/datadog-timeboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,21 @@ def __init__(self, depl, name, id):
nixops.resources.ResourceState.__init__(self, depl, name, id)
self._dd_api = None
self._key_options = None
self._dash_url = nixops.datadog_utils.get_base_url()+"dash/"

def show_type(self):
s = super(DatadogTimeboardState, self).show_type()
return s

@property
def resource_id(self):
t = self.title
if self.url: t = "{0} [ {1} ]".format(t, self.url)
return t
return self._dash_url + self.timeboard_id if self.timeboard_id else None

def prefix_definition(self, attr):
return {('resources', 'datadogTimeboards'): attr}

def get_physical_spec(self):
return {'url': self.url}
return {'url': self._dash_url + self.timeboard_id } if self.timeboard_id else {}

def get_definition_prefix(self):
return "resources.datadogTimeboards."
Expand Down

0 comments on commit 2f7a030

Please sign in to comment.