Skip to content

Commit

Permalink
Merge branch 'bugfix/contact-detail-4804'
Browse files Browse the repository at this point in the history
fixes #4806
  • Loading branch information
mxhash committed Aug 27, 2014
2 parents 70fdd58 + 5e84ff4 commit e342035
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 15 deletions.
40 changes: 35 additions & 5 deletions modules/monitoring/application/controllers/ShowController.php
Expand Up @@ -108,19 +108,22 @@ public function servicesAction()

public function contactAction()
{
$contact = $this->getParam('contact');
if (! $contact) {
$contactName = $this->getParam('contact');

if (! $contactName) {
throw new Zend_Controller_Action_Exception(
$this->translate('The parameter `contact\' is required'),
404
);
}

$query = $this->backend->select()->from('contact', array(
'contact_name',
'contact_id',
'contact_alias',
'contact_email',
'contact_pager',
'contact_object_id',
'contact_notify_service_timeperiod',
'contact_notify_service_recovery',
'contact_notify_service_warning',
Expand All @@ -135,9 +138,36 @@ public function contactAction()
'contact_notify_host_flapping',
'contact_notify_host_downtime',
));
$query->where('contact_name', $contact);
$this->view->contacts = $query->paginate();
$this->view->contact_name = $contact;

$query->where('contact_name', $contactName);

$contact = $query->getQuery()->fetchRow();

if ($contact) {
$commands = $this->backend->select()->from('command', array(
'command_line',
'command_name'
))->where('contact_id', $contact->contact_id);

$this->view->commands = $commands->paginate();

$notifications = $this->backend->select()->from('notification', array(
'host',
'service',
'notification_output',
'notification_contact',
'notification_start_time',
'notification_state'
));

$notifications->where('contact_object_id', $contact->contact_object_id);

$this->view->compact = true;
$this->view->notifications = $notifications->paginate();
}

$this->view->contact = $contact;
$this->view->contactName = $contactName;
}

/**
Expand Down
24 changes: 15 additions & 9 deletions modules/monitoring/application/views/scripts/show/contact.phtml
Expand Up @@ -2,7 +2,7 @@
$contactHelper = $this->getHelper('ContactFlags');
?>
<div style="margin-top: 0.5em;">
<?php foreach ($contacts as $contact): ?>
<?php if ($contact): ?>
<table style="border-spacing: 0.25em; border-collapse: separate;">
<thead>
<tr>
Expand Down Expand Up @@ -45,12 +45,18 @@ $contactHelper = $this->getHelper('ContactFlags');
</tr>
</tbody>
</table>
<?php
return;
endforeach;
printf(
'%s: `%s\'',
t('No such contact'), $contact_name
);
?>

<h4><?= $this->translate('Commands'); ?>:</h4>
<ul>
<?php foreach ($commands as $command): ?>
<li><?= $command->command_name; ?></li>
<?php endforeach; ?>
</ul>

<h4><?= $this->translate('Notifications'); ?>:</h4>
<?= $this->render('list/notifications.phtml') ?>

<?php else: ?>
<?= $this->translate('No such contact'); ?>: <?= $contactName; ?>
<?php endif; ?>
</div>
@@ -0,0 +1,60 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Module\Monitoring\Backend\Ido\Query;

/**
* Query for commands
*/
class CommandQuery extends IdoQuery
{
/**
* @var array
*/
protected $columnMap = array(
'commands' => array(
'command_id' => 'c.command_id',
'command_instance_id' => 'c.instance_id',
'command_config_type' => 'c.config_type',
'command_line' => 'c.command_line',
'command_name' => 'co.name1'
),

'contacts' => array(
'contact_id' => 'con.contact_id',
'contact_alias' => 'con.contact_alias'
)
);

/**
* Fetch basic information about commands
*/
protected function joinBaseTables()
{
$this->select->from(
array('c' => $this->prefix . 'commands'),
array()
)->join(
array('co' => $this->prefix . 'objects'),
'co.object_id = c.object_id',
array()
);

$this->joinedVirtualTables = array('commands' => true);
}

/**
* Join contacts
*/
protected function joinContacts()
{
$this->select->join(
array('cnc' => $this->prefix . 'contact_notificationcommands'),
'cnc.command_object_id = co.object_id'
)->join(
array('con' => $this->prefix . 'contacts'),
'con.contact_id = cnc.contact_id'
);
}
}
Expand Up @@ -13,6 +13,7 @@ class ContactQuery extends IdoQuery
'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',
Expand Down
Expand Up @@ -25,7 +25,8 @@ class NotificationQuery extends IdoQuery
'service' => 'o.name2'
),
'contact' => array(
'notification_contact' => 'c_o.name1'
'notification_contact' => 'c_o.name1',
'contact_object_id' => 'c_o.object_id'
),
'command' => array(
'notification_command' => 'cmd_o.name1'
Expand Down
28 changes: 28 additions & 0 deletions modules/monitoring/library/Monitoring/DataView/Command.php
@@ -0,0 +1,28 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Module\Monitoring\DataView;

/**
* View representation for commands
*/
class Command extends DataView
{
/**
* Retrieve columns provided by this view
*
* @return array
*/
public function getColumns()
{
return array(
'command_id',
'command_instance_id',
'command_config_type',
'command_line',
'command_name'
);
}

}
1 change: 1 addition & 0 deletions modules/monitoring/library/Monitoring/DataView/Contact.php
Expand Up @@ -38,6 +38,7 @@ public function getColumns()
'contact_notify_host_unreachable',
'contact_notify_host_flapping',
'contact_notify_host_downtime',
'contact_object_id',
'host_object_id',
'host_name',
'service_object_id',
Expand Down

0 comments on commit e342035

Please sign in to comment.