Giter Site home page Giter Site logo

python-mk-livestatus's Introduction

Python MK Livestatus parser

Author

Michael Fladischer

Version

0.5-dev0

Access the data returned from MK Livestatus queries as Python lists or dictionaries. It does this by sending queries to the MK Livestatus UNIX socket and parses the returned rows. Read/write permission to the UNIX socket are required.

This package is known to be compatible with Python 2.7, 3.3, 34, pypy and pypy3.

Usage

Here a simple example to fetch the name and hostgroups for all servers in the UP (0) state:

>>> from mk_livestatus import Socket >>> s = Socket("/var/lib/icinga/rw/live") >>> q = s.hosts.columns('name', 'groups').filter('state = 0') >>> print q GET hosts Columns: name groups Filter: state = 0

>>> q.call() [{'name': 'example.com', 'groups': ['ssh', 'snmp', 'smtp-server', 'ping-server', 'http-server', 'debian-server', 'apache2']}]

s.hosts returns a Query to the hosts resources on Nagios. The columns and filter methods modify our query and return it, so we can chain the calls. The call to call method returns the rows as a list of dictionaries.

If you use xinetd to bind the Unix socket to a TCP socket (like explained here), you can create the socket like :

>>> s = Socket(('192.168.1.1', 6557))

For more information please visit the python-mk-livestatus website. Information about MK Livestatus and it's query syntax is available at the mk-livestatus website.

python-mk-livestatus's People

Contributors

ahaerpfer avatar arthru avatar edin1 avatar fladi avatar

Stargazers

 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

python-mk-livestatus's Issues

Non-trivial performance data breaks output

Any performance data output that contains multiple semicolon-separated values corrupts the returned dictionary. For a minimal example take any host that has a check-host-alive check configured and try the following:

>>> q = s.hosts.columns('perf_data')
>>> pprint(q.call()[0])
{None: ['3000.000',
        '5000.000',
        '0',
        ' pl=0%',
        '80',
        '100',
        '',
        ' rtmax=28.500ms',
        '',
        '',
        '',
        ' rtmin=21.859ms',
        '',
        '',
        '',
        ''],
 'perf_data': 'rta=24.821ms'}

I.e. the first part of the output up until the first semicolon ends up in perf_data, all subsequent parts end up in an anonymous list. If you do not filter for particular columns and instead do just a q = s.hosts the output looks even worse.

Not sure if this can be solved easily. Livestatus here seems to mix it's own semicolons to separate columns with the semicolons present in the perfdata output without escaping the latter :-(

Counts do not work

I try query 6 from http://mathias-kettner.de/checkmk_livestatus.html
GET services
Stats: state = 0
Stats: state = 1
Stats: state = 2
Stats: state = 3

like:

from mk_livestatus import Socket
s = Socket(('x.y.z.q', 50000))
q = s.services
q = q.filter('state = 1')
q = q.filter('state = 2')
q = q.filter('state = 3')
q.call()

result is empty array

Does not work on icinga2 at debian jessie, python2.7.9

On latest Icinga2, for example making a plain "GET services" query fails. Apparently the reason is that the query must contain an extra trailing newline that python-mk-livestatus is not adding.

At least after adding it things started working.

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.