Skip to content

Commit

Permalink
Merge pull request #94 from signalfx/cory-get-dashboards
Browse files Browse the repository at this point in the history
Add some dashboard and dashboard group methods
  • Loading branch information
cory-signalfx authored Jan 16, 2020
2 parents 4fc6b03 + 99922fc commit e7d8777
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions signalfx/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SignalFxRestClient(object):

_CHART_ENDPOINT_SUFFIX = 'v2/chart'
_DASHBOARD_ENDPOINT_SUFFIX = 'v2/dashboard'
_DASHBOARD_GROUP_ENDPOINT_SUFFIX = 'v2/dashboardgroup'
_METRIC_ENDPOINT_SUFFIX = 'v2/metric'
_DIMENSION_ENDPOINT_SUFFIX = 'v2/dimension'
_DETECTOR_ENDPOINT_SUFFIX = 'v2/detector'
Expand Down Expand Up @@ -355,6 +356,40 @@ def get_chart(self, id, **kwargs):
**kwargs)
return resp

# functionality related to dashboard groups
def get_dashboard_group(self, id, **kwargs):
""""Retrieve a (v2) dashboard group by id.
"""
resp = self._get_object_by_name(self._DASHBOARD_GROUP_ENDPOINT_SUFFIX,
id, **kwargs)
return resp

def get_dashboard_groups(self, name=None, batch_size=100, **kwargs):
"""Retrieve all (v2) dashboard groupss matching the given name; all (v2)
dashboard groups otherwise.
Note that this method will loop through the paging of the results and
accumulate all dashboard groups that match the query.
"""
dashgroups = []
offset = 0
while True:
resp = self._get(
self._u(self._DASHBOARD_GROUP_ENDPOINT_SUFFIX),
params={
'offset': offset,
'limit': batch_size,
'name': name,
},
**kwargs)
resp.raise_for_status()
data = resp.json()
dashgroups += data['results']
if len(dashgroups) == data['count']:
break
offset = len(dashgroups)
return dashgroups

# functionality related to dashboards
def get_dashboard(self, id, **kwargs):
""""Retrieve a (v2) dashboard by id.
Expand All @@ -363,6 +398,32 @@ def get_dashboard(self, id, **kwargs):
**kwargs)
return resp

def get_dashboards(self, name=None, batch_size=100, **kwargs):
"""Retrieve all (v2) dashboards matching the given name; all (v2)
dashboards otherwise.
Note that this method will loop through the paging of the results and
accumulate all dashboards that match the query. This may be expensive.
"""
dashboards = []
offset = 0
while True:
resp = self._get(
self._u(self._DASHBOARD_ENDPOINT_SUFFIX),
params={
'offset': offset,
'limit': batch_size,
'name': name,
},
**kwargs)
resp.raise_for_status()
data = resp.json()
dashboards += data['results']
if len(dashboards) == data['count']:
break
offset = len(dashboards)
return dashboards

# functionality related to detectors
def get_detector(self, id, **kwargs):
""""Retrieve a (v2) detector by id.
Expand Down

0 comments on commit e7d8777

Please sign in to comment.