PHP code example of kwkm / mklivestatus-client

1. Go to this page and download the library: Download kwkm/mklivestatus-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kwkm / mklivestatus-client example snippets


use Kwkm\MkLiveStatusClient as mk;

  array(
        'socketType' => 'unix',
        'socketPath' => '/var/run/nagios/rw/live',
    )
);

$client = new mk\Client($config);

$parser = new mk\Parser();

use Kwkm\MkLiveStatusClient as mk;

  array(
        'socketType' => 'tcp',
        'socketAddress' => '192.168.0.100',
        'socketPort' => 6557,
    )
);

$client = new mk\Client($config);

$parser = new mk\Parser();

$lql = new mk\LqlBuilder(mk\Table::CONTACTS);

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::CONTACTS);
$lql->columns(array('name', 'alias'));

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->columns(array('host_name', 'description', 'state'))
    ->filterEqual('state', '2');

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->columns(array('host_name', 'description', 'state'))
    ->filterEqual('state', '2')
    ->filterEqual('in_notification_period', '1');

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->columns(array('host_name', 'description', 'state', 'contacts'))
    ->filterGreaterEqual('contacts', 'harri');

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::HOSTS);
$lql->column('name')
    ->filterEqual('parents', '');

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::HOSTS);
$lql->columns(array('host_name', 'modified_attributes_list'))
    ->filterNotEqual('modified_attributes', '0');

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::HOSTS);
$lql->columns(array('host_name', 'modified_attributes_list'))
    ->filterMatch('modified_attributes', 'notifications_enabled')
    ->filterEqual('notifications_enabled', '0');

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::HOSTS);
$lql->columns(array('host_name', 'modified_attributes_list'))
    ->filterSet('modified_attributes ~~ active_checks_enabled,passive_checks_enabled');

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->filterEqual('state', '1')
    ->filterEqual('state', '3')
    ->filterOr(2);

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->filterGreater('scheduled_downtime_depth', '0')
    ->filterGreater('host_scheduled_downtime_depth', '0')
    ->filterOr(2);

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->filterEqual('state', '2')
    ->filterEqual('acknowledged', '1')
    ->filterAnd(2)
    ->filterEqual('state', '0')
    ->filterOr(2);

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::HOSTS);
$lql->filterMatch('name', 'a')
    ->filterMatch('name', 'o')
    ->filterOr(2)
    ->filterNegate();

$result = $parser->get($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->statsEqual('state', '0')
    ->statsEqual('state', '1')
    ->statsEqual('state', '2')
    ->statsEqual('state', '3');

$result = $parser->decode($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->statsEqual('state', '0')
    ->statsEqual('state', '1')
    ->statsEqual('state', '2')
    ->statsEqual('state', '3')
    ->filterGreaterEqual('contacts', 'harri');

$result = $parser->decode($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->filterGreaterEqual('host_groups', 'windows')
    ->filterEqual('scheduled_downtime_depth', '0')
    ->filterEqual('host_scheduled_downtime_depth', '0')
    ->filterEqual('in_notification_period', '1')
    ->statsEqual('last_hard_state', '0')
    ->statsEqual('last_hard_state', '1')
    ->statsEqual('acknowledged', '0')
    ->statsAnd(2)
    ->statsEqual('last_hard_state', '1')
    ->statsEqual('acknowledged', '1')
    ->statsAnd(2)
    ->statsEqual('last_hard_state', '2')
    ->statsEqual('acknowledged', '0')
    ->statsAnd(2)
    ->statsEqual('last_hard_state', '2')
    ->statsEqual('acknowledged', '1')
    ->statsAnd(2)
    ->statsEqual('last_hard_state', '3')
    ->statsEqual('acknowledged', '0')
    ->statsAnd(2)
    ->statsEqual('last_hard_state', '3')
    ->statsEqual('acknowledged', '1')
    ->statsAnd(2);

$result = $parser->decode($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->filterGreaterEqual('host_groups', 'windows')
    ->statsEqual('state', '0')
    ->statsEqual('state', '1')
    ->statsEqual('state', '2')
    ->statsEqual('state', '3')
    ->column('host_name');

$result = $parser->decode($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->statsNotEqual('state', '9999')
    ->column('check_command');

$result = $parser->decode($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->statsNotEqual('state', '9999')
    ->column('state');

$result = $parser->decode($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->filterEqual('state', '0')
    ->statsMin('execution_time')
    ->statsMax('execution_time')
    ->statsAvg('execution_time');

$result = $parser->decode($client->execute($lql));

$lql = new mk\LqlBuilder(mk\Table::SERVICES);
$lql->filterEqual('state', '0')
    ->statsMin('execution_time')
    ->statsMax('execution_time')
    ->statsAvg('execution_time')
    ->column('host_name');

$result = $parser->decode($client->execute($lql));

$column = new mk\Column(
    array(
        'host_name',
        'description',
        'state',
    )
);

$filter = new mk\Filter();
$filter->equal('state', '2')
       ->equal('acknowledged', '1')
       ->operatorAnd(2)
       ->equal('state', '0')
       ->operatorOr(2);

$lql = new mk\Lql(mk\Table::SERVICES);
$lql->column($column)->filter($filter);

$result = $parser->get($client->execute($lql));

$column = new mk\Column(
    array(
        'host_name',
    )
);

$stats = new mk\Stats();
$stats->equal('state', '0')
      ->equal('state', '1')
      ->equal('state', '2')
      ->equal('state', '3');

$lql = new mk\Lql(mk\Table::SERVICES);
$lql->stats($stats)->column($column);

$result = $parser->decode($client->execute($lql));