GithubHelp home page GithubHelp logo

pysensu's Introduction

Sensu client for python

https://travis-ci.org/sangoma/pysensu.png?branch=master https://pypip.in/d/pysensu-ng/badge.png

This is a client to interact with the Sensu API

Features

  • Includes methods for some entrypoints (clients, events, checks, stashes) of the Sensu API (0.24) IMPORTANT: from 0.6.0 release we are supporting Sensu API 0.24+ .. backward compatibility with previous versions of Sensu API might be broken.
  • Includes methods for handle subscriptions info (nodes subscribed to a specific channel)

Trivial Example

from pysensu.api import SensuAPI

url = 'http://localhost:4567'
my_sensu = SensuAPI(url, username=username, password=password)
print(my_sensu.get_info())

DEBUG

To enable debug import logging module and set the debug level

import logging
logging.getLogger('pysensu.api').setLevel(logging.DEBUG)

Exceptions

You can handle an exception using a code like this. Note: Sensu API give you a 404 code if a client does not exists.

import pysensu.api

url = 'http://localhost:4567'
my_sensu = pysensu.api.SensuAPI(url)
client = "testclient"

try:
    print(my_sensu.get_client_data(client))
except pysensu.api.SensuAPIException as e:
    if "404" in str(e):
        print("{} does not exists on sensu api".format(client))
    else:
        raise e

pysensu's People

Contributors

angvp avatar angvp-sng avatar lindsayhill avatar ryan-mccabe avatar wcastello avatar zagy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

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

pysensu's Issues

Logging output in case of exception

The logger output strings in case of exception, so also if you handle the exception, you have output in your console.
To reproduce try to query a client that does not exists and handle the exception, you will find a 404 in the output.

The problem is related to logger.warning and logger.error, we could set logger to debug, so who want to debug the problem need only to set debug in his own script.

Bug on bad request status

Hi,
I tried to make a query with a client that does not exists and I have this error in
API pysensu/api.py", line 59, in _request elif resp.status_code.startswith('400'): AttributeError: 'int' object has no attribute 'startswith'

This is because the resp.status.code is an integer, so or we change it to str and use starswith
elif str(resp.status_code).startswith('400'):
or we can use
elif resp.status_code == 400:

Just to understand: why you distinguish 400 from other errors?
Maybe, do you want a different exception messages for all the 40* errors?
If so we need the startswith but with only 40 and not 400:
elif str(resp.status_code).startswith('40'):

If we decide how we want to proceed and manage 40* errors, I could write the related code and send a merge requests .

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.