Core

Setup the CirconusClient:

from circonus import CirconusClient

CIRCONUS_API_APP_NAME = "my-circonus-app"
CIRCONUS_APP_TOKEN = "generated-by-circonus-ui"

circonus = CirconusClient(CIRCONUS_API_APP_NAME, CIRCONUS_APP_TOKEN)

Authentication is performed via custom Circonus HTTP request headers. The headers are set for all subsequent requests made via the circonus object:

print circonus.api_headers
{'Accept': 'application/json',
'X-Circonus-App-Name': 'my-circonus-app',
'X-Circonus-Auth-Token': 'generated-in-circonus-ui'}

Get

The current user:

response = circonus.get("user/current")
print response.json()
{u'_cid': u'/user/1234',
 u'contact_info': {u'sms': u'', u'xmpp': u''},
 u'email': u'user@example.com',
 u'firstname': u'Ewe',
 u'lastname': u'Sure'}

All users:

response = circonus.get("user")
print response.json()
[{u'_cid': u'/user/1234',
  u'contact_info': {u'sms': u'', u'xmpp': u''},
  u'email': u'user0@example.com',
  u'firstname': u'Ewe',
  u'lastname': u'Sure'},
 {u'_cid': u'/user/1235',
  u'contact_info': {u'sms': u'', u'xmpp': u''},
  u'email': u'user1@example.com',
  u'firstname': u'Ewe',
  u'lastname': u'Sure Jr.'},
  ...]

A specific graph:

response = circonus.get("graph/6c53484e-b0ad-4652-8b4b-6645fae0db7b")
print response.json()
{u'_cid': u'/graph/6c53484e-b0ad-4652-8b4b-6645fae0db7b',
 u'access_keys': [],
 u'composites': [],
 u'datapoints': [...],
 u'description': u'',
 u'guides': [],
 u'line_style': u'stepped',
 u'logarithmic_left_y': None,
 u'logarithmic_right_y': None,
 u'max_left_y': None,
 u'max_right_y': None,
 u'metric_clusters': [],
 u'min_left_y': u'0',
 u'min_right_y': u'0',
 u'notes': None,
 u'style': u'area',
 u'tags': [],
 u'title': u'cpu usage'}

Graphs filtered by title:

response = circonus.get("graph", {"f_title_wildcard": "*cpu*"})
print response.json()
[{u'_cid': u'/graph/6c53484e-b0ad-4652-8b4b-6645fae0db7b',
 u'access_keys': [],
 u'composites': [],
 u'datapoints': [...],
 u'description': u'',
 u'guides': [],
 u'line_style': u'stepped',
 u'logarithmic_left_y': None,
 u'logarithmic_right_y': None,
 u'max_left_y': None,
 u'max_right_y': None,
 u'metric_clusters': [],
 u'min_left_y': u'0',
 u'min_right_y': u'0',
 u'notes': None,
 u'style': u'area',
 u'tags': [],
 u'title': u'cpu usage'}]

Create

A check bundle:

data = {
    "brokers": ["/broker/123"],
    "metrics": [{"type": "text", "name": "dummy"}],
    "target": "10.0.0.1",
    "type": "collectd"
}
response = circonus.create("check_bundle", data)
print response.json()
{u'_checks': [u'/check/123456'],
 u'_cid': u'/check_bundle/12345',
 u'_created': 1418331830,
 u'_last_modified': 1418331830,
 u'_last_modified_by': u'/user/1234',
 u'brokers': [u'/broker/123'],
 u'config': {u'asynch_metrics': u'false'},
 u'display_name': u'10.0.0.1 - collectd',
 u'metrics': [{u'name': u'dummy', u'status': u'active', u'type': u'text'}],
 u'notes': None,
 u'period': 60,
 u'status': u'active',
 u'tags': [u'telemetry:collectd'],
 u'target': u'10.0.0.1',
 u'timeout': 10,
 u'type': u'collectd'}

Update

A check bundle to remove all of the tags associated with it:

response = circonus.update("/check_bundle/12345", {"tags": []})
print response.json()
{u'_checks': [u'/check/123456'],
 u'_cid': u'/check_bundle/12345',
 u'_created': 1418331830,
 u'_last_modified': 1418331830,
 u'_last_modified_by': u'/user/1234',
 u'brokers': [u'/broker/123'],
 u'config': {u'asynch_metrics': u'false'},
 u'display_name': u'10.0.0.1 - collectd',
 u'metrics': [{u'name': u'dummy', u'status': u'active', u'type': u'text'}],
 u'notes': None,
 u'period': 60,
 u'status': u'active',
 u'tags': [],
 u'target': u'10.0.0.1',
 u'timeout': 10,
 u'type': u'collectd'}

Delete

A tag:

response = circonus.delete("tag/category:tag")
print response.status_code
204

A HTTP status code 204 No Content indicates that the resource was deleted successfully.

Table Of Contents

Related Topics