More comment query cleanup and fix a typo

This commit is contained in:
Thomas Gelf 2014-03-09 20:05:59 +01:00
parent 1659df216d
commit 2f61075260
5 changed files with 25 additions and 52 deletions

View File

@ -327,9 +327,9 @@ class Monitoring_ListController extends Controller
'timestamp' => 'comment_timestamp',
'type' => 'comment_type',
'persistent' => 'comment_is_persistent',
'expiration' => 'comment_expiration_timestamp',
'host',
'service'
'expiration' => 'comment_expiration',
'host' => 'comment_host',
'service' => 'comment_service'
)
)->getQuery();
@ -338,9 +338,9 @@ class Monitoring_ListController extends Controller
$this->setupSortControl(
array(
'comment_timestamp' => 'Comment Timestamp',
'host_name' => 'Host / Service',
'comment_host' => 'Host / Service',
'comment_type' => 'Comment Type',
'comment_expiration_timestamp' => 'Expiration',
'comment_expiration' => 'Expiration',
)
);
$this->handleFormatRequest($query);

View File

@ -36,23 +36,16 @@ class CommentQuery extends IdoQuery
{
protected $columnMap = array(
'comments' => array(
'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",
'comment_internal_id' => 'cm.internal_comment_id',
'comment_data' => 'cm.comment_data',
'comment_author' => 'cm.author_name COLLATE latin1_general_ci',
'comment_timestamp' => 'UNIX_TIMESTAMP(cm.comment_time)',
'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' => 'cm.is_persistent',
'comment_expiration_timestamp' => 'CASE cm.expires WHEN 1 THEN UNIX_TIMESTAMP(cm.expiration_time) ELSE NULL END',
),
'hosts' => array(
'host_name' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci',
'host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci',
),
'services' => array(
'service' => 'so.name2 COLLATE latin1_general_ci',
'service_name' => 'so.name2 COLLATE latin1_general_ci',
'service_description' => 'so.name2 COLLATE latin1_general_ci',
'comment_internal_id' => 'cm.internal_comment_id',
'comment_data' => 'cm.comment_data',
'comment_author' => 'cm.author_name COLLATE latin1_general_ci',
'comment_timestamp' => 'UNIX_TIMESTAMP(cm.comment_time)',
'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' => 'cm.is_persistent',
'comment_expiration' => 'CASE cm.expires WHEN 1 THEN UNIX_TIMESTAMP(cm.expiration_time) ELSE NULL END',
'comment_host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci',
'comment_service' => 'so.name2 COLLATE latin1_general_ci',
'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",
)
);
@ -62,37 +55,17 @@ class CommentQuery extends IdoQuery
array('cm' => $this->prefix . 'comments'),
array()
);
/*
$this->baseQuery->join(
array(
'co' => $this->prefix . 'objects'
),
'cm.object_id = co.' . $this->object_id . ' AND co.is_active = 1'
);*/
$this->joinedVirtualTables = array('comments' => true);
$this->joinVirtualTable('hosts');
$this->joinVirtualTable('services');
}
protected function joinHosts()
{
// $this->conflictsWithVirtualTable('services');
$this->baseQuery->joinLeft(
array('ho' => $this->prefix . 'objects'),
'cm.object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
array()
);
}
protected function joinServices()
{
// $this->conflictsWithVirtualTable('hosts');
$this->baseQuery->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);
}
}

View File

@ -49,9 +49,9 @@ class Comment extends DataView
'comment_timestamp',
'comment_type',
'comment_is_persistent',
'comment_expiration_timestamp',
'host_name',
'service_description',
'comment_expiration',
'comment_host',
'comment_service',
);
}
@ -66,10 +66,10 @@ class Comment extends DataView
'comment_timestamp' => array(
'order' => self::SORT_DESC
),
'host_name' => array(
'comment_host' => array(
'columns' => array(
'host_name',
'service_description'
'comment_host',
'comment_service'
),
'order' => self::SORT_ASC
),

View File

@ -52,9 +52,9 @@ abstract class AbstractObject
))->getQuery();
$query->where('comment_type', array('comment', 'ack'));
$query->where('comment_objecttype', $this->type);
$query->where('host_name', $this->host_name);
$query->where('comment_host', $this->host_name);
if ($this->type === 'service') {
$query->where('service_description', $this->service_description);
$query->where('comment_service', $this->service_description);
}
$this->comments = $query->fetchAll();
return $this;

View File

@ -7,7 +7,7 @@ use Icinga\Data\Db\Query;
class Host extends AbstractObject
{
public $typ = 'host';
public $type = 'host';
public $prefix = 'host_';
private $view = null;