Skip to content

Commit

Permalink
Add hosts API (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
samanthadrago authored and pietdaniel committed Apr 27, 2018
1 parent adc49d5 commit b1468cf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion datadog/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from datadog.api.monitors import Monitor
from datadog.api.screenboards import Screenboard
from datadog.api.graphs import Graph, Embed
from datadog.api.hosts import Host
from datadog.api.hosts import Host, Hosts
from datadog.api.service_checks import ServiceCheck
from datadog.api.tags import Tag
from datadog.api.users import User
44 changes: 43 additions & 1 deletion datadog/api/hosts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datadog.api.resources import ActionAPIResource
from datadog.api.resources import ActionAPIResource, SearchableAPIResource


class Host(ActionAPIResource):
Expand Down Expand Up @@ -42,3 +42,45 @@ def unmute(cls, host_name):
"""
return super(Host, cls)._trigger_class_action('POST', 'unmute', host_name)


class Hosts(ActionAPIResource, SearchableAPIResource):
"""
A wrapper around Hosts HTTP API.
"""
_resource_name = 'hosts'

@classmethod
def search(cls, **params):
"""
Search among hosts live within the past 2 hours. Max 100
results at a time.
:param filter: query to filter search results
:type filter: string
:param sort_field: "status", "apps", "cpu", "iowait", or "load"
:type sort_field: string
:param sort_dir: "asc" or "desc"
:type sort_dir: string
:param start: host result to start at
:type start: integer
:param count: number of host results to return
:type count: integer
:returns: Dictionary representing the API's JSOn response
"""
return super(Hosts, cls)._search(**params)

@classmethod
def totals(cls):
"""
Get total number of hosts active and up.
:returns: Dictionary representing the API's JSON response
"""
return super(Hosts, cls)._trigger_class_action('GET', 'totals')
5 changes: 5 additions & 0 deletions datadog/api/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ def search(cls, **params):
:returns: Dictionary representing the API's JSON response
"""
# Deprecate the hosts search param
query = params.get('q', '').split(':')
if len(query) > 1 and query[0] == 'hosts':
print("[DEPRECATION] Infrastructure.search() is deprecated for ",
"hosts. Use `Hosts.search` instead.")
return super(Infrastructure, cls)._search(**params)

0 comments on commit b1468cf

Please sign in to comment.