Remove qUrl, use ListController::query, proper default sorting

refs #4187
This commit is contained in:
Jannis Moßhammer 2013-08-12 11:09:22 +02:00 committed by Eric Lippmann
parent baaf5b81d9
commit 3c56f5c53a
3 changed files with 75 additions and 86 deletions

View File

@ -219,8 +219,9 @@ class Monitoring_ListController extends ModuleActionController
*/
public function notificationsAction()
{
$query = $this->backend->select()
->from('notification', array(
$this->view->notifications = $this->query(
'notification',
array(
'host_name',
'service_description',
'notification_type',
@ -229,14 +230,12 @@ class Monitoring_ListController extends ModuleActionController
'notification_contact',
'notification_information',
'notification_command'
));
)
);
if (!$this->_getParam('sort')) {
// TODO: Remove this once MonitoringView::applyRequestSorting
// applies NotificationView::sortDefaults
$this->_request->setParam('sort', 'notification_start_time');
$this->_request->setParam('dir', -1); // Query is still using ASC!?
$this->view->notifications->order('notification_start_time DESC');
}
$this->view->notifications = $query->applyRequest($this->_request);
$this->inheritCurrentSortColumn();
}

View File

@ -2,6 +2,7 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Class Zend_View_Helper_MonitoringProperties
*/
@ -57,12 +58,25 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
'status_update_time' => 'Last update'
);
private static $notificationReasons = array(
0 => 'NORMAL',
1 => 'ACKNOWLEDGEMENT',
2 => 'FLAPPING START',
3 => 'FLAPPING STOP',
4 => 'FLAPPING DISABLED',
5 => 'DOWNTIME START',
6 => 'DOWNTIME END',
7 => 'DOWNTIME CANCELLED',
8 => 'CUSTOM',
9 => 'STALKING'
);
/**
* Return the object type
* @param stdClass $object
* @return mixed
*/
private function getObjectType(\stdClass $object)
private function getObjectType(stdClass $object)
{
$keys = array_keys(get_object_vars($object));
$keyParts = explode('_', array_shift($keys), 2);
@ -75,7 +89,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param $type
* @return object
*/
private function dropObjectType(\stdClass $object, $type)
private function dropObjectType(stdClass $object, $type)
{
$vars = get_object_vars($object);
$out = array();
@ -91,7 +105,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildAttempt(\stdClass $object)
private function buildAttempt(stdClass $object)
{
return sprintf(
'%s/%s (%s state)',
@ -116,7 +130,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildCheckType(\stdClass $object)
private function buildCheckType(stdClass $object)
{
if ($object->passive_checks_enabled === '1' && $object->active_checks_enabled === '0') {
return self::CHECK_PASSIVE;
@ -132,7 +146,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildLatency(\stdClass $object)
private function buildLatency(stdClass $object)
{
$val = '';
if ($this->buildCheckType($object) === self::CHECK_PASSIVE) {
@ -155,7 +169,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildNextCheck(\stdClass $object)
private function buildNextCheck(stdClass $object)
{
if ($this->buildCheckType($object) === self::CHECK_PASSIVE) {
return self::VALUE_NA;
@ -169,7 +183,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildLastStateChange(\stdClass $object)
private function buildLastStateChange(stdClass $object)
{
return strftime('%Y-%m-%d %H:%M:%S', $object->last_state_change);
}
@ -179,7 +193,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildLastNotification(\stdClass $object)
private function buildLastNotification(stdClass $object)
{
$val = '';
@ -199,7 +213,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildFlapping(\stdClass $object)
private function buildFlapping(stdClass $object)
{
$val = '';
@ -219,7 +233,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildScheduledDowntime(\stdClass $object)
private function buildScheduledDowntime(stdClass $object)
{
if ($object->in_downtime === '1') {
return self::VALUE_YES;
@ -234,7 +248,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return array
*/
public function monitoringProperties(\stdClass $object)
public function monitoringProperties(stdClass $object)
{
$type = $this->getObjectType($object);
$object = $this->dropObjectType($object, $type);
@ -252,4 +266,21 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
return $out;
}
public function getNotificationType(stdClass $notification)
{
$reason = intval($notification->notification_reason);
if (!isset(self::$notificationReasons[$reason])) {
return 'N/A';
}
$type = self::$notificationReasons[$reason];
if ($reason === 8 ) {
if (intval($notification->notification_type) === 0) {
$type .= '(UP)';
} else {
$type .= '(OK)';
}
}
return $type;
}
}

View File

@ -1,9 +1,16 @@
<?= $this->tabs->render($this); ?>
<form method="get" action="<?= $this->qUrl(
'monitoring/list/notifications',
$this->notifications->getAppliedFilter()->toParams()
);
<?php
use Icinga\Web\Url;
$formatter = $this->getHelper('MonitoringProperties');
?>
<form method="get" action="<?=
Url::fromPath(
'monitoring/list/notifications',
$this->notifications->getAppliedFilter()->toParams()
)->getAbsoluteUrl();
?>">
Sort by <?= $this->formSelect(
'sort',
@ -44,49 +51,9 @@ echo $this->paginationControl($notifications, null, null, array('preserve' => $t
<?= $notification->host_name ?>
</td>
<td>
<?= empty($notification->service_description) ? 'N/A' : $notification->service_description ?>
<?= empty($notification->service_description) ? '' : $notification->service_description; ?>
</td>
<td><?php
switch ($notification->notification_reason)
{
case 0:
echo 'NORMAL';
break;
case 1:
echo 'ACKNOWLEDGEMENT';
break;
case 2:
echo 'FLAPPINGSTART';
break;
case 3:
echo 'FLAPPINGSTOP';
break;
case 4:
echo 'FLAPPINGDISABLED';
break;
case 5:
echo 'DOWNTIMESTART';
break;
case 6:
echo 'DOWNTIMEEND';
break;
case 7:
echo 'DOWNTIMECANCELLED';
break;
case 8:
if (intval($notification->notification_type) === 0) {
echo 'CUSTOM(UP)';
} else {
echo 'CUSTOM(OK)';
}
break;
case 9:
echo 'STALKING';
break;
default:
echo 'N/A';
}
?>
<td><?= $formatter->getNotificationType($notification); ?>
</td>
<td>
<?= $notification->notification_start_time ?>
@ -100,32 +67,24 @@ echo $this->paginationControl($notifications, null, null, array('preserve' => $t
<td>
<?= $this->escape(substr(strip_tags($notification->notification_information), 0, 10000)); ?>
</td>
<td><?php
if (intval($notification->notification_type) === 0) {
echo $this->qlink(
'',
<td>
<?php if (intval($notification->notification_type) === 0): ?>
<a href="<?=
Url::fromPath(
'monitoring/show/host',
array(
'host' => $notification->host_name
),
array(
'class' => 'row-action'
)
);
} else {
echo $this->qlink(
'',
'monitoring/show/service',
array('host' => $notification->host_name)
)->getAbsoluteUrl();
?>" class="row-action"> </a>
<?php else: ?>
<a href="<?=
Url::fromPath('monitoring/show/service',
array(
'host' => $notification->host_name,
'service' => $notification->service_description
),
array(
'class' => 'row-action'
)
);
}
?>
)->getAbsoluteUrl(); ?>" class="row-action"></a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>