04 Jul 2013

Automate!

When trying to automate everything sometimes the tools you use can hold you back. An example is monitoring, where old systems (like nagios) are difficult to automate because they have no remote control API.

Using MK-livestatus

MK-livestatus is an extension for Nagios/Icinga (and built-in for Shinken) that allows retrieving information or sending commands via an Unix Domain Socket (UDS).

Livestatus is cool

Information from nagios itself comes from a file named status.dat which is updated every x seconds (where x can be configured but usually has a value of 5-10).
As the name livestatus hints, the information retrieved and sent using livestatus is always up-to-date. Livestatus does this by directly retrieving the in-memory information using the broker API. Thus having real-time information from livestatus is very useful.

The problems

Unix Domain Socket means you need local access

The MK-livestatus page suggests either using SSH or xinetd to expose the socket to the network. While exposing the socket over TCP is a security nightmare, both suggestions have another issue in common!

You have to deal with the output format from MK-livestatus

The output format from MK-livestatus is not very pleasant to work with (due to performance concerns). For example if you ask for JSON, you'll get something like
[['field1', 'field2', 'field3'],
['value1', 'value2', 'value3']]

Basically the first list is the list of column names, and then you get a list with the values for every row. If you restrict the displayed columns like so :
Columns: field_1 field_2
you'd just get
[['value1', 'value2']]
so get ready to parse your own query (or add a Column-Headers section to it).

Awesome, right?

Introducing livestatus-service

What it does for you

Wouldn't it be nice to access the livestatus API over HTTP (being able to build in authentication and so on) and at the same time get cool responses like:
[{'field1': 'value1', 'field2': 'value2', 'field3': 'value3'}]?
With livestatus-service, this is possible. You can even select an index (say field1) and get something like
{'value1' : {'field1': 'value1', 'field2': 'value2', 'field3': 'value3'}}

Getting livestatus-service

The code is released under the MIT license on GitHub. You can build it from there, or just use the PyPI package.
Refer to the documentation on GitHub for more information.

YADT an Augmented Deployment Tool
Copyright (C) 2010-2016 Immobilien Scout GmbH
Licensed under GNU GPL v3

2016-05-11 10:48:37 +0000