Skip to content
Merged
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM python:2-slim

RUN mkdir -p /opt/app/
WORKDIR /opt/app/

RUN ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

ADD requirements.txt /opt/app/
ADD test_requirements.txt /opt/app/

RUN pip install -r /opt/app/requirements.txt
RUN pip install -r /opt/app/test_requirements.txt

ADD . /opt/app/

RUN python setup.py test
RUN python setup.py install

RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you setting this here and on line 6?

Copy link
Contributor Author

@TheConnMan TheConnMan Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests fail when run with the timezone set to UTC (#9) then the samples and events don't respect this timezone when sent in so they are 5 hours in the future if I don't set it back to UTC. I wanted to see if I was doing something incorrectly before I made the latter issue a GitHub issue.


ENV API_URL https://api.app.netuitive.com/ingest
ENV CUSTOM_API_KEY change-me-apikey

CMD python example/example.py
36 changes: 7 additions & 29 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,40 +112,18 @@ Check that our local time is set correctly (returns True/False)

``ApiClient.time_insync()``

Example
Docker Example
----------
The below example sets up the Netuitive Python client, creates an element ("MyElement") with attributes, a relationship, and tags and then passes in some samples. After the element is posted, the samples are cleared, an event is created and posted.
::

import netuitive
import time

ApiClient = netuitive.Client(api_key='aaaa9956110211e594444697f922ec7b')

MyElement = netuitive.Element()

MyElement.add_attribute('Language', 'Python')
MyElement.add_attribute('app_version', '7.0')

MyElement.add_relation('my_child_element')
Included in this project is an example python script (`example/example.py`) which can be built and run within a Docker container. To send test data into your Netuitive environment run the following:

MyElement.add_tag('Production', 'True')
MyElement.add_tag('app_tier', 'True')

timestamp = int(time.mktime(time.gmtime()))
MyElement.add_sample('app.error', timestamp, 1, host='appserver01')
MyElement.add_sample('app.request', timestamp, 10, host='appserver01')

ApiClient.post(MyElement)

MyElement.clear_samples()
::

MyEvent = netuitive.Event('appserver01', 'INFO', 'test event','this is a test message', 'INFO')
docker build -t netuitive-client-python .
docker run -e CUSTOM_API_KEY=<custom-api-key> netuitive-client-python

ApiClient.post_event(MyEvent)
::

if ApiClient.time_insync():
print('we have time sync with the server')
Make sure to use your **Custom** Netuitive datasource API key.

Copyright and License
---------------------
Expand Down
30 changes: 30 additions & 0 deletions example/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import netuitive
import time
import os

ApiClient = netuitive.Client(url=os.environ.get('API_URL'), api_key=os.environ.get('CUSTOM_API_KEY'))

MyElement = netuitive.Element()

MyElement.add_attribute('Language', 'Python')
MyElement.add_attribute('app_version', '7.0')

MyElement.add_relation('my_child_element')

MyElement.add_tag('Production', 'True')
MyElement.add_tag('app_tier', 'True')

timestamp = int(time.mktime(time.gmtime()))
MyElement.add_sample('app.error', timestamp, 1, host='appserver01')
MyElement.add_sample('app.request', timestamp, 10, host='appserver01')

ApiClient.post(MyElement)

MyElement.clear_samples()

MyEvent = netuitive.Event('appserver01', 'INFO', 'test event','this is a test message', 'INFO')

ApiClient.post_event(MyEvent)

if ApiClient.time_insync():
print('we have time sync with the server')