Coder Social home page Coder Social logo

sumologic-python's Introduction

https://travis-ci.org/sijis/sumologic-python.svg?branch=master

sumologic-python

Sumologic's python api library

The library currently supports the following features:

  • search
  • collectors
from sumologic import Client, Collectors, Search

# Need a client to authenticate to service
client = Client(auth=('username', 'password'))

# collector usage
collector = Collectors(client)
for c in collector.get_collectors():
    print('{0}:{1}'.format(c['name'], c['alive']))

# find and delete a collector
c = collector.find('logserver')
c.delete()

# search usage
search = Search(client)
results = search.query('log1', formats='json')
print(results)

To see the library in use, go to sumologic-cli repo.

sumologic-python's People

Contributors

davegallant avatar sijis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sumologic-python's Issues

Project license

I'm considering using and contributing to the project, but I couldn't find its license anywhere. Can you clarify?

getting No JSON object could be decoded

Hi,

Trying to run this simple script in virtual environment on MacOS, Python 2.7.16

#!/usr/bin/env python

import os
from sumologic import Client, Collectors, Search

USENAME = os.environ['SUMOLOGIC_ACCESSID']
PASSWORD = os.environ['SUMOLOGIC_ACCESSKEY']

# Need a client to authenticate to service
client = Client(auth=(USENAME, PASSWORD))

# collector usage
collector = Collectors(client)
for c in collector.get_collectors():
    print('{0}:{1}'.format(c['name'], c['alive']))

and I'm getting this error:

Traceback (most recent call last):
  File "./script.py", line 14, in <module>
    for c in collector.get_collectors():
  File "/Users/user/Documents/SumoLogic/api/.venv/lib/python2.7/site-packages/sumologic/collectors.py", line 41, in get_collectors
    results = request.json()['collectors']
  File "/Users/user/Documents/SumoLogic/api/.venv/lib/python2.7/site-packages/requests/models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
pip freeze
certifi==2020.6.20
chardet==3.0.4
idna==2.10
requests==2.24.0
sumologic==0.1.4
urllib3==1.25.11

what am I doing wrong ?
the credentials are valid.

SSLError name mismatch

I am currently seeing this only on my CentOS 5.6 machine with python2.6 but no error on OS X which I originally developed my script on. This seems to be failing on the get_collectors method on line containing "collectors = coll.get_collectors()"

$ python26 sumo_standard.py
Traceback (most recent call last):
File "sumo_standard.py", line 24, in
collectors = coll.get_collectors()
File "/usr/lib/python2.6/site-packages/sumologic/collectors.py", line 55, in get_collectors
request = requests.get(self.url, params=options, auth=self.auth)
File "/usr/lib/python2.6/site-packages/requests/api.py", line 54, in get
return request('get', url, *_kwargs)
File "/usr/lib/python2.6/site-packages/requests/safe_mode.py", line 37, in wrapped
return function(method, url, *_kwargs)
File "/usr/lib/python2.6/site-packages/requests/api.py", line 42, in request
return s.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.6/site-packages/requests/sessions.py", line 230, in request
r.send(prefetch=prefetch)
File "/usr/lib/python2.6/site-packages/requests/models.py", line 613, in send
raise SSLError(e)
requests.exceptions.SSLError: hostname 'api.sumologic.com' doesn't match u'service.sumologic.com'

author = 'xxx'
import sumologic.client
import sumologic.search
import sumologic.collectors
import requests
import json
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import smtplib

ACCESS_ID='xxxx'

ACCESS_KEY='xxx'

Dev Access Credentials

ACCESS_ID='xxx'

ACCESS_KEY='xxx'

Production Access Credentials

ACCESS_ID='xx'
ACCESS_KEY='xxx'

conn = sumologic.client.Client(auth=(ACCESS_ID, ACCESS_KEY))
coll = sumologic.collectors.Collectors(conn)
collectors = coll.get_collectors()

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.