Make sql-queries more standard compliant
The connection now uses ONLY_FULL_GROUP_BY when connecting and also forces ANSI SQL, this is reflected in the query codebase. Also the comment count fields are added in this commit. refs #4179
This commit is contained in:
parent
bec7049785
commit
705127a95e
|
@ -57,7 +57,8 @@ class Connection implements DatasourceInterface
|
|||
$adapter = 'Pdo_Mysql';
|
||||
$drv_options[\PDO::MYSQL_ATTR_INIT_COMMAND] =
|
||||
"SET SESSION SQL_MODE='STRICT_ALL_TABLES,NO_ZERO_IN_DATE,"
|
||||
. "NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION';";
|
||||
."NO_ZERO_IN_DATE,ANSI,TRADITIONAL,ONLY_FULL_GROUP_BY,"
|
||||
. "NO_ENGINE_SUBSTITUTION';";
|
||||
// Not using ONLY_FULL_GROUP_BY as of performance impact
|
||||
// TODO: NO_ZERO_IN_DATE as been added with 5.1.11. Is it
|
||||
// ignored by other versions?
|
||||
|
|
|
@ -37,8 +37,10 @@ class Monitoring_ListController extends ModuleActionController
|
|||
'host_handled',
|
||||
'host_last_state_change',
|
||||
'host_notifications_enabled',
|
||||
'host_problems'
|
||||
// 'host_comment_count'
|
||||
'host_problems',
|
||||
'host_action_url',
|
||||
'host_notes_url',
|
||||
'host_last_comment'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -54,20 +56,11 @@ class Monitoring_ListController extends ModuleActionController
|
|||
}
|
||||
}
|
||||
|
||||
$this->view->hosts->getQuery()->group('host_id');
|
||||
//$this->view->hosts->getQuery()->group('host_id');
|
||||
if ($this->_getParam('dump') === 'sql') {
|
||||
echo '<pre>' . htmlspecialchars(wordwrap($this->view->hosts->getQuery()->dump())) . '</pre>';
|
||||
exit;
|
||||
}
|
||||
// TODO: Get rid of "preserve"
|
||||
$preserve = array();
|
||||
if ($this->_getParam('sort')) {
|
||||
$preserve['sort'] = $this->view->sort = $this->_getParam('sort');
|
||||
}
|
||||
if ($this->_getParam('backend')) {
|
||||
$preserve['backend'] = $this->_getParam('backend');
|
||||
}
|
||||
$this->view->preserve = $preserve;
|
||||
|
||||
if ($this->_getParam('view') === 'compact') {
|
||||
$this->_helper->viewRenderer('hosts_compact');
|
||||
|
|
|
@ -7,7 +7,7 @@ use Icinga\Web\ModuleActionController;
|
|||
use Icinga\Web\Hook;
|
||||
use Icinga\Monitoring\Object\Host;
|
||||
use Icinga\Monitoring\Object\Service;
|
||||
|
||||
use Icinga\Application\Benchmark;
|
||||
/**
|
||||
* Class Monitoring_ShowController
|
||||
*
|
||||
|
|
|
@ -6,11 +6,9 @@ $viewHelper = $this->getHelper('MonitoringState');
|
|||
$trimArea = $this->getHelper('Trim');
|
||||
?>
|
||||
<form method="get" action="<?= $this->qUrl(
|
||||
'monitoring/list/hosts?' . http_build_query(
|
||||
$this->hosts->getAppliedFilter()->toParams()
|
||||
),
|
||||
'monitoring/list/hosts?' . http_build_query($this->hosts->getAppliedFilter()->toParams()),
|
||||
array()
|
||||
)
|
||||
);
|
||||
?>">
|
||||
Sort by <?= $this->formSelect(
|
||||
'sort',
|
||||
|
@ -51,59 +49,59 @@ $trimArea = $this->getHelper('Trim');
|
|||
<div class="icon-box"><?php $trimArea->start(); ?>
|
||||
<?php if (!$host->host_handled): ?>
|
||||
<a href="#" title="<?= 'Unhandled host' ?>">
|
||||
<i class="reactible icon-warning-sign"></i>
|
||||
<i class="icon-warning-sign"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($host->host_acknowledged && !$host->host_in_downtime): ?>
|
||||
<a href="#" title="<?= 'Acknowledged' ?>">
|
||||
<i class="reactible icon-ok-sign"></i>
|
||||
<i class="icon-ok-sign"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($host->host_is_flapping): ?>
|
||||
<a href="#" title="<?= 'Flapping' ?>">
|
||||
<i class="reactible icon-random"></i>
|
||||
<i class="icon-random"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (!$host->host_notifications_enabled): ?>
|
||||
<a href="#" title="<?= 'Notifications disabled' ?>">
|
||||
<i class="reactible icon-volume-off"></i>
|
||||
<i class="icon-volume-off"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($host->host_in_downtime): ?>
|
||||
<a href="#" title="<?= 'In downtime' ?>">
|
||||
<i class="reactible icon-wrench"></i>
|
||||
<i class="icon-wrench"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php $trimArea->end(); ?></div>
|
||||
</td>
|
||||
<td class="indicator state" title="<?= $viewHelper->getStateTitle($host, 'host'); ?>">
|
||||
<div class="statetext">
|
||||
<?= $this->qlink(
|
||||
"<b>".ucfirst($viewHelper->monitoringState($host, 'host'))."</b>".
|
||||
'<div class="nowrap"> since '.
|
||||
$this->timeSince($host->host_last_state_change),
|
||||
'monitoring/show/history', array(
|
||||
'host' => $host->host_name
|
||||
),
|
||||
array('quote' => false)
|
||||
);?>
|
||||
<?php if ($host->host_state_type === 0): ?>
|
||||
<a href="#" title="<?= 'Soft state' ?>">
|
||||
<i class="icon-gears"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="statetext">
|
||||
<?= $this->qlink(
|
||||
"<b>".ucfirst($viewHelper->monitoringState($host, 'host'))."</b>".
|
||||
'<div class="nowrap"> since '.
|
||||
$this->timeSince($host->host_last_state_change),
|
||||
'monitoring/show/history', array(
|
||||
'host' => $host->host_name
|
||||
),
|
||||
array('quote' => false)
|
||||
);?>
|
||||
<?php if ($host->host_state_type == 0): ?>
|
||||
<a href="#" title="<?= 'Soft state' ?>">
|
||||
<i class="icon-gears"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="hostname">
|
||||
<?php if (false && $host->host_comment_count > 0): ?>
|
||||
<a href="#" style="font-size:1.4em;;padding-left:1em;float:right" title="<?= 'Comments' ?>">
|
||||
<i class="icon-comment"> </i>
|
||||
</a>
|
||||
<?php if ($host->host_last_comment !== null): ?>
|
||||
<a href="#" title="<?= 'Comments' ?>">
|
||||
<i class="icon-comment"> </i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?= $this->qlink(
|
||||
"<b>".$host->host_name."</b><br/>".
|
||||
"<i>".$host->host_address."<i>",
|
||||
"<i>".$host->host_address."</i>",
|
||||
'monitoring/show/host', array(
|
||||
'host' => $host->host_name
|
||||
), array(
|
||||
|
@ -111,6 +109,15 @@ $trimArea = $this->getHelper('Trim');
|
|||
'quote' => false
|
||||
)
|
||||
); ?>
|
||||
|
||||
|
||||
<?php if ($host->host_action_url != ""): ?>
|
||||
<a href="<?= $host->host_action_url; ?>">Action</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($host->host_notes_url != ""): ?>
|
||||
<a href="<?= $host->host_notes_url; ?>">Notes</a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="expand-full">
|
||||
<?= $this->escape(substr(strip_tags($host->host_output), 0, 10000)); ?>
|
||||
|
|
|
@ -156,9 +156,11 @@ class AbstractBackend implements DatasourceInterface
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
$select = $this->select()
|
||||
->from('status', $fields)
|
||||
->where('host_name', $host);
|
||||
|
||||
return $select->fetchRow();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,15 @@ class StatusQuery extends AbstractQuery
|
|||
|
||||
protected $columnMap = array(
|
||||
'hosts' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_display_name' => 'h.display_name',
|
||||
'host_alias' => 'h.alias',
|
||||
'host_address' => 'h.address',
|
||||
'host_ipv4' => 'INET_ATON(h.address)',
|
||||
'host_icon_image' => 'h.icon_image',
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_display_name' => 'h.display_name',
|
||||
'host_alias' => 'h.alias',
|
||||
'host_address' => 'h.address',
|
||||
'host_ipv4' => 'INET_ATON(h.address)',
|
||||
'host_icon_image' => 'h.icon_image',
|
||||
'host_action_url' => 'h.action_url',
|
||||
'host_notes_url' => 'h.notes_url'
|
||||
),
|
||||
'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',
|
||||
|
@ -30,7 +32,7 @@ class StatusQuery extends AbstractQuery
|
|||
'host_check_command' => 'hs.check_command',
|
||||
'host_current_check_attempt' => 'hs.current_check_attempt',
|
||||
'host_max_check_attempts' => 'hs.max_check_attempts',
|
||||
'host_attempt' => 'CONCAT(hs.current_check_attempt, "/", hs.max_check_attempts)',
|
||||
'host_attempt' => 'CONCAT(hs.current_check_attempt, \'/\', hs.max_check_attempts)',
|
||||
'host_last_check' => 'hs.last_check',
|
||||
'host_next_check' => 'hs.next_check',
|
||||
'host_check_type' => 'hs.check_type',
|
||||
|
@ -68,7 +70,7 @@ class StatusQuery extends AbstractQuery
|
|||
'host_status_update_time' => 'hs.status_update_time',
|
||||
'host_problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
|
||||
'host_severity' => 'CASE WHEN hs.current_state = 0
|
||||
THEN
|
||||
THEN
|
||||
CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL
|
||||
THEN 16
|
||||
ELSE 0
|
||||
|
@ -139,11 +141,17 @@ class StatusQuery extends AbstractQuery
|
|||
'service_last_time_critical' => 'ss.last_time_critical',
|
||||
'service_last_time_unknown' => 'ss.last_time_unknown',
|
||||
),
|
||||
'lasthostcomment' => array(
|
||||
'host_last_comment' => 'hlc.comment_id'
|
||||
),
|
||||
'lastservicecomment' => array(
|
||||
'service_last_comment' => 'slc.comment_id'
|
||||
),
|
||||
'status' => array(
|
||||
'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',
|
||||
'severity' => 'CASE WHEN ss.current_state = 0
|
||||
THEN
|
||||
THEN
|
||||
CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL
|
||||
THEN 16
|
||||
ELSE 0
|
||||
|
@ -160,7 +168,7 @@ class StatusQuery extends AbstractQuery
|
|||
ELSE
|
||||
CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 16
|
||||
WHEN ss.current_state = 1 THEN 32
|
||||
WHEN ss.current_state = 2 THEN 128
|
||||
WHEN ss.current_state = 2 THEN 128
|
||||
WHEN ss.current_state = 3 THEN 64
|
||||
ELSE 256
|
||||
END
|
||||
|
@ -231,11 +239,11 @@ class StatusQuery extends AbstractQuery
|
|||
array()
|
||||
)->join(
|
||||
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()
|
||||
)->joinLeft(
|
||||
array('ss' => $this->prefix . 'servicestatus'),
|
||||
"so.$this->object_id = ss.service_object_id",
|
||||
'so.'.$this->object_id.' = ss.service_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
@ -258,7 +266,7 @@ class StatusQuery extends AbstractQuery
|
|||
array()
|
||||
)->join(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
"hgm.hostgroup_id = hg.$this->hostgroup_id",
|
||||
'hgm.hostgroup_id = hg'.$this->hostgroup_id,
|
||||
array()
|
||||
);
|
||||
|
||||
|
@ -306,4 +314,16 @@ class StatusQuery extends AbstractQuery
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function joinLasthostcomment()
|
||||
{
|
||||
$this->baseQuery->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)')
|
||||
),
|
||||
'hlc.object_id = hs.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue