Host detail view

Fix psr, adapt output for layouting, add fields to adapt original
views from icinga.

refs #4182
This commit is contained in:
Marius Hein 2013-07-02 16:00:41 +02:00
parent 3bcef9af9b
commit a0f96379a9
10 changed files with 658 additions and 361 deletions

View File

@ -1,14 +1,27 @@
<?php <?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Monitoring\Backend; use Icinga\Monitoring\Backend;
use Icinga\Web\ModuleActionController; use Icinga\Web\ModuleActionController;
use Icinga\Web\Hook; use Icinga\Web\Hook;
use Icinga\Application\Benchmark; use Icinga\Application\Benchmark;
/**
* Class Monitoring_ShowController
*
* Actions for show context
*/
class Monitoring_ShowController extends ModuleActionController class Monitoring_ShowController extends ModuleActionController
{ {
/**
* @var Backend
*/
protected $backend; protected $backend;
/**
* Initialize the controller
*/
public function init() public function init()
{ {
$host = $this->_getParam('host'); $host = $this->_getParam('host');
@ -26,7 +39,7 @@ class Monitoring_ShowController extends ModuleActionController
$this->view->service = $this->backend->fetchService($host, $service); $this->view->service = $this->backend->fetchService($host, $service);
} }
if ($host !== null) { if ($host !== null) {
$this->view->host = $this->backend->fetchHost($host); $this->view->host = $this->backend->fetchHost($host, true);
} }
$this->view->compact = $this->_getParam('view') === 'compact'; $this->view->compact = $this->_getParam('view') === 'compact';
$this->view->tabs = $this->createTabs(); $this->view->tabs = $this->createTabs();
@ -44,7 +57,8 @@ class Monitoring_ShowController extends ModuleActionController
$this->view->ticket_link = preg_replace( $this->view->ticket_link = preg_replace(
'~__ID__~', '~__ID__~',
'\$1', '\$1',
$this->view->qlink('#__ID__', $this->view->qlink(
'#__ID__',
'monitoring/show/ticket', 'monitoring/show/ticket',
$params $params
) )
@ -54,6 +68,9 @@ class Monitoring_ShowController extends ModuleActionController
} }
} }
/**
* Service overview
*/
public function serviceAction() public function serviceAction()
{ {
Benchmark::measure('Entered service action'); Benchmark::measure('Entered service action');
@ -64,7 +81,8 @@ class Monitoring_ShowController extends ModuleActionController
if ($grapher->hasGraph( if ($grapher->hasGraph(
$this->view->host->host_name, $this->view->host->host_name,
$this->view->service->service_description $this->view->service->service_description
)) { )
) {
$this->view->preview_image = $grapher->getPreviewImage( $this->view->preview_image = $grapher->getPreviewImage(
$this->view->host->host_name, $this->view->host->host_name,
$this->view->service->service_description $this->view->service->service_description
@ -73,41 +91,53 @@ class Monitoring_ShowController extends ModuleActionController
} }
$this->view->contacts = $this->backend->select() $this->view->contacts = $this->backend->select()
->from('contact', array( ->from(
'contact_name', 'contact',
'contact_alias', array(
'contact_email', 'contact_name',
'contact_pager', 'contact_alias',
)) 'contact_email',
'contact_pager',
)
)
->where('service_host_name', $this->view->host->host_name) ->where('service_host_name', $this->view->host->host_name)
->where('service_description', $this->view->service->service_description) ->where('service_description', $this->view->service->service_description)
->fetchAll(); ->fetchAll();
$this->view->contactgroups = $this->backend->select() $this->view->contactgroups = $this->backend->select()
->from('contactgroup', array( ->from(
'contactgroup_name', 'contactgroup',
'contactgroup_alias', array(
)) 'contactgroup_name',
'contactgroup_alias',
)
)
->where('service_host_name', $this->view->host->host_name) ->where('service_host_name', $this->view->host->host_name)
->where('service_description', $this->view->service->service_description) ->where('service_description', $this->view->service->service_description)
->fetchAll(); ->fetchAll();
$this->view->comments = $this->backend->select() $this->view->comments = $this->backend->select()
->from('comment', array( ->from(
'comment_timestamp', 'comment',
'comment_author', array(
'comment_data', 'comment_timestamp',
'comment_type', 'comment_author',
)) 'comment_data',
'comment_type',
)
)
->where('service_host_name', $this->view->host->host_name) ->where('service_host_name', $this->view->host->host_name)
->where('service_description', $this->view->service->service_description) ->where('service_description', $this->view->service->service_description)
->fetchAll(); ->fetchAll();
$this->view->customvars = $this->backend->select() $this->view->customvars = $this->backend->select()
->from('customvar', array( ->from(
'varname', 'customvar',
'varvalue' array(
)) 'varname',
'varvalue'
)
)
->where('varname', '-*PW*,-*PASS*') ->where('varname', '-*PW*,-*PASS*')
->where('host_name', $this->view->host->host_name) ->where('host_name', $this->view->host->host_name)
->where('service_description', $this->view->service->service_description) ->where('service_description', $this->view->service->service_description)
@ -116,6 +146,9 @@ class Monitoring_ShowController extends ModuleActionController
Benchmark::measure('Service action done'); Benchmark::measure('Service action done');
} }
/**
* Host overview
*/
public function hostAction() public function hostAction()
{ {
$this->view->active = 'host'; $this->view->active = 'host';
@ -130,90 +163,122 @@ class Monitoring_ShowController extends ModuleActionController
} }
$this->view->hostgroups = $this->backend->select() $this->view->hostgroups = $this->backend->select()
->from('hostgroup', array( ->from(
'hostgroup_name', 'hostgroup',
'hostgroup_alias' array(
)) 'hostgroup_name',
'hostgroup_alias'
)
)
->where('host_name', $this->view->host->host_name) ->where('host_name', $this->view->host->host_name)
->fetchPairs(); ->fetchPairs();
$this->view->contacts = $this->backend->select() $this->view->contacts = $this->backend->select()
->from('contact', array( ->from(
'contact_name', 'contact',
'contact_alias', array(
'contact_email', 'contact_name',
'contact_pager', 'contact_alias',
)) 'contact_email',
'contact_pager',
)
)
->where('host_name', $this->view->host->host_name) ->where('host_name', $this->view->host->host_name)
->fetchAll(); ->fetchAll();
$this->view->contactgroups = $this->backend->select() $this->view->contactgroups = $this->backend->select()
->from('contactgroup', array( ->from(
'contactgroup_name', 'contactgroup',
'contactgroup_alias', array(
)) 'contactgroup_name',
'contactgroup_alias',
)
)
->where('host_name', $this->view->host->host_name) ->where('host_name', $this->view->host->host_name)
->fetchAll(); ->fetchAll();
$this->view->comments = $this->backend->select() $this->view->comments = $this->backend->select()
->from('comment', array( ->from(
'comment_timestamp', 'comment',
'comment_author', array(
'comment_data', 'comment_timestamp',
'comment_type', 'comment_author',
)) 'comment_data',
'comment_type',
)
)
->where('host_name', $this->view->host->host_name) ->where('host_name', $this->view->host->host_name)
->fetchAll(); ->fetchAll();
$this->view->customvars = $this->backend->select() $this->view->customvars = $this->backend->select()
->from('customvar', array( ->from(
'varname', 'customvar',
'varvalue' array(
)) 'varname',
'varvalue'
)
)
->where('varname', '-*PW*,-*PASS*') ->where('varname', '-*PW*,-*PASS*')
->where('host_name', $this->view->host->host_name) ->where('host_name', $this->view->host->host_name)
->where('object_type', 'host') ->where('object_type', 'host')
->fetchPairs(); ->fetchPairs();
} }
/**
* History entries for objects
*/
public function historyAction() public function historyAction()
{ {
if ($this->view->host) { if ($this->view->host) {
$this->view->tabs->activate('history')->enableSpecialActions(); $this->view->tabs->activate('history')->enableSpecialActions();
} }
$this->view->history = $this->backend->select() $this->view->history = $this->backend->select()
->from('eventHistory', array( ->from(
'object_type', 'eventHistory',
'host_name', array(
'service_description', 'object_type',
'timestamp', 'host_name',
'state', 'service_description',
'attempt', 'timestamp',
'max_attempts', 'state',
'output', 'attempt',
'type' 'max_attempts',
))->applyRequest($this->_request); 'output',
'type'
)
)->applyRequest($this->_request);
$this->view->preserve = $this->view->history->getAppliedFilter()->toParams(); $this->view->preserve = $this->view->history->getAppliedFilter()->toParams();
if ($this->_getParam('dump') === 'sql') { if ($this->_getParam('dump') === 'sql') {
echo '<pre>' . htmlspecialchars($this->view->history->getQuery()->dump()) . '</pre>'; echo '<pre>' . htmlspecialchars($this->view->history->getQuery()->dump()) . '</pre>';
exit; exit;
} }
if ($this->_getParam('sort')) { if ($this->_getParam('sort')) {
$this->view->preserve['sort'] = $this->_getParam('sort'); $this->view->preserve['sort'] = $this->_getParam('sort');
} }
} }
/**
* Service overview
*/
public function servicesAction() public function servicesAction()
{ {
// Ugly and slow: // Ugly and slow:
$this->view->services = $this->view->action('services', 'list', 'monitoring', array( $this->view->services = $this->view->action(
'host_name' => $this->view->host->host_name, 'services',
//'sort', 'service_description' 'list',
)); 'monitoring',
array(
'host_name' => $this->view->host->host_name,
//'sort', 'service_description'
)
);
} }
/**
* Ticets actions
*/
public function ticketAction() public function ticketAction()
{ {
$this->view->tabs->activate('ticket')->enableSpecialActions(); $this->view->tabs->activate('ticket')->enableSpecialActions();
@ -222,16 +287,25 @@ class Monitoring_ShowController extends ModuleActionController
if (Hook::has('ticket')) { if (Hook::has('ticket')) {
$ticketModule = 'rt'; $ticketModule = 'rt';
$this->render(); $this->render();
$this->_forward('ticket', 'show', $ticketModule, array( $this->_forward(
'id' => $id 'ticket',
)); 'show',
$ticketModule,
array(
'id' => $id
)
);
} }
} }
/**
* Creating tabs for this controller
* @return \Icinga\Web\Widget\AbstractWidget
*/
protected function createTabs() protected function createTabs()
{ {
$tabs = $this->widget('tabs'); $tabs = $this->widget('tabs');
if ( ! $this->view->host) { if (!$this->view->host) {
return $tabs; return $tabs;
} }
$params = array( $params = array(
@ -246,48 +320,63 @@ class Monitoring_ShowController extends ModuleActionController
} else { } else {
$hostParams = $params; $hostParams = $params;
} }
$tabs->add('host', array( $tabs->add(
'title' => 'Host', 'host',
'icon' => 'img/classic/server.png', array(
'url' => 'monitoring/show/host', 'title' => 'Host',
'urlParams' => $hostParams, 'icon' => 'img/classic/server.png',
)); 'url' => 'monitoring/show/host',
$tabs->add('services', array( 'urlParams' => $hostParams,
'title' => 'Services', )
'icon' => 'img/classic/service.png', );
'url' => 'monitoring/show/services', $tabs->add(
'urlParams' => $params, 'services',
)); array(
if (isset($params['service'])) { 'title' => 'Services',
$tabs->add('service', array( 'icon' => 'img/classic/service.png',
'title' => 'Service', 'url' => 'monitoring/show/services',
'icon' => 'img/classic/service.png',
'url' => 'monitoring/show/service',
'urlParams' => $params, 'urlParams' => $params,
)); )
);
if (isset($params['service'])) {
$tabs->add(
'service',
array(
'title' => 'Service',
'icon' => 'img/classic/service.png',
'url' => 'monitoring/show/service',
'urlParams' => $params,
)
);
} }
$tabs->add('history', array( $tabs->add(
'title' => 'History', 'history',
'icon' => 'img/classic/history.gif', array(
'url' => 'monitoring/show/history', 'title' => 'History',
'urlParams' => $params, 'icon' => 'img/classic/history.gif',
)); 'url' => 'monitoring/show/history',
'urlParams' => $params,
)
);
if ($this->action_name === 'ticket') { if ($this->action_name === 'ticket') {
$tabs->add('ticket', array( $tabs->add(
'title' => 'Ticket', 'ticket',
'icon' => 'img/classic/ticket.gif', array(
'url' => 'monitoring/show/ticket', 'title' => 'Ticket',
'urlParams' => $params + array('ticket' => $this->_getParam('ticket')), 'icon' => 'img/classic/ticket.gif',
)); 'url' => 'monitoring/show/ticket',
'urlParams' => $params + array('ticket' => $this->_getParam('ticket')),
)
);
} }
/* /*
$tabs->add('contacts', array( $tabs->add('contacts', array(
'title' => 'Contacts', 'title' => 'Contacts',
'icon' => 'img/classic/customer.png', 'icon' => 'img/classic/customer.png',
'url' => 'monitoring/detail/contacts', 'url' => 'monitoring/detail/contacts',
'urlParams' => $params, 'urlParams' => $params,
)); ));
*/ */
// TODO: Inventory 'img/classic/facts.gif' // TODO: Inventory 'img/classic/facts.gif'
// Ticket 'img/classic/ticket.gif' // Ticket 'img/classic/ticket.gif'
// Customer 'img/classic/customer.png' // Customer 'img/classic/customer.png'

View File

@ -21,5 +21,11 @@ foreach ($this->comments as $comment) {
); );
} }
?> ?>
<b>Comments:</b><blockquote> <?= implode('<br />', $list) ?></blockquote> <div class="information-container">
<div class="head">
<span>Comments</span>
</div>
<blockquote> <?= implode('<br />', $list) ?></blockquote>
</div>
<?php endif; ?> <?php endif; ?>

View File

@ -1,24 +1,33 @@
<?php if (! empty($this->contacts)): ?> <?php
<? if (!empty($this->contacts)) {
$list = array(); $contactList = array();
foreach ($this->contacts as $contact) { foreach ($this->contacts as $contact) {
$list[] = $this->qlink($contact->contact_alias, 'monitoring/show/contact', array( $contactList[] = $this->qlink(
'contact_name' => $contact->contact_name $contact->contact_alias,
)); 'monitoring/show/contact',
} array(
?> 'contact_name' => $contact->contact_name
<b>Contacts:</b> <?= implode(', ', $list) ?><br /> )
<?php endif; ?> );
}
<?php if (! empty($this->contactgroups)): ?> echo '<strong>Contacts:</strong> ';
<? echo implode(', ', $contactList);
$list = array(); }
foreach ($this->contactgroups as $contactgroup) {
$list[] = $this->qlink($contactgroup->contactgroup_alias, 'monitoring/show/contactgroup', array(
'contactgroup_name' => $contactgroup->contactgroup_name
));
}
?>
<b>Contactgroups:</b> <?= implode(', ', $list) ?><br />
<?php endif; ?>
if (!empty($this->contactgroups)) {
$contactGroupList = array();
foreach ($this->contactgroups as $contactgroup) {
$contactGroupList[] = $this->qlink(
$contactgroup->contactgroup_alias,
'monitoring/show/contactgroup',
array(
'contactgroup_name' => $contactgroup->contactgroup_name
)
);
}
echo '<strong>Contactgroups:</strong> ';
echo implode(', ', $contactGroupList);
}
?>

View File

@ -0,0 +1,22 @@
<?php if (isset($this->customvars) && count($this->customvars)) { ?>
<div class="information-container">
<div class="head">
<span>Customvariables</span>
</div>
<div>
<table>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<?php foreach ($this->customvars as $name => $value) { ?>
<tr>
<td><?= $this->escape($name) ?></td>
<td><?= $this->escape($value) ?></td>
</tr>
<?php } ?>
</table>
</div>
</div>
<?php } ?>

View File

@ -1,30 +1,72 @@
<?php <?php
$showService = isset($this->service) && $this->tabs->getActiveName() !== 'host'; /** @var boolean $showService */
$showService = false;
if (isset($this->service) && $this->tabs->getActiveName() !== 'host') {
$showService = true;
}
/** @var boolean $inlineCommands */
$inlineCommands = true;
if ($this->tabs->getActiveName() === 'history') {
$inlineCommands = false;
}
if (!$this->compact) {
echo $this->tabs;
}
?> ?>
<?php if (! $this->compact): ?> <div class="information-container">
<?= $this->tabs ?> <?php if ($inlineCommands === true) { ?>
<?php endif; ?> <div class="pull-right">
<table style="margin-bottom: 1em"> <div>
<tr class="<?= $this->monitoringState($this->host, 'host') ?><?= $this->host->host_handled ? ' handled' : '' ?>"> <button type="button" class="btn btn-primary">
<td><b><?= $this->escape($this->host->host_name) ?><? <span>Check now</span>
if ($this->host->host_address && $this->host->host_address !== $this->host->host_name): ?> </button>
(<?= $this->escape($this->host->host_address) ?>) </div>
<?php endif; ?> <div class="container-spacer">
</b></td> <button type="button" class="btn btn-danger">
<td class="state"<?= $showService ? '' : ' rowspan="2"' ?>> <span>Acknowledge</span>
<?= $this->util()->getHostStateName($this->host->host_state); ?><br /> </button>
since <?= $this->timeSince($this->host->host_last_state_change) ?> </div>
</td> </div>
</tr> <?php } ?>
<?php if ($showService): ?>
<tr class="<?= $this->monitoringState($this->service, 'service'); ?><?= $this->service->service_handled ? ' handled' : '' ?>"> <table>
<td><b>Service: <?= $this->escape($this->service->service_description) ?></b></td> <tr class="<?= $this->monitoringState($this->host, 'host') ?><?= $this->host->host_handled ? ' handled' : '' ?>">
<td class="state"> <td>
<?= $this->util()->getServiceStateName($this->service->service_state); ?><br /> <strong>
since <?= $this->timeSince($this->service->service_last_state_change) ?> <?= $this->escape($this->host->host_name); ?>
</td> <?php if ($this->host->host_address && $this->host->host_address !== $this->host->host_name) { ?>
</tr> (<?= $this->escape($this->host->host_address); ?>)
<?php else: ?> <?php } ?>
<tr><td><b>Host state</b></td></tr> </strong>
<?php endif; ?>
</table> <?php if (isset($this->host->host_alias) && $this->host->host_alias !== $this->host->host_name) { ?>
<br />
<sup>(<?= $this->host->host_alias; ?>)</sup>
<?php } ?>
</td>
<td class="state"<?= $showService ? '' : ' rowspan="2"'; ?>>
<?= $this->util()->getHostStateName($this->host->host_state); ?>
since <?= $this->timeSince($this->host->host_last_state_change); ?>
</td>
</tr>
<?php if ($showService === true) { ?>
<tr class="<?= $this->monitoringState($this->service, 'service'); ?><?= $this->service->service_handled ? ' handled' : '' ?>">
<td>
<strong>
Service: <?= $this->escape($this->service->service_description); ?>
</strong>
</td>
<td class="state">
<?= $this->util()->getServiceStateName($this->service->service_state); ?>
since <?= $this->timeSince($this->service->service_last_state_change); ?>
</td>
</tr>
<?php } else { ?>
<?php // BYPASS ?>
<?php } ?>
</table>
<div class="clearfix"></div>
</div>

View File

@ -1,40 +1,78 @@
<?= $this->partial('show/header.phtml', array( <?php
'host' => $this->host, $hostgroupLinkList = array();
'service' => $this->service, if (!empty($this->hostgroups)) {
'tabs' => $this->tabs, foreach ($this->hostgroups as $name => $alias) {
'compact' => $this->compact $hostgroupLinkList[] = $this->qlink(
)); ?> $alias,
<?= $this->expandable( 'monitoring/list/services',
$this->pluginOutput($this->host->host_output), array(
$this->pluginOutput($this->host->host_long_output) 'hostgroups' => $name
) ?> )
<?= $this->expandable( );
'<b>Command:</b> ' . array_shift(preg_split('|!|', $this->host->host_check_command)), }
$this->commandArguments($this->host->host_check_command) }
) ?>
<?php if (! empty($this->hostgroups)): ?> var_dump($this->host);
<? ?>
$list = array(); <?=
foreach ($this->hostgroups as $name => $alias) { $this->partial(
$list[] = $this->qlink($alias, 'monitoring/list/services', array( 'show/header.phtml',
'hostgroups' => $name array(
)); 'host' => $this->host,
} 'service' => $this->service,
?> 'tabs' => $this->tabs,
<b>Hostgroups:</b> <?= implode(', ', $list) ?><br /> 'compact' => $this->compact
<?php endif; ?> )
<?= $this->render('show/components/contacts.phtml') ?> );
<?= $this->render('show/components/comments.phtml') ?> ?>
<?php foreach ($this->customvars as $name => $value): ?>
<b><?= $this->escape($name) ?>:</b> <?= $this->escape($value) ?><br />
<?php endforeach; ?>
<?php if ($this->host->host_perfdata): ?>
<?= $this->expandable(
'<b>Performance data</b>',
$this->perfdata($this->host->host_perfdata),
array('collapsed' => false)
) ?>
<?php endif; ?>
<?= $this->preview_image ?> <?= $this->preview_image ?>
<div class="information-container">
<div class="head">
<span>Plugin output</span>
</div>
<div>
<?= $this->pluginOutput($this->host->host_output); ?>
<?= $this->pluginOutput($this->host->host_long_output); ?>
</div>
</div>
<div class="information-container">
<div class="head">
<span>Command</span>
</div>
<div>
<strong>Command:</strong>
<?= array_shift(explode('!', $this->host->host_check_command, 2)); ?>
<?= $this->commandArguments($this->host->host_check_command); ?>
</div>
</div>
<div class="information-container">
<div class="head">
<span>Groups and Contacts</span>
</div>
<?php if (count($hostgroupLinkList)) { ?>
<strong>Hostgroups:</strong>
<?= implode(' ', $hostgroupLinkList); ?>
<?php } ?>
<?= $this->render('show/components/contacts.phtml') ?>
</div>
<?= $this->render('show/components/comments.phtml'); ?>
<?= $this->render('show/components/customvars.phtml'); ?>
<?php if ($this->host->host_perfdata): ?>
<div class="information-container">
<div class="head">
<span>Perfdata</span>
</div>
<div>
<?= $this->perfdata($this->host->host_perfdata); ?>
</div>
</div>
<?php endif; ?>

View File

@ -46,7 +46,7 @@ class AbstractBackend implements DatasourceInterface
public function from($virtual_table, $fields = array()) public function from($virtual_table, $fields = array())
{ {
$classname = $this->tableToClassName($virtual_table); $classname = $this->tableToClassName($virtual_table);
if (! class_exists($classname)) { if (!class_exists($classname)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf( sprintf(
'Asking for invalid virtual table %s', 'Asking for invalid virtual table %s',
@ -67,10 +67,10 @@ class AbstractBackend implements DatasourceInterface
protected function tableToClassName($virtual_table) protected function tableToClassName($virtual_table)
{ {
return 'Icinga\\Monitoring\\View\\' return 'Icinga\\Monitoring\\View\\'
// . $this->getName() // . $this->getName()
// . '\\' // . '\\'
. ucfirst($virtual_table) . ucfirst($virtual_table)
. 'View'; . 'View';
} }
public function getName() public function getName()
@ -84,62 +84,87 @@ class AbstractBackend implements DatasourceInterface
} }
// UGLY temporary host fetch // UGLY temporary host fetch
public function fetchHost($host) public function fetchHost($host, $fetchAll = false)
{ {
$select = $this->select() $fields = array(
->from('status', array( 'host_name',
'host_name', 'host_address',
'host_address', 'host_state',
'host_state', 'host_handled',
'host_handled', 'host_in_downtime',
'host_in_downtime', 'host_acknowledged',
'host_acknowledged', 'host_check_command',
'host_check_command', 'host_last_state_change',
'host_last_state_change', 'host_alias',
'host_alias', 'host_output',
'host_output', 'host_long_output',
'host_long_output', 'host_perfdata'
'host_perfdata',
))
->where('host_name', $host);
return $select->fetchRow();
$object = \Icinga\Objects\Host::fromBackend(
$this->select()
->from('status', array(
'host_name',
'host_address',
'host_state',
'host_handled',
'host_in_downtime',
'host_acknowledged',
'host_check_command',
'host_last_state_change',
'host_alias',
'host_output',
'host_long_output',
'host_perfdata',
))
->where('host_name', $host)
->fetchRow()
); );
// $object->customvars = $this->fetchCustomvars($host);
return $object; $fields = array_merge(
$fields,
array(
'current_check_attempt',
'max_check_attempts',
'attempt',
'last_check',
'next_check',
'check_type',
'last_state_change',
'last_hard_state_change',
'last_hard_state',
'last_time_up',
'last_time_down',
'last_time_unreachable',
'state_type',
'last_notification',
'next_notification',
'no_more_notifications',
'notifications_enabled',
'problem_has_been_acknowledged',
'acknowledgement_type',
'current_notification_number',
'passive_checks_enabled',
'active_checks_enabled',
'event_handler_enabled',
'flap_detection_enabled',
'is_flapping',
'percent_state_change',
'latency',
'execution_time',
'scheduled_downtime_depth',
'failure_prediction_enabled',
'process_performance_data',
'obsess_over_host',
'modified_host_attributes',
'event_handler',
'check_command',
'normal_check_interval',
'retry_check_interval',
'check_timeperiod_object_id'
)
);
$select = $this->select()
->from('status', $fields)
->where('host_name', $host);
return $select->fetchRow();
} }
// UGLY temporary service fetch // UGLY temporary service fetch
public function fetchService($host, $service) public function fetchService($host, $service)
{ {
Benchmark::measure('Preparing service select'); Benchmark::measure('Preparing service select');
$select = $this->select() $select = $this->select()
->from('status', array( ->from(
'status',
array(
'host_name', 'host_name',
'host_state', 'host_state',
'host_check_command', 'host_check_command',
'host_last_state_change', 'host_last_state_change',
'service_description', 'service_description',
'service_state', 'service_state',
'service_acknowledged', 'service_acknowledged',
@ -154,39 +179,42 @@ Benchmark::measure('Preparing service select');
'service_next_check', 'service_next_check',
'service_check_execution_time', 'service_check_execution_time',
'service_check_latency', 'service_check_latency',
// 'service_ // 'service_
)) )
->where('host_name', $host) )
->where('service_description', $service); ->where('host_name', $host)
->where('service_description', $service);
// Benchmark::measure((string) $select->getQuery()); // Benchmark::measure((string) $select->getQuery());
Benchmark::measure('Prepared service select'); Benchmark::measure('Prepared service select');
return $select->fetchRow(); return $select->fetchRow();
$object = \Icinga\Objects\Service::fromBackend( $object = \Icinga\Objects\Service::fromBackend(
$this->select() $this->select()
->from('status', array( ->from(
'status',
array(
'host_name', 'host_name',
'host_state', 'host_state',
'host_check_command', 'host_check_command',
'host_last_state_change', 'host_last_state_change',
'service_description',
'service_description', 'service_state',
'service_state', 'service_acknowledged',
'service_acknowledged', 'service_handled',
'service_handled', 'service_output',
'service_output', 'service_long_output',
'service_long_output', 'service_perfdata',
'service_perfdata', // '_host_satellite',
// '_host_satellite', 'service_check_command',
'service_check_command', 'service_last_state_change',
'service_last_state_change', 'service_last_check',
'service_last_check', 'service_next_check',
'service_next_check', 'service_check_execution_time',
'service_check_execution_time', 'service_check_latency',
'service_check_latency', // 'service_
// 'service_ )
)) )
->where('host_name', $host) ->where('host_name', $host)
->where('service_description', $service) ->where('service_description', $service)
->fetchRow() ->fetchRow()

View File

@ -8,27 +8,67 @@ class StatusQuery extends AbstractQuery
protected $columnMap = array( protected $columnMap = array(
'hosts' => array( 'hosts' => array(
'host' => 'ho.name1', 'host' => 'ho.name1',
'host_name' => 'ho.name1', 'host_name' => 'ho.name1',
'host_display_name' => 'h.display_name', 'host_display_name' => 'h.display_name',
'host_alias' => 'h.alias', 'host_alias' => 'h.alias',
'host_address' => 'h.address', 'host_address' => 'h.address',
'host_ipv4' => 'INET_ATON(h.address)', 'host_ipv4' => 'INET_ATON(h.address)',
'host_icon_image' => 'h.icon_image', 'host_icon_image' => 'h.icon_image',
), ),
'hoststatus' => array( 'hoststatus' => array(
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END', 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
'host_output' => 'hs.output', 'host_output' => 'hs.output',
'host_long_output' => 'hs.long_output', 'host_long_output' => 'hs.long_output',
'host_perfdata' => 'hs.perfdata', 'host_perfdata' => 'hs.perfdata',
'host_acknowledged' => 'hs.problem_has_been_acknowledged', 'host_acknowledged' => 'hs.problem_has_been_acknowledged',
'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END', 'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
'host_handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END', 'host_handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END',
'host_does_active_checks' => 'hs.active_checks_enabled', 'host_does_active_checks' => 'hs.active_checks_enabled',
'host_accepts_passive_checks' => 'hs.passive_checks_enabled', 'host_accepts_passive_checks' => 'hs.passive_checks_enabled',
'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)', 'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)',
'host_check_command' => 'hs.check_command', 'host_check_command' => 'hs.check_command',
'host_problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
'current_check_attempt' => 'hs.current_check_attempt',
'max_check_attempts' => 'hs.max_check_attempts',
'attempt' => 'CONCAT(hs.current_check_attempt, "/", hs.max_check_attempts)',
'last_check' => 'hs.last_check',
'next_check' => 'hs.next_check',
'check_type' => 'hs.check_type',
'last_state_change' => 'hs.last_state_change',
'last_hard_state_change' => 'hs.last_hard_state_change',
'last_hard_state' => 'hs.last_hard_state',
'last_time_up' => 'hs.last_time_up',
'last_time_down' => 'hs.last_time_down',
'last_time_unreachable' => 'hs.last_time_unreachable',
'state_type' => 'hs.state_type',
'last_notification' => 'hs.last_notification',
'next_notification' => 'hs.next_notification',
'no_more_notifications' => 'hs.no_more_notifications',
'notifications_enabled' => 'hs.notifications_enabled',
'problem_has_been_acknowledged' => 'hs.problem_has_been_acknowledged',
'acknowledgement_type' => 'hs.acknowledgement_type',
'current_notification_number' => 'hs.current_notification_number',
'passive_checks_enabled' => 'hs.passive_checks_enabled',
'active_checks_enabled' => 'hs.active_checks_enabled',
'event_handler_enabled' => 'hs.event_handler_enabled',
'flap_detection_enabled' => 'hs.flap_detection_enabled',
'is_flapping' => 'hs.is_flapping',
'percent_state_change' => 'hs.percent_state_change',
'latency' => 'hs.latency',
'execution_time' => 'hs.execution_time',
'scheduled_downtime_depth' => 'hs.scheduled_downtime_depth',
'failure_prediction_enabled' => 'hs.failure_prediction_enabled',
'process_performance_data' => 'hs.process_performance_data',
'obsess_over_host' => 'hs.obsess_over_host',
'modified_host_attributes' => 'hs.modified_host_attributes',
'event_handler' => 'hs.event_handler',
'check_command' => 'hs.check_command',
'normal_check_interval' => 'hs.normal_check_interval',
'retry_check_interval' => 'hs.retry_check_interval',
'check_timeperiod_object_id' => 'hs.check_timeperiod_object_id',
'host_problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
'host_severity' => 'CASE WHEN hs.current_state = 0 'host_severity' => 'CASE WHEN hs.current_state = 0
THEN THEN
CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL
@ -65,36 +105,36 @@ class StatusQuery extends AbstractQuery
'hostgroups' => 'hgo.name1', 'hostgroups' => 'hgo.name1',
), ),
'services' => array( 'services' => array(
'service_host_name' => 'so.name1', 'service_host_name' => 'so.name1',
'service' => 'so.name2', 'service' => 'so.name2',
'service_description' => 'so.name2', 'service_description' => 'so.name2',
'service_display_name' => 's.display_name', 'service_display_name' => 's.display_name',
'service_icon_image' => 's.icon_image', 'service_icon_image' => 's.icon_image',
), ),
'servicestatus' => array( 'servicestatus' => array(
'current_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END', 'current_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END',
'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END', 'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END',
'service_hard_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE CASE WHEN ss.state_type = 1 THEN ss.current_state ELSE ss.last_hard_state END END', 'service_hard_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE CASE WHEN ss.state_type = 1 THEN ss.current_state ELSE ss.last_hard_state END END',
'service_state_type' => 'ss.state_type', 'service_state_type' => 'ss.state_type',
'service_output' => 'ss.output', 'service_output' => 'ss.output',
'service_long_output' => 'ss.long_output', 'service_long_output' => 'ss.long_output',
'service_perfdata' => 'ss.perfdata', 'service_perfdata' => 'ss.perfdata',
'service_acknowledged' => 'ss.problem_has_been_acknowledged', 'service_acknowledged' => 'ss.problem_has_been_acknowledged',
'service_in_downtime' => 'CASE WHEN (ss.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END', 'service_in_downtime' => 'CASE WHEN (ss.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END', 'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END',
'service_does_active_checks' => 'ss.active_checks_enabled', 'service_does_active_checks' => 'ss.active_checks_enabled',
'service_accepts_passive_checks' => 'ss.passive_checks_enabled', 'service_accepts_passive_checks' => 'ss.passive_checks_enabled',
'service_last_state_change' => 'UNIX_TIMESTAMP(ss.last_state_change)', 'service_last_state_change' => 'UNIX_TIMESTAMP(ss.last_state_change)',
'service_last_hard_state_change' => 'UNIX_TIMESTAMP(ss.last_hard_state_change)', 'service_last_hard_state_change' => 'UNIX_TIMESTAMP(ss.last_hard_state_change)',
'service_check_command' => 'ss.check_command', 'service_check_command' => 'ss.check_command',
'service_last_check' => 'UNIX_TIMESTAMP(ss.last_check)', 'service_last_check' => 'UNIX_TIMESTAMP(ss.last_check)',
'service_next_check' => 'CASE WHEN ss.should_be_scheduled THEN UNIX_TIMESTAMP(ss.next_check) ELSE NULL END', 'service_next_check' => 'CASE WHEN ss.should_be_scheduled THEN UNIX_TIMESTAMP(ss.next_check) ELSE NULL END',
'service_check_execution_time' => 'ss.execution_time', 'service_check_execution_time' => 'ss.execution_time',
'service_check_latency' => 'ss.latency', 'service_check_latency' => 'ss.latency',
), ),
'status' => array( 'status' => array(
'problems' => 'CASE WHEN ss.current_state = 0 THEN 0 ELSE 1 END', 'problems' => 'CASE WHEN ss.current_state = 0 THEN 0 ELSE 1 END',
'handled' => 'CASE WHEN ss.problem_has_been_acknowledged = 1 OR ss.scheduled_downtime_depth > 0 THEN 1 ELSE 0 END', 'handled' => 'CASE WHEN ss.problem_has_been_acknowledged = 1 OR ss.scheduled_downtime_depth > 0 THEN 1 ELSE 0 END',
'severity' => 'CASE WHEN ss.current_state = 0 'severity' => 'CASE WHEN ss.current_state = 0
THEN THEN
CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL
@ -129,10 +169,12 @@ class StatusQuery extends AbstractQuery
END', END',
) )
); );
public function group($col)
{ public function group($col)
$this->baseQuery->group($col); {
} $this->baseQuery->group($col);
}
protected function getDefaultColumns() protected function getDefaultColumns()
{ {
return $this->columnMap['hosts']; return $this->columnMap['hosts'];
@ -150,16 +192,16 @@ public function group($col)
array('ho' => $this->prefix . 'objects'), array('ho' => $this->prefix . 'objects'),
array() array()
)->join( )->join(
array('hs' => $this->prefix . 'hoststatus'), array('hs' => $this->prefix . 'hoststatus'),
'ho.object_id = hs.host_object_id AND ho.is_active = 1', 'ho.object_id = hs.host_object_id AND ho.is_active = 1',
array() array()
)->join( )->join(
array('h' => $this->prefix . 'hosts'), array('h' => $this->prefix . 'hosts'),
'hs.host_object_id = h.host_object_id', 'hs.host_object_id = h.host_object_id',
array() array()
); );
$this->joinedVirtualTables = array( $this->joinedVirtualTables = array(
'hosts' => true, 'hosts' => true,
'hoststatus' => true, 'hoststatus' => true,
); );
} }
@ -181,14 +223,14 @@ public function group($col)
's.host_object_id = h.host_object_id', 's.host_object_id = h.host_object_id',
array() array()
)->join( )->join(
array('so' => $this->prefix . 'objects'), array('so' => $this->prefix . 'objects'),
"so.$this->object_id = s.service_object_id AND so.is_active = 1", "so.$this->object_id = s.service_object_id AND so.is_active = 1",
array() array()
)->joinLeft( )->joinLeft(
array('ss' => $this->prefix . 'servicestatus'), array('ss' => $this->prefix . 'servicestatus'),
"so.$this->object_id = ss.service_object_id", "so.$this->object_id = ss.service_object_id",
array() array()
); );
} }
// TODO: Test this one, doesn't seem to work right now // TODO: Test this one, doesn't seem to work right now
@ -208,10 +250,10 @@ public function group($col)
'hgm.host_object_id = h.host_object_id', 'hgm.host_object_id = h.host_object_id',
array() array()
)->join( )->join(
array('hg' => $this->prefix . 'hostgroups'), array('hg' => $this->prefix . 'hostgroups'),
"hgm.hostgroup_id = hg.$this->hostgroup_id", "hgm.hostgroup_id = hg.$this->hostgroup_id",
array() array()
); );
return $this; return $this;
} }
@ -223,15 +265,15 @@ public function group($col)
'hgm.host_object_id = s.host_object_id', 'hgm.host_object_id = s.host_object_id',
array() array()
)->join( )->join(
array('hg' => $this->prefix . 'hostgroups'), array('hg' => $this->prefix . 'hostgroups'),
'hgm.hostgroup_id = hg.' . $this->hostgroup_id, 'hgm.hostgroup_id = hg.' . $this->hostgroup_id,
array() array()
)->join( )->join(
array('hgo' => $this->prefix . 'objects'), array('hgo' => $this->prefix . 'objects'),
'hgo.' . $this->object_id. ' = hg.hostgroup_object_id' 'hgo.' . $this->object_id . ' = hg.hostgroup_object_id'
. ' AND hgo.is_active = 1', . ' AND hgo.is_active = 1',
array() array()
); );
return $this; return $this;
} }
@ -243,15 +285,15 @@ public function group($col)
'sgm.service_object_id = s.service_object_id', 'sgm.service_object_id = s.service_object_id',
array() array()
)->join( )->join(
array('sg' => $this->prefix . 'servicegroups'), array('sg' => $this->prefix . 'servicegroups'),
'sgm.servicegroup_id = sg.' . $this->servicegroup_id, 'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
array() array()
)->join( )->join(
array('hgo' => $this->prefix . 'objects'), array('hgo' => $this->prefix . 'objects'),
'hgo.' . $this->object_id. ' = hg.' . $this->hostgroup_id 'hgo.' . $this->object_id . ' = hg.' . $this->hostgroup_id
. ' AND hgo.is_active = 1', . ' AND hgo.is_active = 1',
array() array()
); );
return $this; return $this;
} }

View File

@ -178,3 +178,4 @@ body {
@import 'dataviews'; @import 'dataviews';
@import 'components/layouts'; @import 'components/layouts';
@import 'components/tables'; @import 'components/tables';
@import 'components/details';

View File

@ -85,3 +85,23 @@ font-size: 12px;
font-weight:bold; font-weight:bold;
} }
} }
.information-container {
margin: 0 0 5px 0;
border: 1px #fa4600 solid;
padding: 5px;
.head {
top: -5px;
left: -5px;
position: relative;
display: table-cell;
background-color: yellow;
padding: 4px;
}
.container-spacer {
margin: 10px 0 0 0;
}
}