Merge branch 'feature/notification-overview-4187'

resolves #4187
This commit is contained in:
Jannis Moßhammer 2013-08-16 17:14:55 +02:00
commit 26402f1c0a
7 changed files with 402 additions and 61 deletions

View File

@ -10,4 +10,5 @@ _1 = 1
Hosts = "/monitoring/list/hosts"
Services = "/monitoring/list/services"
Downtimes = "/monitoring/list/downtimes"
Notifications = "/monitoring/list/notifications"
Summaries = "/monitoring/summary/group/by/hostgroup"

View File

@ -215,13 +215,30 @@ class Monitoring_ListController extends ModuleActionController
}
/**
* Create a query for the given view
*
* @param string $view An string identifying view to query
* @param array $columns An array with the column names to display
*
* @return \Icinga\Data\Db\Query
* Display notification overview
*/
public function notificationsAction()
{
$this->view->notifications = $this->query(
'notification',
array(
'host_name',
'service_description',
'notification_type',
'notification_reason',
'notification_start_time',
'notification_contact',
'notification_information',
'notification_command'
)
);
if (!$this->_getParam('sort')) {
$this->view->notifications->order('notification_start_time DESC');
}
$this->inheritCurrentSortColumn();
}
protected function query($view, $columns)
{
$extra = preg_split(
@ -299,8 +316,11 @@ class Monitoring_ListController extends ModuleActionController
'icon' => 'img/classic/downtime.gif',
'url' => 'monitoring/list/downtimes',
));
$tabs->add('notifications', array(
'title' => 'Notifications',
'icon' => 'img/classic/alarm-clock.png',
'url' => 'monitoring/list/notifications'
));
/*
$tabs->add('hostgroups', array(
'title' => 'Hostgroups',

View File

@ -1,7 +1,9 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Class Zend_View_Helper_MonitoringProperties
*/
@ -57,12 +59,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 +90,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 +106,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 +131,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 +147,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) {
@ -144,8 +159,8 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
}
$val .= ' / '. $this->floatFormatter(
isset($object->check_execution_time) ? $object->check_execution_time : 0
). ' seconds';
isset($object->check_execution_time) ? $object->check_execution_time : 0
). ' seconds';
return $val;
}
@ -155,7 +170,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 +184,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 +194,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 +214,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 +234,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 +249,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 +267,22 @@ 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;
}
}
// @codingStandardsIgnoreStop

View File

@ -0,0 +1,92 @@
<?= $this->tabs->render($this); ?>
<?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',
$this->sort,
array(
'class' => 'autosubmit'
),
array(
'notification_start_time' => 'Time'
)
);
?>
<input type="search" name="filter" placeholder="Type to filter" />
<button class="btn btn-small"><i class="icon-refresh"></i></button>
</form>
<?php
$notifications = $this->notifications->paginate();
echo $this->paginationControl($notifications, null, null, array('preserve' => $this->preserve));
?>
<table class="statustable action table-hover">
<thead>
<tr>
<th>Host</th>
<th>Service</th>
<th>Type</th>
<th>Time</th>
<th>Contact</th>
<th>Notification command</th>
<th>Information</th>
</tr>
</thead>
<tbody>
<?php foreach ($notifications as $notification): ?>
<tr>
<td>
<?= $notification->host_name ?>
</td>
<td>
<?= empty($notification->service_description) ? '' : $notification->service_description; ?>
</td>
<td><?= $formatter->getNotificationType($notification); ?>
</td>
<td>
<?= $notification->notification_start_time ?>
</td>
<td>
<?= $notification->notification_contact ?>
</td>
<td>
<?= $notification->notification_command ?>
</td>
<td>
<?= $this->escape(substr(strip_tags($notification->notification_information), 0, 10000)); ?>
</td>
<td>
<?php if (intval($notification->notification_type) === 0): ?>
<a href="<?=
Url::fromPath(
'monitoring/show/host',
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
)
)->getAbsoluteUrl(); ?>" class="row-action"></a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>

View File

@ -0,0 +1,133 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Icinga 2 Web - Head for multiple monitoring frontends
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Monitoring\Backend\Ido\Query;
/**
* Notification query
*/
class NotificationQuery extends AbstractQuery
{
/**
* Column map
*
* @var array
*/
protected $columnMap = array(
'notification' => array(
'notification_type' => 'n.notification_type',
'notification_reason' => 'n.notification_reason',
'notification_start_time' => 'n.start_time',
'notification_information' => 'n.output'
),
'objects' => array(
'host_name' => 'o.name1',
'service_description' => 'o.name2'
),
'contact' => array(
'notification_contact' => 'c_o.name1'
),
'command' => array(
'notification_command' => 'cmd_o.name1'
)
);
/**
* Fetch basic information about notifications
*/
protected function joinBaseTables()
{
$this->baseQuery = $this->db->select()->from(
array(
'n' => $this->prefix . 'notifications'
),
array()
);
$this->joinedVirtualTables = array('notification' => true);
}
/**
* Fetch description of each affected host/service
*/
protected function joinObjects()
{
$this->baseQuery->join(
array(
'o' => $this->prefix . 'objects'
),
'n.object_id = o.object_id AND o.is_active = 1 AND o.objecttype_id IN (1, 2)',
array()
);
}
/**
* Fetch name of involved contacts and/or contact groups
*/
protected function joinContact()
{
$this->baseQuery->join(
array(
'c' => $this->prefix . 'contactnotifications'
),
'n.notification_id = c.notification_id',
array()
);
$this->baseQuery->join(
array(
'c_o' => $this->prefix . 'objects'
),
'c.contact_object_id = c_o.object_id',
array()
);
}
/**
* Fetch name of the command which was used to send out a notification
*/
protected function joinCommand()
{
$this->baseQuery->join(
array(
'cmd_c' => $this->prefix . 'contactnotifications'
),
'n.notification_id = cmd_c.notification_id',
array()
);
$this->baseQuery->join(
array(
'cmd_m' => $this->prefix . 'contactnotificationmethods'
),
'cmd_c.notification_id = cmd_m.contactnotification_id',
array()
);
$this->baseQuery->join(
array(
'cmd_o' => $this->prefix . 'objects'
),
'cmd_m.command_object_id = cmd_o.object_id',
array()
);
}
}

View File

@ -1,4 +1,7 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Monitoring\Backend\Ido\Query;
@ -32,7 +35,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' => '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',
@ -135,7 +138,7 @@ class StatusQuery extends AbstractQuery
'service_last_time_unknown' => 'ss.last_time_unknown',
'service_current_check_attempt' => 'ss.current_check_attempt',
'service_max_check_attempts' => 'ss.max_check_attempts',
'service_attempt' => 'CONCAT(ss.current_check_attempt, \'/\', ss.max_check_attempts)',
'service_attempt' => 'ss.current_check_attempt || \'/\' || ss.max_check_attempts',
'service_last_check' => 'ss.last_check',
'service_next_check' => 'ss.next_check',
'service_check_type' => 'ss.check_type',
@ -238,13 +241,13 @@ class StatusQuery extends AbstractQuery
array('ho' => $this->prefix . 'objects'),
array()
)->join(
array('hs' => $this->prefix . 'hoststatus'),
'ho.object_id = hs.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
array()
)->join(
array('h' => $this->prefix . 'hosts'),
'hs.host_object_id = h.host_object_id',
array()
array('hs' => $this->prefix . 'hoststatus'),
'ho.object_id = hs.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
array()
)->join(
array('h' => $this->prefix . 'hosts'),
'hs.host_object_id = h.host_object_id',
array()
);
$this->joinedVirtualTables = array(
'hosts' => true,
@ -269,14 +272,14 @@ class StatusQuery extends AbstractQuery
's.host_object_id = h.host_object_id',
array()
)->join(
array('so' => $this->prefix . 'objects'),
'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',
array()
);
array('so' => $this->prefix . 'objects'),
'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',
array()
);
}
// TODO: Test this one, doesn't seem to work right now
@ -296,10 +299,10 @@ class StatusQuery extends AbstractQuery
'hgm.host_object_id = h.host_object_id',
array()
)->join(
array('hg' => $this->prefix . 'hostgroups'),
'hgm.hostgroup_id = hg'.$this->hostgroup_id,
array()
);
array('hg' => $this->prefix . 'hostgroups'),
'hgm.hostgroup_id = hg'.$this->hostgroup_id,
array()
);
return $this;
}
@ -311,15 +314,15 @@ class StatusQuery extends AbstractQuery
'hgm.host_object_id = s.host_object_id',
array()
)->join(
array('hg' => $this->prefix . 'hostgroups'),
'hgm.hostgroup_id = hg.' . $this->hostgroup_id,
array()
)->join(
array('hgo' => $this->prefix . 'objects'),
'hgo.' . $this->object_id . ' = hg.hostgroup_object_id'
. ' AND hgo.is_active = 1',
array()
);
array('hg' => $this->prefix . 'hostgroups'),
'hgm.hostgroup_id = hg.' . $this->hostgroup_id,
array()
)->join(
array('hgo' => $this->prefix . 'objects'),
'hgo.' . $this->object_id . ' = hg.hostgroup_object_id'
. ' AND hgo.is_active = 1',
array()
);
return $this;
}
@ -332,16 +335,15 @@ class StatusQuery extends AbstractQuery
'sgm.service_object_id = s.service_object_id',
array()
)->join(
array('sg' => $this->prefix . 'servicegroups'),
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
array()
)->join(
array('sgo' => $this->prefix . 'objects'),
'sgo.' . $this->object_id. ' = sg.servicegroup_object_id'
. ' AND sgo.is_active = 1',
array()
);
array('sg' => $this->prefix . 'servicegroups'),
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
array()
)->join(
array('sgo' => $this->prefix . 'objects'),
'sgo.' . $this->object_id. ' = sg.servicegroup_object_id'
. ' AND sgo.is_active = 1',
array()
);
return $this;
}
@ -385,3 +387,4 @@ class StatusQuery extends AbstractQuery
);
}
}
// @codingStandardsIgnoreStop

View File

@ -0,0 +1,59 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Icinga 2 Web - Head for multiple monitoring frontends
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Monitoring\View;
/**
* NotificationView
*/
class NotificationView extends MonitoringView
{
/**
* Available columns provided by this view
*
* @var array
*/
protected $availableColumns = array(
'host_name',
'service_description',
'notification_type',
'notification_reason',
'notification_start_time',
'notification_contact',
'notification_information',
'notification_command'
);
/**
* Default sorting rules
*
* @var array
*/
protected $sortDefaults = array(
'notification_start_time' => array(
'default_dir' => self::SORT_DESC
)
);
}