monitoring: No longer provide contact columns in the contact group query

Contacts query w/ filter for contact group should be used instead.
This commit is contained in:
Eric Lippmann 2016-03-31 09:14:15 +02:00
parent 7481e3af43
commit a2ff8c9778
4 changed files with 50 additions and 112 deletions

View File

@ -342,6 +342,9 @@ class ListController extends Controller
$this->view->orientation = $orientation; $this->view->orientation = $orientation;
} }
/**
* List contact groups
*/
public function contactgroupsAction() public function contactgroupsAction()
{ {
$this->addTitleTab( $this->addTitleTab(
@ -350,39 +353,22 @@ class ListController extends Controller
$this->translate('List contact groups') $this->translate('List contact groups')
); );
$query = $this->backend->select()->from('contactgroup', array( $contactGroups = $this->backend->select()->from('contactgroup', array(
'contactgroup_name', 'contactgroup_name',
'contactgroup_alias', 'contactgroup_alias',
'contact_name', 'contact_count'
'contact_alias',
'contact_email',
'contact_pager'
)); ));
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $contactGroups);
$this->filterQuery($query); $this->filterQuery($contactGroups);
$this->setupPaginationControl($contactGroups);
$this->setupLimitControl();
$this->setupSortControl(array( $this->setupSortControl(array(
'contactgroup_name' => $this->translate('Contactgroup Name'), 'contactgroup_name' => $this->translate('Contactgroup Name'),
'contactgroup_alias' => $this->translate('Contactgroup Alias') 'contactgroup_alias' => $this->translate('Contactgroup Alias')
), $query); ), $contactGroups);
// Fetch and prepare all contact groups: $this->view->contactGroups = $contactGroups;
$contactgroups = $query->getQuery()->fetchAll();
$groupData = array();
foreach ($contactgroups as $c) {
if (!array_key_exists($c->contactgroup_name, $groupData)) {
$groupData[$c->contactgroup_name] = array(
'alias' => $c->contactgroup_alias,
'contacts' => array()
);
}
if (isset ($c->contact_name)) {
$groupData[$c->contactgroup_name]['contacts'][] = $c;
}
}
// TODO: Find a better naming
$this->view->groupData = $groupData;
} }
/** /**

View File

@ -12,42 +12,39 @@ if (! $this->compact): ?>
</div> </div>
<?php endif ?> <?php endif ?>
<div class="content"> <div class="content">
<?php <?php if (! $contactGroups->hasResult()): ?>
if (count($groupData) === 0) { <p><?= $this->translate('No contact groups found matching the filter') ?></p>
echo $this->translate('No contactgroups found matching the filter') . '</div>'; </div>
return; <?php return; endif ?>
} <table class="common-table table-row-selectable" data-base-target="_next">
?>
<table class="action table-row-selectable common-table" data-base-target="_next">
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<th><?= $this->translate('Contact Group ') ?></th> <th><?= $this->translate('Contact Group ') ?></th>
<th><?= $this->translate('Alias') ?></th> <th><?= $this->translate('Alias') ?></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($contactGroups as $contactGroup): ?>
<?php foreach ($groupData as $groupName => $groupInfo): ?> <tr>
<tr> <td class="count-col">
<td class="count-col"> <span class="badge"><?= $contactGroup->contact_count ?></span>
<span class="badge"><?= count($groupInfo['contacts']) ?></span> </td>
</td> <td>
<?= $this->qlink(
$contactGroup->contactgroup_name,
'monitoring/list/contacts',
array('contactgroup_name' => $contactGroup->contactgroup_name),
array('title' => sprintf(
$this->translate('Show detailed information about %s'),
$contactGroup->contactgroup_name
))
) ?>
</td>
<td> <td>
<?= $this->qlink( <?php if ($contactGroup->contactgroup_name !== $contactGroup->contactgroup_alias): ?>
$groupName, <?= $contactGroup->contactgroup_alias ?>
'monitoring/list/contacts', <?php endif ?>
array('contactgroup_name' => $groupName),
array('title' => sprintf(
$this->translate('Show detailed information about %s'),
$groupName
))
) ?>
</td>
<td>
<?php if ($groupInfo['alias'] !== $groupName): ?>
<?= $groupInfo['alias'] ?>
<?php endif ?>
</td> </td>
</tr> </tr>
<?php endforeach ?> <?php endforeach ?>

View File

@ -16,12 +16,12 @@ class ContactgroupQuery extends IdoQuery
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected $groupBase = array('contactgroups' => array('cg.contactgroup_id', 'cgo.object_id')); protected $groupBase = array('contactgroups' => array('cg.contactgroup_id'));
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected $groupOrigin = array('contacts', 'hosts', 'services'); protected $groupOrigin = array('hosts', 'members', 'services');
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -32,28 +32,8 @@ class ContactgroupQuery extends IdoQuery
'contactgroup_name' => 'cgo.name1', 'contactgroup_name' => 'cgo.name1',
'contactgroup_alias' => 'cg.alias COLLATE latin1_general_ci' 'contactgroup_alias' => 'cg.alias COLLATE latin1_general_ci'
), ),
'contacts' => array( 'members' => array(
'contact_id' => 'c.contact_id', 'contact_count' => 'COUNT(cgm.contactgroup_member_id)'
'contact' => 'co.name1 COLLATE latin1_general_ci',
'contact_name' => 'co.name1',
'contact_alias' => 'c.alias COLLATE latin1_general_ci',
'contact_email' => 'c.email_address COLLATE latin1_general_ci',
'contact_pager' => 'c.pager_address',
'contact_object_id' => 'c.contact_object_id',
'contact_has_host_notfications' => 'c.host_notifications_enabled',
'contact_has_service_notfications' => 'c.service_notifications_enabled',
'contact_can_submit_commands' => 'c.can_submit_commands',
'contact_notify_service_recovery' => 'c.notify_service_recovery',
'contact_notify_service_warning' => 'c.notify_service_warning',
'contact_notify_service_critical' => 'c.notify_service_critical',
'contact_notify_service_unknown' => 'c.notify_service_unknown',
'contact_notify_service_flapping' => 'c.notify_service_flapping',
'contact_notify_service_downtime' => 'c.notify_service_recovery',
'contact_notify_host_recovery' => 'c.notify_host_recovery',
'contact_notify_host_down' => 'c.notify_host_down',
'contact_notify_host_unreachable' => 'c.notify_host_unreachable',
'contact_notify_host_flapping' => 'c.notify_host_flapping',
'contact_notify_host_downtime' => 'c.notify_host_downtime'
), ),
'hostgroups' => array( 'hostgroups' => array(
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
@ -99,22 +79,18 @@ class ContactgroupQuery extends IdoQuery
} }
/** /**
* Join contacts * Join contact group members
*/ */
protected function joinContacts() protected function joinMembers()
{ {
$this->select->joinLeft( $this->select->joinLeft(
array('cgm' => $this->prefix . 'contactgroup_members'), array('cgm' => $this->prefix . 'contactgroup_members'),
'cgm.contactgroup_id = cg.contactgroup_id', 'cgm.contactgroup_id = cg.contactgroup_id',
array() array()
)->joinLeft( )->join(
array('co' => $this->prefix . 'objects'), array('co' => $this->prefix . 'objects'),
'co.object_id = cgm.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10', 'co.object_id = cgm.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10',
array() array()
)->joinLeft(
array('c' => $this->prefix . 'contacts'),
'c.contact_object_id = co.object_id',
array()
); );
} }

View File

@ -11,31 +11,9 @@ class Contactgroup extends DataView
public function getColumns() public function getColumns()
{ {
return array( return array(
'instance_name',
'contactgroup_name', 'contactgroup_name',
'contactgroup_alias', 'contactgroup_alias',
'contact_object_id', 'contact_count'
'contact_id',
'contact_name',
'contact_alias',
'contact_email',
'contact_pager',
'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',
'contact_notify_host_timeperiod',
'contact_notify_service_timeperiod'
); );
} }
@ -60,9 +38,10 @@ class Contactgroup extends DataView
public function getStaticFilterColumns() public function getStaticFilterColumns()
{ {
return array( return array(
'contactgroup', 'contact', 'contactgroup',
'host', 'host_name', 'host_display_name', 'host_alias', 'host', 'host_name', 'host_display_name', 'host_alias',
'hostgroup', 'hostgroup_alias', 'hostgroup_name', 'hostgroup', 'hostgroup_alias', 'hostgroup_name',
'instance_name',
'service', 'service_description', 'service_display_name', 'service', 'service_description', 'service_display_name',
'servicegroup', 'servicegroup_alias', 'servicegroup_name' 'servicegroup', 'servicegroup_alias', 'servicegroup_name'
); );