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

hoover fixes + enhancements #11

Open
wants to merge 3 commits into
base: master
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

updates to hoover

- add retry support to events
- change APIs to v2 url
  • Loading branch information
thehesiod committed Nov 24, 2015
commit 3d572a76ab91f8847bec4b7086e58e3cc60554a6
@@ -2,11 +2,14 @@
from hoover.exceptions import NotFound, AuthFail
from hoover.utils import time_translate
import logging

try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode
import requests
import requests.exceptions

try:
from simplejson import loads
except ImportError:
@@ -52,7 +55,7 @@ def inputs(self):
return self._inputs

def _inputs_init(self):
inputs = self._api_help('api/inputs')
inputs = self._api_help('apiv2/inputs')
self._inputs = [LogglyInput(i, self) for i in inputs]

@property
@@ -84,14 +87,30 @@ def search(self, q='*', **kwargs):
'''Thin wrapper on Loggly's text search API. First parameter is a query
string.'''
kwargs['q'] = q
return self._api_help('api/search', kwargs)
return self._api_help('apiv2/search', kwargs)

def events(self, search_result, num_retries=5, **kwargs):
'''Thin wrapper on Loggly's events API. First parameter is the result from search.'''
kwargs['rsid'] = search_result['rsid']['id']

# large requests may take some time
retries = 0
while retries < num_retries:
try:
return self._api_help('apiv2/events', kwargs)
except requests.exceptions.HTTPError as e:
if e.response.status_code == 504:
logging.getLogger('hoover').info('Retrying due to request timeout')
retries += 1
else:
raise

@time_translate
def facets(self, q='*', facetby='date', **kwargs):
'''Thin wrapper on Loggly's facet search API. facetby can be input, ip,
or a json parameter of the form json.foo'''
kwargs['q'] = q
return self._api_help('api/facets/%s' % facetby, kwargs)
return self._api_help('apiv2/facets/%s' % facetby, kwargs)

def create_input(self, name, service='syslogudp', description='',
json=False):
@@ -107,7 +126,7 @@ def create_input(self, name, service='syslogudp', description='',
format = json and 'json' or 'text'
params = {'name': name, 'service': service, 'description': description,
'format': format}
result = self._api_help('api/inputs', params, method='POST')
result = self._api_help('apiv2/inputs', params, method='POST')
try:
newinput = LogglyInput(result, self)
except:
@@ -4,7 +4,7 @@
from distutils.core import setup

setup(name='Hoover',
version='0.6.0',
version='0.6.2',
description="Library for logging to Loggly from within Python webapps",
author="Mike Blume",
author_email="mike@loggly.com",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.