monitoring: Add last *comment columns to the host status queries

This commit is contained in:
Eric Lippmann 2015-05-29 15:07:06 +02:00
parent a93ef04d5d
commit 0729973045
1 changed files with 91 additions and 0 deletions
modules/monitoring/library/Monitoring/Backend/Ido/Query

View File

@ -128,6 +128,18 @@ class HoststatusQuery extends IdoQuery
'host_status_update_time' => 'hs.status_update_time',
'host_unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END'
),
'lasthostackcomment' => array(
'host_last_ack' => 'hlac.last_ack_data'
),
'lasthostcomment' => array(
'host_last_comment' => 'hlc.last_comment_data'
),
'lasthostdowntimecomment' => array(
'host_last_downtime' => 'hldc.last_downtime_data'
),
'lasthostflappingcomment' => array(
'host_last_flapping' => 'hlfc.last_flapping_data'
),
'servicegroups' => array(
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
'servicegroup_name' => 'sgo.name1',
@ -143,6 +155,37 @@ class HoststatusQuery extends IdoQuery
)
);
/**
* Create a sub query to join comments into status query
*
* @param int $entryType
* @param string $alias
*
* @return Zend_Db_Expr
*/
protected function createLastCommentSubQuery($entryType, $alias)
{
$sql = <<<SQL
SELECT
c.object_id,
'[' || c.author_name || '] ' || c.comment_data AS $alias
FROM
icinga_comments c
INNER JOIN
(
SELECT
MAX(comment_id) AS comment_id,
object_id
FROM
icinga_comments
WHERE
entry_type = $entryType
GROUP BY object_id
) ec ON ec.comment_id = c.comment_id
SQL;
return new Zend_Db_Expr('(' . $sql . ')');
}
/**
* {@inheritdoc}
*/
@ -205,6 +248,54 @@ class HoststatusQuery extends IdoQuery
);
}
/**
* Join last host acknowledgement comment
*/
protected function joinLasthostackcomment()
{
$this->select->joinLeft(
array('hlac' => $this->createLastCommentSubQuery(4, 'last_ack_data')),
'hlac.object_id = ho.object_id',
array()
);
}
/**
* Join last host comment
*/
protected function joinLasthostcomment()
{
$this->select->joinLeft(
array('hlc' => $this->createLastCommentSubQuery(1, 'last_comment_data')),
'hlc.object_id = ho.object_id',
array()
);
}
/**
* Join last host downtime comment
*/
protected function joinLasthostdowntimeComment()
{
$this->select->joinLeft(
array('hldc' => $this->createLastCommentSubQuery(2, 'last_downtime_data')),
'hldc.object_id = ho.object_id',
array()
);
}
/**
* Join last host flapping comment
*/
protected function joinLasthostflappingcomment()
{
$this->select->joinLeft(
array('hlfc' => $this->createLastCommentSubQuery(3, 'last_flapping_data')),
'hlfc.object_id = ho.object_id',
array()
);
}
/**
* Join service groups
*/