monitoring/status: re-introduce comments, problems

This re-introduces expensive columns been disabled time ago and adds
even more to it. We are now showing last comment, last ack comment and
service problem count on hosts in list views.

It still costs performance, but seems that we can stand it. I'd like
to add more like this to the host view.
This commit is contained in:
Thomas Gelf 2014-06-25 21:38:55 +02:00
parent d634889acb
commit ff9c29472e
7 changed files with 78 additions and 32 deletions

View File

@ -82,9 +82,12 @@ class Monitoring_ListController extends Controller
'host_last_state_change',
'host_notifications_enabled',
// 'host_unhandled_service_count',
'host_unhandled_services',
'host_action_url',
'host_notes_url',
// 'host_last_comment',
'host_last_comment',
'host_last_ack',
'host_last_downtime',
'host_active_checks_enabled',
'host_passive_checks_enabled',
'host_current_check_attempt',
@ -147,7 +150,9 @@ class Monitoring_ListController extends Controller
'service_notifications_enabled',
'service_action_url',
'service_notes_url',
// 'service_last_comment',
'service_last_comment',
'service_last_ack',
'service_last_downtime',
'service_active_checks_enabled',
'service_passive_checks_enabled',
'current_check_attempt' => 'service_current_check_attempt',

View File

@ -65,18 +65,17 @@ if ($hosts->count() === 0) {
}
}
// Not available right now:
if (isset($host->host_last_comment) && $host->host_last_comment !== null) {
$icons[] = $this->icon('comment.png', 'Comments');
$icons[] = $this->icon('comment.png', 'Comment: ' . $host->host_last_comment);
}
?>
<tr class="state <?= $hostStateName ?><?= $host->host_handled ? ' handled' : '' ?>">
<!-- State -->
<td class="state" title="<?= $helper->getStateTitle($host, 'host'); ?>">
<div>
<?php if (isset($host->host_unhandled_service_count) && $host->host_unhandled_service_count > 0): ?>
<span class="badge pull-right" title="<?= $host->host_unhandled_service_count; ?> Service Problems on Host">
<a href="<?= $this->href('monitoring/list/services', array('host' => $host->host_name, 'service_problem' => 1)) ?>"><?= $host->host_unhandled_service_count; ?></a>
<?php if (isset($host->host_unhandled_services) && $host->host_unhandled_services > 0): ?>
<span class="badge pull-right" title="<?= $host->host_unhandled_services ?> Service Problems on Host">
<a href="<?= $this->href('monitoring/show/services', array('host' => $host->host_name, 'service_problem' => 1)) ?>"><?= $host->host_unhandled_services ?></a>
</span>
<?php endif; ?>
@ -96,6 +95,7 @@ if ($hosts->count() === 0) {
<?php if ($host->host_icon_image) : ?>
<?= $this->img($this->resolveMacros($host->host_icon_image, $host), array('align' => 'right')) ?>
<?php endif ?>
<?= implode(' ', $icons) ?>
<a href="<?= $this->href('monitoring/show/host', array('host' => $host->host_name)) ?>"><?= $host->host_name ?></a><br />
<?= $this->escape(substr(strip_tags($host->host_output), 0, 10000)); ?>
</td>

View File

@ -64,7 +64,9 @@ foreach ($services as $service):
<?php endif ?>
<?php if ($service->service_acknowledged && !$service->service_in_downtime): ?>
<?= $this->icon('acknowledgement.png', 'Acknowledged') ?>
<?= $this->icon('acknowledgement.png', 'Acknowledged' . (
$service->service_last_ack ? ': ' . $service->service_last_ack : ''
)) ?>
<?php endif ?>
<?php if ($service->service_is_flapping): ?>
@ -79,6 +81,10 @@ foreach ($services as $service):
<?= $this->icon('in_downtime.png', 'In Downtime') ?>
<?php endif ?>
<?php if (isset($service->service_last_comment) && $service->service_last_comment !== null): ?>
<?= $this->icon('comment.png', 'Comment: ' . $service->service_last_comment) ?>
<?php endif ?>
<?php if (!$service->service_active_checks_enabled): ?>
<?php if (!$service->service_passive_checks_enabled): ?>
<?= $this->icon('active_passive_checks_disabled.png', 'Active And Passive Checks Disabled') ?>

View File

@ -30,6 +30,8 @@
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use Zend_Db_Expr;
class StatusQuery extends IdoQuery
{
protected $allowCustomVars = true;
@ -293,16 +295,19 @@ class StatusQuery extends IdoQuery
END'
),
'serviceproblemsummary' => array(
// 'host_unhandled_service_count' => 'sps.unhandled_service_count'
'host_unhandled_service_count' => '(NULL)'
'host_unhandled_services' => 'sps.unhandled_services_count'
),
'lasthostcomment' => array(
// 'host_last_comment' => 'hlc.comment_id'
'host_last_comment' => '(NULL)'
'host_last_comment' => 'hlc.last_comment_data',
'host_last_downtime' => 'hlc.last_downtime_data',
'host_last_flapping' => 'hlc.last_flapping_data',
'host_last_ack' => 'hlc.last_ack_data',
),
'lastservicecomment' => array(
// 'service_last_comment' => 'slc.comment_id'
'service_last_comment' => '(NULL)'
'service_last_comment' => 'slc.last_comment_data',
'service_last_downtime' => 'slc.last_downtime_data',
'service_last_flapping' => 'slc.last_flapping_data',
'service_last_ack' => 'slc.last_ack_data',
)
);
@ -325,9 +330,6 @@ class StatusQuery extends IdoQuery
$this->joinedVirtualTables = array(
'hosts' => true,
'hoststatus' => true,
'lasthostcomment' => true,
'lastservicecomment' => true,
'serviceproblemsummary' => true,
);
}
@ -467,10 +469,23 @@ class StatusQuery extends IdoQuery
return $this;
}
// TODO: This will be obsolete once status is based on the new hoststatus, offering much more
// columns in a more efficient way
protected function joinServiceproblemsummary()
{
$sub = new Zend_Db_Expr('(SELECT'
. ' SUM(CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 0 ELSE 1 END) AS unhandled_services_count,'
. ' SUM(CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END) AS handled_services_count,'
. ' s.host_object_id FROM icinga_servicestatus ss'
. ' JOIN icinga_services s'
. ' ON s.service_object_id = ss.service_object_id'
. ' AND ss.current_state > 0'
. ' GROUP BY s.host_object_id)');
$this->select->joinLeft(
array('sps' => $sub),
'sps.host_object_id = hs.host_object_id',
array()
);
return;
$this->select->joinleft(
array ('sps' => new \Zend_Db_Expr(
'(SELECT COUNT(s.service_object_id) as unhandled_service_count, s.host_object_id as host_object_id '.
@ -484,14 +499,30 @@ class StatusQuery extends IdoQuery
);
}
// TODO: Terribly slow. As I have no idea of how to fix this we should remove it.
protected function getLastCommentSubQuery()
{
$sub = '(SELECT'
. ' lc.object_id,'
. " CASE WHEN lc.entry_type = 1 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_comment_data,"
. " CASE WHEN lc.entry_type = 2 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_downtime_data,"
. " CASE WHEN lc.entry_type = 3 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_flapping_data,"
. " CASE WHEN lc.entry_type = 4 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_ack_data"
. ' FROM icinga_comments c'
. ' JOIN (SELECT'
. ' MAX(comment_id) as comment_id,'
. ' object_id,'
. ' entry_type'
. ' FROM icinga_comments'
. ' WHERE entry_type = 1 OR entry_type = 4'
. ' GROUP BY object_id, entry_type'
. ') lc ON lc.comment_id = c.comment_id GROUP BY lc.object_id)';
return new Zend_Db_Expr($sub);
}
protected function joinLasthostcomment()
{
$this->select->joinleft(
array ('hlc' => new \Zend_Db_Expr(
'(SELECT MAX(c.comment_id) as comment_id, c.object_id '.
'FROM icinga_comments c GROUP BY c.object_id)')
),
$this->select->joinLeft(
array('hlc' => $this->getLastCommentSubQuery()),
'hlc.object_id = hs.host_object_id',
array()
);
@ -500,11 +531,8 @@ class StatusQuery extends IdoQuery
// TODO: Terribly slow. As I have no idea of how to fix this we should remove it.
protected function joinLastservicecomment()
{
$this->select->joinleft(
array ('slc' => new \Zend_Db_Expr(
'(SELECT MAX(c.comment_id) as comment_id, c.object_id '.
'FROM icinga_comments c GROUP BY c.object_id)')
),
$this->select->joinLeft(
array('slc' => $this->getLastCommentSubQuery()),
'slc.object_id = ss.service_object_id',
array()
);

View File

@ -60,7 +60,8 @@ class HostStatus extends DataView
'host_long_output',
'host_check_command',
'host_perfdata',
'host_check_source',
'host_check_source',
'host_unhandled_services',
'host_passive_checks_enabled',
'host_passive_checks_enabled_changed',
'host_obsessing',
@ -80,6 +81,9 @@ class HostStatus extends DataView
'host_percent_state_change',
'host_is_flapping',
'host_last_comment',
'host_last_downtime',
'host_last_ack',
'host_last_flapping',
'host_action_url',
'host_notes_url',
'host_percent_state_change',

View File

@ -66,6 +66,9 @@ class ServiceStatus extends DataView
'service_action_url',
'service_notes_url',
'service_last_comment',
'service_last_downtime',
'service_last_flapping',
'service_last_ack',
'service_last_check',
'service_next_check',
'service_attempt',

View File

@ -70,7 +70,7 @@ class Service extends AbstractObject
'host_is_flapping',
'host_last_check',
'host_notifications_enabled',
'host_unhandled_service_count',
'host_unhandled_services',
'host_action_url',
'host_notes_url',
'host_display_name',