Add contact and contactgroup views
Create the new views, extend backend queries to fetch timeperiods and add navigation bar entries refs #4713
This commit is contained in:
parent
ba77713af0
commit
5d4533a6ad
|
@ -13,6 +13,8 @@ Hosts = "/monitoring/list/hosts"
|
||||||
Services = "/monitoring/list/services"
|
Services = "/monitoring/list/services"
|
||||||
Downtimes = "/monitoring/list/downtimes"
|
Downtimes = "/monitoring/list/downtimes"
|
||||||
Notifications = "/monitoring/list/notifications"
|
Notifications = "/monitoring/list/notifications"
|
||||||
|
Contacts = "/monitoring/list/contacts"
|
||||||
|
Contact Groups = "/monitoring/list/contactgroups"
|
||||||
|
|
||||||
;Remove component as of #4583 since it's not working
|
;Remove component as of #4583 since it's not working
|
||||||
;Summaries = "/monitoring/summary/group/by/hostgroup"
|
;Summaries = "/monitoring/summary/group/by/hostgroup"
|
||||||
|
|
|
@ -42,6 +42,8 @@ use \Icinga\Application\Config as IcingaConfig;
|
||||||
|
|
||||||
use Icinga\Module\Monitoring\DataView\Notification as NotificationView;
|
use Icinga\Module\Monitoring\DataView\Notification as NotificationView;
|
||||||
use Icinga\Module\Monitoring\DataView\Downtime as DowntimeView;
|
use Icinga\Module\Monitoring\DataView\Downtime as DowntimeView;
|
||||||
|
use Icinga\Module\Monitoring\DataView\Contact as ContactView;
|
||||||
|
use Icinga\Module\Monitoring\DataView\Contactgroup as ContactgroupView;
|
||||||
use Icinga\Module\Monitoring\DataView\HostAndServiceStatus as HostAndServiceStatusView;
|
use Icinga\Module\Monitoring\DataView\HostAndServiceStatus as HostAndServiceStatusView;
|
||||||
|
|
||||||
class Monitoring_ListController extends ActionController
|
class Monitoring_ListController extends ActionController
|
||||||
|
@ -114,7 +116,6 @@ class Monitoring_ListController extends ActionController
|
||||||
'host_last_comment',
|
'host_last_comment',
|
||||||
'host_active_checks_enabled',
|
'host_active_checks_enabled',
|
||||||
'host_passive_checks_enabled'
|
'host_passive_checks_enabled'
|
||||||
|
|
||||||
)
|
)
|
||||||
)->getQuery();
|
)->getQuery();
|
||||||
$this->view->hosts = $query->paginate();
|
$this->view->hosts = $query->paginate();
|
||||||
|
@ -250,6 +251,61 @@ class Monitoring_ListController extends ActionController
|
||||||
$this->handleFormatRequest($query);
|
$this->handleFormatRequest($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function contactsAction()
|
||||||
|
{
|
||||||
|
$query = ContactView::fromRequest(
|
||||||
|
$this->_request,
|
||||||
|
array(
|
||||||
|
'contact_name',
|
||||||
|
'contact_id',
|
||||||
|
'contact_alias',
|
||||||
|
'contact_email',
|
||||||
|
'contact_pager',
|
||||||
|
'contact_notify_service_timeperiod',
|
||||||
|
'contact_notify_service_recovery',
|
||||||
|
'contact_notify_service_warning',
|
||||||
|
'contact_notify_service_critical',
|
||||||
|
'contact_notify_service_unknown',
|
||||||
|
'contact_notify_service_flapping',
|
||||||
|
'contact_notify_service_downtime',
|
||||||
|
'contact_notify_host_timeperiod',
|
||||||
|
'contact_notify_host_recovery',
|
||||||
|
'contact_notify_host_down',
|
||||||
|
'contact_notify_host_unreachable',
|
||||||
|
'contact_notify_host_flapping',
|
||||||
|
'contact_notify_host_downtime',
|
||||||
|
)
|
||||||
|
)->getQuery();
|
||||||
|
$this->view->contacts = $query->paginate();
|
||||||
|
$this->setupSortControl(array(
|
||||||
|
'contact_name' => 'Name',
|
||||||
|
'contact_alias' => 'Alias',
|
||||||
|
'contact_email' => 'Email',
|
||||||
|
'contact_pager' => 'Pager Address / Number',
|
||||||
|
'contact_notify_service_timeperiod' => 'Service Notification Timeperiod',
|
||||||
|
'contact_notify_host_timeperiod' => 'Host Notification Timeperiod'
|
||||||
|
));
|
||||||
|
$this->handleFormatRequest($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function contactgroupsAction()
|
||||||
|
{
|
||||||
|
$query = ContactgroupView::fromRequest(
|
||||||
|
$this->_request,
|
||||||
|
array(
|
||||||
|
'contactgroup_name',
|
||||||
|
'contactgroup_alias',
|
||||||
|
'contact_name'
|
||||||
|
)
|
||||||
|
)->getQuery();
|
||||||
|
$this->view->contactgroups = $query->paginate();
|
||||||
|
$this->setupSortControl(array(
|
||||||
|
'contactgroup_name' => 'Group Name',
|
||||||
|
'contactgroup_alias' => 'Group Alias'
|
||||||
|
));
|
||||||
|
$this->handleFormatRequest($query);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the 'format' and 'view' parameter
|
* Handle the 'format' and 'view' parameter
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Zend_View_Helper_ContactFlags extends Zend_View_Helper_Abstract
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the human readable flag name for the given contact notification option
|
||||||
|
*
|
||||||
|
* @param string $tableName the name of the option table
|
||||||
|
*/
|
||||||
|
public function getNotificationOptionName($tableName) {
|
||||||
|
$exploded = explode('_', $tableName);
|
||||||
|
$name = end($exploded);
|
||||||
|
return ucfirst($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build all active notification options to a readable string
|
||||||
|
*
|
||||||
|
* @param object $contact The contact retrieved from a backend
|
||||||
|
* @param string $type Whether to display the flags for 'host' or 'service'
|
||||||
|
* @param string $glue The symbol to use to concatenate the flag names
|
||||||
|
*
|
||||||
|
* @return string A string that contains a human readable list of active options
|
||||||
|
*/
|
||||||
|
public function contactFlags($contact, $type, $glue = ', ')
|
||||||
|
{
|
||||||
|
$out = array();
|
||||||
|
foreach ($contact as $key => $value) {
|
||||||
|
if (preg_match('/^contact_notify_' . $type . '_.*/', $key) && $value == True) {
|
||||||
|
$option = $this->getNotificationOptionName($key);
|
||||||
|
if (strtolower($option) != 'timeperiod') {
|
||||||
|
array_push($out, $option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return implode($glue, $out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?= $this->tabs->render($this); ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$viewHelper = $this->getHelper('MonitoringState');
|
||||||
|
$knownGroups = array()
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div data-icinga-component="app/mainDetailGrid">
|
||||||
|
<?= $this->sortControl->render($this); ?>
|
||||||
|
<?= $this->paginationControl($contactgroups, null, null, array('preserve' => $this->preserve)); ?>
|
||||||
|
<table class="table table-condensed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th> Group Name </th>
|
||||||
|
<th> Description </th>
|
||||||
|
<th> Member Name </th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
<?php foreach($contactgroups as $contact): ?>
|
||||||
|
|
||||||
|
<?php $periodLink = $this->href('monitoring/show/contacts', array('contact' => $contact->contact_name)); ?>
|
||||||
|
<tr class="active">
|
||||||
|
<?php
|
||||||
|
$groupName = $contact->contactgroup_name;
|
||||||
|
if (!array_key_exists($groupName, $knownGroups)) {
|
||||||
|
echo '<td>' . $groupName . '</td><td>' . $contact->contactgroup_alias . '</td>';
|
||||||
|
$knownGroups[$groupName] = True;
|
||||||
|
} else {
|
||||||
|
echo '<td></td><td></td>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<td>
|
||||||
|
<a href="<?= $periodLink ?>"">
|
||||||
|
<?= $contact->contact_name ?>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?= $this->paginationControl($contactgroups, null, null, array('preserve' => $this->preserve)); ?>
|
||||||
|
</div>
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?= $this->tabs->render($this); ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$viewHelper = $this->getHelper('MonitoringState');
|
||||||
|
$contactHelper = $this->getHelper('ContactFlags');
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div data-icinga-component="app/mainDetailGrid">
|
||||||
|
<?= $this->sortControl->render($this); ?>
|
||||||
|
<?= $this->paginationControl($contacts, null, null, array('preserve' => $this->preserve)); ?>
|
||||||
|
<table class="table table-condensed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th> Contact Name </th>
|
||||||
|
<th> Alias </th>
|
||||||
|
<th> Email Address </th>
|
||||||
|
<th> Pager Address / Number </th>
|
||||||
|
<th> Service Notification Options </th>
|
||||||
|
<th> Host Notification Options </th>
|
||||||
|
<th> Service Notification Period </th>
|
||||||
|
<th> Host Notification Period </th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach($contacts as $contact): ?>
|
||||||
|
<?php $periodLink = $this->href('monitoring/show/contacts', array('contact' => $contact->contact_name)); ?>
|
||||||
|
<tr class="active">
|
||||||
|
<td> <?= $contact->contact_name ?> </td>
|
||||||
|
<td> <?= $contact->contact_alias ?> </td>
|
||||||
|
<td> <?= $contact->contact_email ?> </td>
|
||||||
|
<td> <?= $contact->contact_pager ?> </td>
|
||||||
|
<td> <?= $contactHelper->contactFlags($contact, 'service') ?> </td>
|
||||||
|
<td> <?= $contactHelper->contactFlags($contact, 'host') ?> </td>
|
||||||
|
<td> <?= $contact->contact_notify_service_timeperiod ?> </td>
|
||||||
|
<td> <?= $contact->contact_notify_host_timeperiod ?> </td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?= $this->paginationControl($contacts, null, null, array('preserve' => $this->preserve)); ?>
|
||||||
|
</div>
|
|
@ -4,13 +4,12 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
|
|
||||||
class ContactQuery extends AbstractQuery
|
class ContactQuery extends AbstractQuery
|
||||||
{
|
{
|
||||||
// TODO: join host/service timeperiod
|
|
||||||
|
|
||||||
protected $columnMap = array(
|
protected $columnMap = array(
|
||||||
'contacts' => array(
|
'contacts' => array(
|
||||||
|
'contact_id' => 'c.contact_id',
|
||||||
'contact_name' => 'co.name1 COLLATE latin1_general_ci',
|
'contact_name' => 'co.name1 COLLATE latin1_general_ci',
|
||||||
'contact_alias' => 'c.alias',
|
'contact_alias' => 'c.alias COLLATE latin1_general_ci',
|
||||||
'contact_email' => 'c.email_address',
|
'contact_email' => 'c.email_address COLLATE latin1_general_ci',
|
||||||
'contact_pager' => 'c.pager_address',
|
'contact_pager' => 'c.pager_address',
|
||||||
'contact_has_host_notfications' => 'c.host_notifications_enabled',
|
'contact_has_host_notfications' => 'c.host_notifications_enabled',
|
||||||
'contact_has_service_notfications' => 'c.service_notifications_enabled',
|
'contact_has_service_notfications' => 'c.service_notifications_enabled',
|
||||||
|
@ -27,6 +26,10 @@ class ContactQuery extends AbstractQuery
|
||||||
'contact_notify_host_flapping' => 'c.notify_host_flapping',
|
'contact_notify_host_flapping' => 'c.notify_host_flapping',
|
||||||
'contact_notify_host_downtime' => 'c.notify_host_downtime',
|
'contact_notify_host_downtime' => 'c.notify_host_downtime',
|
||||||
),
|
),
|
||||||
|
'timeperiods' => array(
|
||||||
|
'contact_notify_host_timeperiod' => 'ht.alias COLLATE latin1_general_ci',
|
||||||
|
'contact_notify_service_timeperiod' => 'st.alias COLLATE latin1_general_ci'
|
||||||
|
),
|
||||||
'hosts' => array(
|
'hosts' => array(
|
||||||
'host_object_id' => 'ho.object_id',
|
'host_object_id' => 'ho.object_id',
|
||||||
'host_name' => 'ho.name1 COLLATE latin1_general_ci',
|
'host_name' => 'ho.name1 COLLATE latin1_general_ci',
|
||||||
|
@ -87,4 +90,17 @@ class ContactQuery extends AbstractQuery
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function joinTimeperiods()
|
||||||
|
{
|
||||||
|
$this->baseQuery->join(
|
||||||
|
array('ht' => $this->prefix . 'timeperiods'),
|
||||||
|
'ht.timeperiod_object_id = c.host_timeperiod_object_id',
|
||||||
|
array()
|
||||||
|
);
|
||||||
|
$this->baseQuery->join(
|
||||||
|
array('st' => $this->prefix . 'timeperiods'),
|
||||||
|
'st.timeperiod_object_id = c.service_timeperiod_object_id',
|
||||||
|
array()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\DataView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the data needed by the 'Contact' DataView
|
||||||
|
*/
|
||||||
|
class Contact extends DataView
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve columns provided by this view
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getColumns()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'contact_name',
|
||||||
|
'contact_alias',
|
||||||
|
'contact_email',
|
||||||
|
'contact_pager',
|
||||||
|
'contact_notify_hosts',
|
||||||
|
'contact_notify_services',
|
||||||
|
'contact_has_host_notfications',
|
||||||
|
'contact_has_service_notfications',
|
||||||
|
'contact_can_submit_commands',
|
||||||
|
'contact_notify_service_recovery',
|
||||||
|
'contact_notify_service_warning',
|
||||||
|
'contact_notify_service_critical',
|
||||||
|
'contact_notify_service_unknown',
|
||||||
|
'contact_notify_service_flapping',
|
||||||
|
'contact_notify_service_downtime',
|
||||||
|
'contact_notify_host_recovery',
|
||||||
|
'contact_notify_host_down',
|
||||||
|
'contact_notify_host_unreachable',
|
||||||
|
'contact_notify_host_flapping',
|
||||||
|
'contact_notify_host_downtime',
|
||||||
|
'host_object_id',
|
||||||
|
'host_name',
|
||||||
|
'service_object_id',
|
||||||
|
'service_host_name',
|
||||||
|
'service_description'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getSortRules()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'contact_alias' => array(
|
||||||
|
'default_dir' => self::SORT_ASC,
|
||||||
|
'order' => self::SORT_DESC
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\DataView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the data needed by the Contactgroup DataView
|
||||||
|
*/
|
||||||
|
class Contactgroup extends DataView
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve columns provided by this view
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getColumns()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'contact_name',
|
||||||
|
'contactgroup_name',
|
||||||
|
'contactgroup_alias'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getSortRules()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'contactgroup_name' => array(
|
||||||
|
'default_dir' => self::SORT_ASC,
|
||||||
|
'order' => self::SORT_DESC
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue