Git Product home page Git Product logo

sumologic-python-sdk's Introduction

Sumo Logic Python SDK

Community-supported Python interface to the Sumo Logic REST API. The idea is to make it easier to hit the API in Python code. Sample scripts available in the scripts folder. Please submit issues here via Github. Do not submit customer issues to Sumo Logic support (but REST API issues are of course supported).

TLS 1.2 Requirement

Sumo Logic only accepts connections from clients using TLS version 1.2 or greater. To utilize the content of this repo, ensure that it's running in an execution environment that is configured to use TLS 1.2 or greater.

Installing

pip install sumologic-sdk

How to use / examples

See scripts/

License

Copyright 2017 Sumo Logic Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributing

Please see CONTRIBUTING.md for guidelines

Support

This repository and the code within is not supported by Sumo Logic.

sumologic-python-sdk's People

Contributors

alexwaclawik avatar bbayles avatar blaise-sumo avatar charlessumo avatar cybercookiez avatar dependabot[bot] avatar duchatran avatar ericpohl avatar himanshu219 avatar himsharma01 avatar jpbottinelli avatar jwatroba avatar kasia-kujawa avatar kb18951452 avatar lei-sumo avatar mbabinski avatar mccartney avatar patristo avatar peterjmorgan avatar produceallthethings avatar raszi avatar rjury-sumo avatar rvmiller89 avatar sumovishal avatar tynick avatar upstart-swiss avatar yowayb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sumologic-python-sdk's Issues

Endpoint Verification is checking wrong variable

After getting the proper endpoint from _get_endpoint. The if statement checking for a forward slash at the end of the URL is checking the wrong endpoint variable. It's checking the endpoint variable passed in when initializing the class as opposed to self.endpoint.

Requests do not follow 401 behind corporate proxy

When trying to get the appropriate API URL, the get statement in the _get_endpoint() function would not follow redirects even though it the default setting is to allow_redirects was set to true,

Only seen this on a windows 10 host behind a corporate proxy with SSL offloading. This does not happen on macOS with no custom ssl ca bundles or behind any proxies.

Put and Post definations

Hi there,

I want to send logs using Sumologic-python-sdk.

I see there are two function in the code, which are put and post.

Can anyone one explain me how to use them, what are the parameters it accepts and how I should send payload to particular collector source.

No Details on "400 Client Error"

When the API doesn't return 200, you're using raise_for_status to throw exceptions:

  File "/usr/local/lib/python2.7/site-packages/sumologic/sumologic.py", line 77, in search_job_records
    r = self.get('/search/jobs/' + str(search_job['id']) + '/records', params)
  File "/usr/local/lib/python2.7/site-packages/sumologic/sumologic.py", line 43, in get
    r.raise_for_status()
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 825, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request

However, the problem with this is that, particular with 400 Client Error, the return JSON from Sumo indicates what exactly in the request is wrong. However, with this message, we are left with no idea what may be bad within a given request.

For example, if the start time isn't properly formatted when doing a search, the library shows this 400 Client Error but no information that the reason for failure is the timezone formatting.

It would be helpful to all developers, especially those new to Sumo, to add this information in the exception.

Records always empty

While using the search-job.py script the records returned are always:

{'fields': [{'name': '_count', 'fieldType': 'int', 'keyField': False}], 'records': []}

for query * | count
Using the UI I get many results.

Any suggestions?

__init__.py import doesn't work correctly w/ Python 3.6

Heyo,

The line from sumologic import * in init.py (https://github.com/SumoLogic/sumologic-python-sdk/blob/2ca5e97e4f7514a98cdf8ddd372a9ff00ea8b8a1/sumologic/__init__.py) doesn't work correctly in Python 3.6 because it uses an absolute import, and not a relative import. It ends up just importing its own (currently empty) package. As a result, from sumologic import SumoLogic doesn't work, and you have to import sumologic.sumologic to access the class:

$ python
Python 3.6.0 (default, Dec 24 2016, 00:01:50)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sumologic
>>> dir(sumologic)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'sumologic']
>>>
>>> from sumologic import SumoLogic
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'SumoLogic'
>>>
>>> from sumologic.sumologic import SumoLogic
>>> SumoLogic
<class 'sumologic.sumologic.SumoLogic'>

Synchronize SDK to latest API feature support

There are multiple APIs implemented server side that don't appear to be implemented in the SDK. There are also some methods in the SDK that don't appear to correspond to the documented API. Could the SDK be updated to true up support to current Sumo API standards?

Examples in API but not in client SDK:

Examples in SDK but not found in API documentation:

Discussion/Enhancement Proposal: Higher Level API Abstraction

I think it would be helpful to have a higher-level, object-based abstraction around the current API.
Is this something that other people would find valuable?

Somewhat like Boto3 Service Resources for the AWS API
With that, there are Waiter and Paginator objects that can handle the polling, pagination, automatic retries after rate limiting.
Similarly, a heirarchy of objects and collections of child objects, which can lazy load as needed.
An application no longer needs to be cluttered with polling logic.

collectors endpoint is broken if you have / on end of endpoint

when I call the collectors endpoint with this sdk it fails with a 500. I believe this might be because there are // in the url for example: https://api.us2.sumologic.com/api/v1//collectors

if I try to get back a list of collectors or access a single collector I now get an error where this worked up till a month or so ago.

sumo.collectors()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rick.jury/.local/share/virtualenvs/sumologic-api-tools-f4YSK5be/lib/python3.6/site-packages/sumologic/sumologic.py", line 99, in collectors
    r = self.get('/collectors', params)
  File "/Users/rick.jury/.local/share/virtualenvs/sumologic-api-tools-f4YSK5be/lib/python3.6/site-packages/sumologic/sumologic.py", line 53, in get
    r.raise_for_status()
  File "/Users/rick.jury/.local/share/virtualenvs/sumologic-api-tools-f4YSK5be/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: {"id":"YGMEC-MMS5N-UZJ1K","errors":[{"code":"internal.error","message":"Internal server error."}]} for url: https://api.us2.sumologic.com/api/v1//collectors

ez_setup issues

Is ez_setup really needed? pip installs break because of it. Here is traceback of it

$ pip install sumologic-sdk
You are using pip version 7.1.0, however version 8.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting sumologic-sdk
  Using cached sumologic-sdk-0.1.4.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/private/var/folders/jp/djdh4dx56011p3hf0m71p2306sp5p0/T/pip-build-o342kT/sumologic-sdk/setup.py", line 1, in <module>
        import ez_setup
    ImportError: No module named ez_setup

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/jp/djdh4dx56011p3hf0m71p2306sp5p0/T/pip-build-o342kT/sumologic-sdk

I will submit a patch fixing this. I don't really think using ez_setup is needed if we can just specify that setuptools is required to be installed as a prerequisite.

Jobs Message API return 401

Hi Team
sumo = SumoLogic(ACCESS_ID, ACCESS_KEY)
response = sumo.search_job(query, from_v, to, timeZone, True, autoParsingMode='Manual')
After calling the sumo.search_job_messages(response,8)
I am getting the below error though I am getting the job_id from search_job
raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: { "status" : 400, "id" : "2U5U6-YAO5P-DOFTB", "code" : "searchjob.generic", "message" : "Generic error." } for url: https://api.sumologic.com/api/v1/search/jobs/job_id/messages?limit=8&offset=0

I was trying with the below option:
auth = (ACCESS_ID, ACCESS_KEY)
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
results_url = f'https://api.sumologic.com/api/v1/search/jobs/{response['id']}/messages'
resp = requests.get(results_url, auth=auth, headers=headers)

I am getting 401 error code.

How to solve this?

Implement high level helper functions for asynchronous APIs

The API server implements several asynchronous APIs that require users to submit job, poll for status, and finally fetch results. It would be logical and would help fulfill the purpose of the Python SDK as a high level client to expose helper methods that support handling these asynchronous backend jobs smoothly. The goal would be for a single call to handle necessary functionality:

  1. Submit job
  2. Poll for completion
  3. Return results

Support should allow for some specification by user of things like poll period, maximum number of tries/timeout, etc. The higher level methods could then signal situations like timeouts and failures with exceptions or similar.

The outcome would be higher level support in the SDK that smooths out the user experience and enables simpler client code without the need to add in so much polling and retry logic, etc.

Similar ideas have been proposed in #3 and #32.

search-job-messages.py: requests.exceptions.HTTPError: 400 Client Error: Bad Request for url

Hi guys,

I'm looking into this sdk to understand how it all works. In general I will need to get all data and push it to my system.

I'm executing script like this:

$ cat query.sumoql | python search-job-messages.py <secret_id> <secret_key> `date +%s000` $(echo | awk "{print 1000+`date +%s000`}") EEST                     Traceback (most recent call last):
  File "search-job-messages.py", line 31, in <module>
    sj = sumo.search_job(q, fromTime, toTime, timeZone)
  File "build/bdist.cygwin-2.6.0-x86_64/egg/sumologic/sumologic.py", line 67, in search_job
  File "build/bdist.cygwin-2.6.0-x86_64/egg/sumologic/sumologic.py", line 52, in post
  File "/usr/lib/python2.7/site-packages/requests/models.py", line 862, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.us2.sumologic.com/api/v1/search/jobs

Ivan.

SDK Endpoint is printed to standard output

The SumoLogic constructor calls an internal _get_endpoint method, which prints an "SDK Endpoint" to standard output; e.g. SDK Endpoint https://api.us2.sumologic.com/api. This makes it difficult to write utilities that are intended to be used in a unix-style pipeline, such as outputting JSON that can be parsed manipulated downstream by tools such as jq.

Bug on Search Job - does not work if autoParsingMode is not specified

AutoParsing Mode is getting passed as null causing incomprehensible 500 errors. From reaching out to sumo support this is because it's passing that null.
This should either not be set if it's null (remove the key) or it should be set to either Manual or Automatic

def search_job(self, query, fromTime=None, toTime=None, timeZone='UTC', byReceiptTime=None, autoParsingMode=None):

New Release

Hi,

There's been a number of changes since the 0.1.7 release to pypi over a year ago in February 2017. Can you please tag and release a new version.

Thanks.

fail to obtain job status

Hi, i'm trying to access a job that was successfully created, but I keep getting even though the create job returns 202 status

{
"status" : 404,
"id" : "D0FMU-CJDYR-H0VCO",
"code" : "searchjob.jobid.invalid",
"message" : "Job ID is invalid."
}

Thanks!

Publish release on PyPI

Hello, v0.1.9 has been tagged for some time in the repository but has yet to be published to PyPI.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.