mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
monitoring: Use the host and service comment queries in the comment query
refs #9009
This commit is contained in:
parent
82644b6122
commit
85c21b042d
@ -3,78 +3,126 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
|
|
||||||
|
use Zend_Db_Expr;
|
||||||
|
use Zend_Db_Select;
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query map for comments
|
* Query for host and service comments
|
||||||
*/
|
*/
|
||||||
class CommentQuery extends IdoQuery
|
class CommentQuery extends IdoQuery
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected $columnMap = array(
|
protected $columnMap = array(
|
||||||
'comments' => array(
|
'comments' => array(
|
||||||
'comment_internal_id' => 'cm.internal_comment_id',
|
'comment_author' => 'c.comment_author',
|
||||||
'comment_data' => 'cm.comment_data',
|
'comment_author_name' => 'c.comment_author_name',
|
||||||
'comment_author' => 'cm.author_name COLLATE latin1_general_ci',
|
'comment_data' => 'c.comment_data',
|
||||||
'comment_author_name' => 'cm.author_name',
|
'comment_expiration' => 'c.comment_expiration',
|
||||||
'comment_timestamp' => 'UNIX_TIMESTAMP(cm.comment_time)',
|
'comment_internal_id' => 'c.comment_internal_id',
|
||||||
'comment_type' => "CASE cm.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'downtime' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END",
|
'comment_is_persistent' => 'c.comment_is_persistent',
|
||||||
'comment_is_persistent' => 'cm.is_persistent',
|
'comment_timestamp' => 'c.comment_timestamp',
|
||||||
'comment_expiration' => 'CASE cm.expires WHEN 1 THEN UNIX_TIMESTAMP(cm.expiration_time) ELSE NULL END',
|
'comment_type' => 'c.comment_type',
|
||||||
'comment_objecttype' => "CASE WHEN ho.object_id IS NOT NULL THEN 'host' ELSE CASE WHEN so.object_id IS NOT NULL THEN 'service' ELSE NULL END END",
|
'object_type' => 'c.object_type'
|
||||||
'host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci',
|
|
||||||
'host_name' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END',
|
|
||||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
|
||||||
'service_description' => 'so.name2',
|
|
||||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
|
||||||
'service_host_name' => 'so.name1'
|
|
||||||
),
|
),
|
||||||
'hosts' => array(
|
'hosts' => array(
|
||||||
'host_display_name' => 'CASE WHEN sh.display_name IS NOT NULL THEN sh.display_name ELSE h.display_name END'
|
'host_display_name' => 'c.host_display_name',
|
||||||
|
'host_name' => 'c.host_name',
|
||||||
|
'host_state' => 'c.host_state'
|
||||||
),
|
),
|
||||||
'services' => array(
|
'services' => array(
|
||||||
'service_display_name' => 's.display_name'
|
'service_description' => 'c.service_description',
|
||||||
|
'service_display_name' => 'c.service_display_name',
|
||||||
|
'service_host_name' => 'c.service_host_name',
|
||||||
|
'service_state' => 'c.service_state'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
protected function joinBaseTables()
|
/**
|
||||||
{
|
* The union
|
||||||
$this->select->from(
|
*
|
||||||
array('cm' => $this->prefix . 'comments'),
|
* @var Zend_Db_Select
|
||||||
array()
|
*/
|
||||||
);
|
protected $commentQuery;
|
||||||
$this->select->joinLeft(
|
|
||||||
array('ho' => $this->prefix . 'objects'),
|
|
||||||
'cm.object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
|
||||||
array()
|
|
||||||
);
|
|
||||||
$this->select->joinLeft(
|
|
||||||
array('so' => $this->prefix . 'objects'),
|
|
||||||
'cm.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
|
||||||
array()
|
|
||||||
);
|
|
||||||
$this->joinedVirtualTables = array('comments' => true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function joinHosts()
|
/**
|
||||||
|
* Subqueries used for the comment query
|
||||||
|
*
|
||||||
|
* @var IdoQuery[]
|
||||||
|
*/
|
||||||
|
protected $subQueries = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function addFilter(Filter $filter)
|
||||||
{
|
{
|
||||||
$this->select->joinLeft(
|
foreach ($this->subQueries as $sub) {
|
||||||
array('h' => $this->prefix . 'hosts'),
|
$sub->applyFilter(clone $filter);
|
||||||
'h.host_object_id = ho.object_id',
|
}
|
||||||
array()
|
|
||||||
);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function joinBaseTables()
|
||||||
|
{
|
||||||
|
$this->commentQuery = $this->db->select();
|
||||||
|
$this->select->from(
|
||||||
|
array('c' => $this->commentQuery),
|
||||||
|
array()
|
||||||
|
);
|
||||||
|
$this->joinedVirtualTables['comments'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join hosts
|
||||||
|
*/
|
||||||
|
protected function joinHosts()
|
||||||
|
{
|
||||||
|
$columns = array_keys($this->columnMap['comments'] + $this->columnMap['hosts']);
|
||||||
|
foreach (array_keys($this->columnMap['services']) as $column) {
|
||||||
|
$columns[$column] = new Zend_Db_Expr('NULL');
|
||||||
|
}
|
||||||
|
$hosts = $this->createSubQuery('hostcomment', $columns);
|
||||||
|
$this->subQueries[] = $hosts;
|
||||||
|
$this->commentQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join services
|
||||||
|
*/
|
||||||
protected function joinServices()
|
protected function joinServices()
|
||||||
{
|
{
|
||||||
$this->select->joinLeft(
|
$columns = array_keys($this->columnMap['comments'] + $this->columnMap['hosts'] + $this->columnMap['services']);
|
||||||
array('s' => $this->prefix . 'services'),
|
$services = $this->createSubQuery('servicecomment', $columns);
|
||||||
's.service_object_id = so.object_id',
|
$this->subQueries[] = $services;
|
||||||
array()
|
$this->commentQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
||||||
);
|
}
|
||||||
$this->select->joinLeft(
|
|
||||||
array('sh' => $this->prefix . 'hosts'),
|
/**
|
||||||
'sh.host_object_id = s.host_object_id',
|
* {@inheritdoc}
|
||||||
array()
|
*/
|
||||||
);
|
public function order($columnOrAlias, $dir = null)
|
||||||
|
{
|
||||||
|
foreach ($this->subQueries as $sub) {
|
||||||
|
$sub->requireColumn($columnOrAlias);
|
||||||
|
}
|
||||||
|
return parent::order($columnOrAlias, $dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function where($condition, $value = null)
|
||||||
|
{
|
||||||
|
$this->requireColumn($condition);
|
||||||
|
foreach ($this->subQueries as $sub) {
|
||||||
|
$sub->where($condition, $value);
|
||||||
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user