Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] basic device add #7

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions kentikapi/v5/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Kentik Python API
=================

Site API
----------------
- fetch

Device API
----------------
- create

HyperTagging API
----------------

Expand Down
57 changes: 57 additions & 0 deletions kentikapi/v5/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python

from __future__ import print_function
from builtins import str
from builtins import object
import json
import requests


"""Device API client"""


class Device(object):
"""Creates Kentik Device"""

def __init__(self, api_email, api_token, base_url="https://api.kentik.com"):
self.api_email = api_email
self.api_token = api_token
self.base_url = base_url

def create(
self,
host,
host_ip,
site_id,
plan_id,
community="public",
url="https://api.kentik.com/api/v5/device",
):
headers = {
"User-Agent": "kentik-python-api/0.2",
"Content-Type": "application/json",
"X-CH-Auth-Email": self.api_email,
"X-CH-Auth-API-Token": self.api_token,
}
data = {
"device": {
"device_name": host.replace(".", "_"),
"device_type": "router",
"device_description": host,
"sending_ips": [host_ip],
"device_sample_rate": 4096,
"plan_id": plan_id,
"site_id": site_id,
"minimize_snmp": False,
"device_snmp_ip": host_ip,
"device_snmp_community": community,
"device_bgp_type": "none",
}
}
resp = requests.post(url, headers=headers, json=data)

# break out at first sign of trouble
resp.raise_for_status()
device = resp.json()

return device
37 changes: 37 additions & 0 deletions kentikapi/v5/plan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

from __future__ import print_function
from builtins import str
from builtins import object
import json
import requests


"""Plan API client"""


class Plan(object):
"""Returns all Kentik Plans"""

def __init__(self, api_email, api_token, base_url="https://api.kentik.com"):
self.api_email = api_email
self.api_token = api_token
self.base_url = base_url

def list(self, url="https://api.kentik.com/api/v5/plans"):
headers = {
"User-Agent": "kentik-python-api/0.2",
"Content-Type": "application/json",
"X-CH-Auth-Email": self.api_email,
"X-CH-Auth-API-Token": self.api_token,
}
resp = requests.get(url, headers=headers)

# print the HTTP response to help debug
# print(resp.text)

# break out at first sign of trouble
resp.raise_for_status()
plans = resp.json()

return plans
37 changes: 37 additions & 0 deletions kentikapi/v5/site.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

from __future__ import print_function
from builtins import str
from builtins import object
import json
import requests


"""Site API client"""


class Site(object):
"""Returns all Kentik Sites"""

def __init__(self, api_email, api_token, base_url="https://api.kentik.com"):
self.api_email = api_email
self.api_token = api_token
self.base_url = base_url

def list(self, url="https://api.kentik.com/api/v5/sites"):
headers = {
"User-Agent": "kentik-python-api/0.2",
"Content-Type": "application/json",
"X-CH-Auth-Email": self.api_email,
"X-CH-Auth-API-Token": self.api_token,
}
resp = requests.get(url, headers=headers)

# print the HTTP response to help debug
# print(resp.text)

# break out at first sign of trouble
resp.raise_for_status()
sites = resp.json()

return sites
4 changes: 2 additions & 2 deletions kentikapi/v5/tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def _submit_batch(self, url, batch):

guid = ""
headers = {
'User-Agent': 'kentik-python-api/0.1',
'User-Agent': 'kentik-python-api/0.2',
'Content-Type': 'application/json',
'X-CH-Auth-Email': self.api_email,
'X-CH-Auth-API-Token': self.api_token
Expand Down Expand Up @@ -454,7 +454,7 @@ def fetch_batch_status(self, guid):
"""Fetch the status of a batch, given the guid"""
url = '%s/api/v5/batch/%s/status' % (self.base_url, guid)
headers = {
'User-Agent': 'kentik-python-api/0.1',
'User-Agent': 'kentik-python-api/0.2',
'Content-Type': 'application/json',
'X-CH-Auth-Email': self.api_email,
'X-CH-Auth-API-Token': self.api_token
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='kentikapi',
version='0.1.10',
version='0.2.0',
author='Blake Caldwell',
packages=find_packages(),
url='https://github.com/kentik/api-client',
Expand Down