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;
}
/**
* List contact groups
*/
public function contactgroupsAction()
{
$this->addTitleTab(
@ -350,39 +353,22 @@ class ListController extends Controller
$this->translate('List contact groups')
);
$query = $this->backend->select()->from('contactgroup', array(
$contactGroups = $this->backend->select()->from('contactgroup', array(
'contactgroup_name',
'contactgroup_alias',
'contact_name',
'contact_alias',
'contact_email',
'contact_pager'
'contact_count'
));
$this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $contactGroups);
$this->filterQuery($contactGroups);
$this->setupPaginationControl($contactGroups);
$this->setupLimitControl();
$this->setupSortControl(array(
'contactgroup_name' => $this->translate('Contactgroup Name'),
'contactgroup_alias' => $this->translate('Contactgroup Alias')
), $query);
), $contactGroups);
// Fetch and prepare all contact groups:
$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;
$this->view->contactGroups = $contactGroups;
}
/**

View File

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

View File

@ -16,12 +16,12 @@ class ContactgroupQuery extends IdoQuery
/**
* {@inheritdoc}
*/
protected $groupBase = array('contactgroups' => array('cg.contactgroup_id', 'cgo.object_id'));
protected $groupBase = array('contactgroups' => array('cg.contactgroup_id'));
/**
* {@inheritdoc}
*/
protected $groupOrigin = array('contacts', 'hosts', 'services');
protected $groupOrigin = array('hosts', 'members', 'services');
/**
* {@inheritdoc}
@ -32,28 +32,8 @@ class ContactgroupQuery extends IdoQuery
'contactgroup_name' => 'cgo.name1',
'contactgroup_alias' => 'cg.alias COLLATE latin1_general_ci'
),
'contacts' => array(
'contact_id' => 'c.contact_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'
'members' => array(
'contact_count' => 'COUNT(cgm.contactgroup_member_id)'
),
'hostgroups' => array(
'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(
array('cgm' => $this->prefix . 'contactgroup_members'),
'cgm.contactgroup_id = cg.contactgroup_id',
array()
)->joinLeft(
)->join(
array('co' => $this->prefix . 'objects'),
'co.object_id = cgm.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10',
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()
{
return array(
'instance_name',
'contactgroup_name',
'contactgroup_alias',
'contact_object_id',
'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'
'contact_count'
);
}
@ -60,9 +38,10 @@ class Contactgroup extends DataView
public function getStaticFilterColumns()
{
return array(
'contactgroup', 'contact',
'contactgroup',
'host', 'host_name', 'host_display_name', 'host_alias',
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
'instance_name',
'service', 'service_description', 'service_display_name',
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
);