kwkm / mklivestatus-client
mkLiveStatus 客户端
v1.0.1
2016-01-20 13:11 UTC
Requires (Dev)
- phpunit/phpunit: 4.5.*
- satooshi/php-coveralls: 1.0.*
This package is not auto-updated.
Last update: 2024-09-14 18:52:57 UTC
README
客户端设置。
本地主机情况。
use Kwkm\MkLiveStatusClient as mk; require __DIR__ . '/vendor/autoload.php'; $config = new mk\Configuration( array( 'socketType' => 'unix', 'socketPath' => '/var/run/nagios/rw/live', ) ); $client = new mk\Client($config); $parser = new mk\Parser();
远程网络情况。
use Kwkm\MkLiveStatusClient as mk; require __DIR__ . '/vendor/autoload.php'; $config = new mk\Configuration( array( 'socketType' => 'tcp', 'socketAddress' => '192.168.0.100', 'socketPort' => 6557, ) ); $client = new mk\Client($config); $parser = new mk\Parser();
示例 - LqlBuilder
检索所有联系人。
$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));
获取当前状态为2(关键)的所有服务。
$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));
使用 And、Or 和否定组合筛选器。
选择状态为 1 或 3 的所有服务。
$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));
显示所有名称中既没有 a 也没有 o 的主机。
$lql = new mk\LqlBuilder(mk\Table::HOSTS); $lql->filterMatch('name', 'a') ->filterMatch('name', 'o') ->filterOr(2) ->filterNegate(); $result = $parser->get($client->execute($lql));
统计和计数。
OK、WARN、CRIT 或 UNKNOWN 状态的服务数量。
$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));
将输出发送到联系人 harri 的服务。
$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));
与 and/or 结合使用。
$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));
求和、最小值、最大值、平均值、标准差。
OK 状态所有服务检查的最小、最大和平均检查执行时间。
$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));
示例 - 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));