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

View File

@ -2,6 +2,7 @@
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
/** /**
* Class Zend_View_Helper_MonitoringProperties * Class Zend_View_Helper_MonitoringProperties
*/ */
@ -57,12 +58,25 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
'status_update_time' => 'Last update' '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 * Return the object type
* @param stdClass $object * @param stdClass $object
* @return mixed * @return mixed
*/ */
private function getObjectType(\stdClass $object) private function getObjectType(stdClass $object)
{ {
$keys = array_keys(get_object_vars($object)); $keys = array_keys(get_object_vars($object));
$keyParts = explode('_', array_shift($keys), 2); $keyParts = explode('_', array_shift($keys), 2);
@ -75,7 +89,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param $type * @param $type
* @return object * @return object
*/ */
private function dropObjectType(\stdClass $object, $type) private function dropObjectType(stdClass $object, $type)
{ {
$vars = get_object_vars($object); $vars = get_object_vars($object);
$out = array(); $out = array();
@ -91,7 +105,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object * @param stdClass $object
* @return string * @return string
*/ */
private function buildAttempt(\stdClass $object) private function buildAttempt(stdClass $object)
{ {
return sprintf( return sprintf(
'%s/%s (%s state)', '%s/%s (%s state)',
@ -116,7 +130,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object * @param stdClass $object
* @return string * @return string
*/ */
private function buildCheckType(\stdClass $object) private function buildCheckType(stdClass $object)
{ {
if ($object->passive_checks_enabled === '1' && $object->active_checks_enabled === '0') { if ($object->passive_checks_enabled === '1' && $object->active_checks_enabled === '0') {
return self::CHECK_PASSIVE; return self::CHECK_PASSIVE;
@ -132,7 +146,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object * @param stdClass $object
* @return string * @return string
*/ */
private function buildLatency(\stdClass $object) private function buildLatency(stdClass $object)
{ {
$val = ''; $val = '';
if ($this->buildCheckType($object) === self::CHECK_PASSIVE) { if ($this->buildCheckType($object) === self::CHECK_PASSIVE) {
@ -155,7 +169,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object * @param stdClass $object
* @return string * @return string
*/ */
private function buildNextCheck(\stdClass $object) private function buildNextCheck(stdClass $object)
{ {
if ($this->buildCheckType($object) === self::CHECK_PASSIVE) { if ($this->buildCheckType($object) === self::CHECK_PASSIVE) {
return self::VALUE_NA; return self::VALUE_NA;
@ -169,7 +183,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object * @param stdClass $object
* @return string * @return string
*/ */
private function buildLastStateChange(\stdClass $object) private function buildLastStateChange(stdClass $object)
{ {
return strftime('%Y-%m-%d %H:%M:%S', $object->last_state_change); 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 * @param stdClass $object
* @return string * @return string
*/ */
private function buildLastNotification(\stdClass $object) private function buildLastNotification(stdClass $object)
{ {
$val = ''; $val = '';
@ -199,7 +213,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object * @param stdClass $object
* @return string * @return string
*/ */
private function buildFlapping(\stdClass $object) private function buildFlapping(stdClass $object)
{ {
$val = ''; $val = '';
@ -219,7 +233,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object * @param stdClass $object
* @return string * @return string
*/ */
private function buildScheduledDowntime(\stdClass $object) private function buildScheduledDowntime(stdClass $object)
{ {
if ($object->in_downtime === '1') { if ($object->in_downtime === '1') {
return self::VALUE_YES; return self::VALUE_YES;
@ -234,7 +248,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object * @param stdClass $object
* @return array * @return array
*/ */
public function monitoringProperties(\stdClass $object) public function monitoringProperties(stdClass $object)
{ {
$type = $this->getObjectType($object); $type = $this->getObjectType($object);
$object = $this->dropObjectType($object, $type); $object = $this->dropObjectType($object, $type);
@ -252,4 +266,21 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
return $out; 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); ?> <?= $this->tabs->render($this); ?>
<form method="get" action="<?= $this->qUrl( <?php
'monitoring/list/notifications', use Icinga\Web\Url;
$this->notifications->getAppliedFilter()->toParams()
); $formatter = $this->getHelper('MonitoringProperties');
?>
<form method="get" action="<?=
Url::fromPath(
'monitoring/list/notifications',
$this->notifications->getAppliedFilter()->toParams()
)->getAbsoluteUrl();
?>"> ?>">
Sort by <?= $this->formSelect( Sort by <?= $this->formSelect(
'sort', 'sort',
@ -44,49 +51,9 @@ echo $this->paginationControl($notifications, null, null, array('preserve' => $t
<?= $notification->host_name ?> <?= $notification->host_name ?>
</td> </td>
<td> <td>
<?= empty($notification->service_description) ? 'N/A' : $notification->service_description ?> <?= empty($notification->service_description) ? '' : $notification->service_description; ?>
</td> </td>
<td><?php <td><?= $formatter->getNotificationType($notification); ?>
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> </td>
<td> <td>
<?= $notification->notification_start_time ?> <?= $notification->notification_start_time ?>
@ -100,32 +67,24 @@ echo $this->paginationControl($notifications, null, null, array('preserve' => $t
<td> <td>
<?= $this->escape(substr(strip_tags($notification->notification_information), 0, 10000)); ?> <?= $this->escape(substr(strip_tags($notification->notification_information), 0, 10000)); ?>
</td> </td>
<td><?php <td>
if (intval($notification->notification_type) === 0) { <?php if (intval($notification->notification_type) === 0): ?>
echo $this->qlink( <a href="<?=
'', Url::fromPath(
'monitoring/show/host', 'monitoring/show/host',
array( array('host' => $notification->host_name)
'host' => $notification->host_name )->getAbsoluteUrl();
), ?>" class="row-action"> </a>
array(
'class' => 'row-action' <?php else: ?>
) <a href="<?=
); Url::fromPath('monitoring/show/service',
} else {
echo $this->qlink(
'',
'monitoring/show/service',
array( array(
'host' => $notification->host_name, 'host' => $notification->host_name,
'service' => $notification->service_description 'service' => $notification->service_description
),
array(
'class' => 'row-action'
) )
); )->getAbsoluteUrl(); ?>" class="row-action"></a>
} <?php endif; ?>
?>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>