PHP code example of aashley / nagios-livestatus-client

1. Go to this page and download the library: Download aashley/nagios-livestatus-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/ */

    

aashley / nagios-livestatus-client example snippets

 php


use Nagios\Livestatus\Client;

$options = array(
    'socketType' => 'tcp',
    'socketAddress' => '10.253.14.22',
    'socketPort' => '6557',
);

$client = new Client($options);

$response = $client
    ->get('hosts')
    ->column('host_name')
    ->column('state')
    ->execute();

foreach ($response as $host) {
    print $host[0] . ": " . $host[1] . "\n";
}

$response = $client
    ->get('hosts')
    ->column('host_name')
    ->column('state')
    ->executeAssoc();

foreach ($response as $host) {
    print $host['host_name'] . ": " . $host['state'] . "\n";
}

$client->command(
	array(
		'ACKNOWLEDGE_SVC_PROBLEM',
		'example.com',
		'some service', 2, 0, 1,
		'username', 'Example comment'
    )
);