NAME

Nagios::MKLivestatus - access nagios runtime data from check_mk livestatus Nagios addon

SYNOPSIS

use Nagios::MKLivestatus;
my $nl = Nagios::MKLivestatus->new( socket => '/var/lib/nagios3/rw/livestatus.sock' );
my $hosts = $nl->selectall_arrayref("GET hosts");

DESCRIPTION

This module connects via socket to the check_mk livestatus nagios addon. You first have to install and activate the livestatus addon in your nagios installation.

CONSTRUCTOR

new ( [ARGS] )

Creates an Nagios::MKLivestatus object. new takes at least the socketpath. Arguments are in key-value pairs.

socket                    path to the UNIX socket of check_mk livestatus
server                    use this server for a TCP connection
verbose                   verbose mode
line_seperator            ascii code of the line seperator, defaults to 10, (newline)
column_seperator          ascii code of the column seperator, defaults to 0 (null byte)
list_seperator            ascii code of the list seperator, defaults to 44 (comma)
host_service_seperator    ascii code of the host/service seperator, defaults to 124 (pipe)
keepalive                 enable keepalive. Default is off
errors_are_fatal          errors will die with an error message. Default: on

If the constructor is only passed a single argument, it is assumed to be a the socket specification. Use either socker OR server.

METHODS

do
do($statement)

Send a single statement without fetching the result.
Always returns true.
selectall_arrayref
selectall_arrayref($statement)
selectall_arrayref($statement, %opts)
selectall_arrayref($statement, %opts, $limit )

Sends a query and returns an array reference of arrays

   my $arr_refs = $nl->selectall_arrayref("GET hosts");

to get an array of hash references do something like

   my $hash_refs = $nl->selectall_arrayref("GET hosts", { Slice => {} });

to get an array of hash references from the first 2 returned rows only

   my $hash_refs = $nl->selectall_arrayref("GET hosts", { Slice => {} }, 2);

use limit to limit the result to this number of rows
selectall_hashref
selectall_hashref($statement, $key_field)

Sends a query and returns a hashref with the given key

   my $hashrefs = $nl->selectall_hashref("GET hosts", "name");
selectcol_arrayref
selectcol_arrayref($statement)
selectcol_arrayref($statement, %opt )

Sends a query an returns an arrayref for the first columns

   my $array_ref = $nl->selectcol_arrayref("GET hosts\nColumns: name");

   $VAR1 = [
             'localhost',
             'gateway',
           ];

returns an empty array if nothing was found


to get a different column use this

   my $array_ref = $nl->selectcol_arrayref("GET hosts\nColumns: name contacts", { Columns => [2] } );

you can link 2 columns in a hash result set

   my %hash = @{$nl->selectcol_arrayref("GET hosts\nColumns: name contacts", { Columns => [1,2] } )};

   produces a hash with host the contact assosiation

   $VAR1 = {
             'localhost' => 'user1',
             'gateway'   => 'user2'
           };
selectrow_array
selectrow_array($statement)

Sends a query and returns an array for the first row

   my @array = $nl->selectrow_array("GET hosts");

returns undef if nothing was found
selectrow_arrayref
selectrow_arrayref($statement)

Sends a query and returns an array reference for the first row

   my $arrayref = $nl->selectrow_arrayref("GET hosts");

returns undef if nothing was found
selectrow_hashref
selectrow_hashref($statement)

Sends a query and returns a hash reference for the first row

   my $hashref = $nl->selectrow_hashref("GET hosts");

returns undef if nothing was found
select_scalar_value
select_scalar_value($statement)

Sends a query and returns a single scalar

   my $count = $nl->select_scalar_value("GET hosts\nStats: state = 0");

returns undef if nothing was found
errors_are_fatal
errors_are_fatal($values)

Enable or disable fatal errors. When enabled the module will croak on any error.

returns always undef

SEE ALSO

For more information about the query syntax and the livestatus plugin installation see the Livestatus page: http://mathias-kettner.de/checkmk_livestatus.html

AUTHOR

Sven Nierlein, <nierlein@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2009 by Sven Nierlein

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.