ShowController: Deprecate historyAction
This commit is contained in:
parent
196450d8cf
commit
71e932bcf9
|
@ -1,12 +1,7 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
use Icinga\Module\Monitoring\Object\MonitoredObject;
|
||||
use Icinga\Web\Hook;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Tabs;
|
||||
use Icinga\Web\Widget\Tabextension\OutputFormat;
|
||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Controller;
|
||||
|
||||
|
@ -22,34 +17,6 @@ class Monitoring_ShowController extends Controller
|
|||
*/
|
||||
protected $backend;
|
||||
|
||||
/**
|
||||
* @var Hook\GrapherHook
|
||||
*/
|
||||
protected $grapher;
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->view->object = MonitoredObject::fromParams($this->params);
|
||||
if ($this->view->object && $this->view->object->fetch() === false) {
|
||||
throw new Zend_Controller_Action_Exception($this->translate('Host or service not found'));
|
||||
}
|
||||
|
||||
if (Hook::has('ticket')) {
|
||||
$this->view->tickets = Hook::first('ticket');
|
||||
}
|
||||
if (Hook::has('grapher')) {
|
||||
$this->grapher = Hook::first('grapher');
|
||||
if ($this->grapher && ! $this->grapher->hasPreviews()) {
|
||||
$this->grapher = null;
|
||||
}
|
||||
}
|
||||
|
||||
$this->createTabs();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
|
@ -66,37 +33,16 @@ class Monitoring_ShowController extends Controller
|
|||
$this->redirectNow(Url::fromRequest()->setPath('monitoring/host/show'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function historyAction()
|
||||
{
|
||||
$this->getTabs()->activate('history');
|
||||
$this->view->object->fetchEventHistory();
|
||||
$this->view->history = $this->view->object->eventhistory;
|
||||
$this->handleFormatRequest($this->view->object->eventhistory);
|
||||
$this->fetchHostStats();
|
||||
if ($this->params->has('service')) {
|
||||
$this->redirectNow(Url::fromRequest()->setPath('monitoring/service/history'));
|
||||
}
|
||||
|
||||
$this->setupLimitControl(50);
|
||||
$this->setupPaginationControl($this->view->history, 50);
|
||||
}
|
||||
|
||||
protected function fetchHostStats()
|
||||
{
|
||||
$this->view->stats = $this->backend->select()->from('statusSummary', array(
|
||||
'services_total',
|
||||
'services_ok',
|
||||
'services_problem',
|
||||
'services_problem_handled',
|
||||
'services_problem_unhandled',
|
||||
'services_critical',
|
||||
'services_critical_unhandled',
|
||||
'services_critical_handled',
|
||||
'services_warning',
|
||||
'services_warning_unhandled',
|
||||
'services_warning_handled',
|
||||
'services_unknown',
|
||||
'services_unknown_unhandled',
|
||||
'services_unknown_handled',
|
||||
'services_pending',
|
||||
))->where('service_host_name', $this->params->get('host'))->getQuery()->fetchRow();
|
||||
$this->redirectNow(Url::fromRequest()->setPath('monitoring/host/history'));
|
||||
}
|
||||
|
||||
public function contactAction()
|
||||
|
@ -162,91 +108,4 @@ class Monitoring_ShowController extends Controller
|
|||
$this->view->contact = $contact;
|
||||
$this->view->contactName = $contactName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating tabs for this controller
|
||||
* @return Tabs
|
||||
*/
|
||||
protected function createTabs()
|
||||
{
|
||||
if (($object = $this->view->object) === null) {
|
||||
return;
|
||||
}
|
||||
if ($object->getType() === $object::TYPE_HOST) {
|
||||
$isService = false;
|
||||
$params = array(
|
||||
'host' => $object->getName()
|
||||
);
|
||||
} else {
|
||||
$isService = true;
|
||||
$params = array(
|
||||
'host' => $object->getHost()->getName(),
|
||||
'service' => $object->getName()
|
||||
);
|
||||
}
|
||||
$tabs = $this->getTabs();
|
||||
$tabs->add(
|
||||
'host',
|
||||
array(
|
||||
'title' => sprintf(
|
||||
$this->translate('Show detailed information for host %s'),
|
||||
$isService ? $object->getHost()->getName() : $object->getName()
|
||||
),
|
||||
'label' => $this->translate('Host'),
|
||||
'icon' => 'host',
|
||||
'url' => 'monitoring/show/host',
|
||||
'urlParams' => $params,
|
||||
)
|
||||
);
|
||||
if ($isService) {
|
||||
$tabs->add(
|
||||
'service',
|
||||
array(
|
||||
'title' => sprintf(
|
||||
$this->translate('Show detailed information for service %s on host %s'),
|
||||
$object->getName(),
|
||||
$object->getHost()->getName()
|
||||
),
|
||||
'label' => $this->translate('Service'),
|
||||
'icon' => 'service',
|
||||
'url' => 'monitoring/show/service',
|
||||
'urlParams' => $params,
|
||||
)
|
||||
);
|
||||
}
|
||||
$tabs->add(
|
||||
'services',
|
||||
array(
|
||||
'title' => sprintf(
|
||||
$this->translate('List all services on host %s'),
|
||||
$isService ? $object->getHost()->getName() : $object->getName()
|
||||
),
|
||||
'label' => $this->translate('Services'),
|
||||
'icon' => 'services',
|
||||
'url' => 'monitoring/host/services',
|
||||
'urlParams' => $params,
|
||||
)
|
||||
);
|
||||
if ($this->backend->hasQuery('eventHistory')) {
|
||||
$tabs->add(
|
||||
'history',
|
||||
array(
|
||||
'title' => $isService
|
||||
? sprintf(
|
||||
$this->translate('Show all event records of service %s on host %s'),
|
||||
$object->getName(),
|
||||
$object->getHost()->getName()
|
||||
)
|
||||
: sprintf($this->translate('Show all event records of host %s'), $object->getName())
|
||||
,
|
||||
'label' => $this->translate('History'),
|
||||
'icon' => 'rewind',
|
||||
'url' => 'monitoring/show/history',
|
||||
'urlParams' => $params,
|
||||
)
|
||||
);
|
||||
}
|
||||
$tabs->extend(new OutputFormat())
|
||||
->extend(new DashboardAction());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,174 +0,0 @@
|
|||
<?php
|
||||
use Icinga\Module\Monitoring\Object\Host;
|
||||
use Icinga\Module\Monitoring\Object\Service;
|
||||
|
||||
$self = $this;
|
||||
$hostContext = $object->getType() === 'host';
|
||||
|
||||
if (! $this->compact): ?>
|
||||
<div class="controls">
|
||||
<?= $this->tabs; ?>
|
||||
<?php if ($hostContext): ?>
|
||||
<?= $this->render('partials/host/object-header.phtml'); ?>
|
||||
<?php else: ?>
|
||||
<?= $this->render('partials/service/object-header.phtml'); ?>
|
||||
<?php endif ?>
|
||||
<h1><?= $this->translate('This Object\'s Event History'); ?></h1>
|
||||
<?= $this->sortBox; ?>
|
||||
<?= $this->limiter; ?>
|
||||
<?= $this->paginator; ?>
|
||||
<?= $this->filterEditor; ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<div class="content">
|
||||
<?php
|
||||
|
||||
if (count($history) === 0) {
|
||||
echo $this->translate('No history available for this object') . '</div>';
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
function contactsLink($match, $view) {
|
||||
$links = array();
|
||||
foreach (preg_split('/,\s/', $match[1]) as $contact) {
|
||||
$links[] = $view->qlink(
|
||||
$contact,
|
||||
'monitoring/show/contact',
|
||||
array('contact_name' => $contact),
|
||||
array('title' => sprintf($view->translate('Show detailed information about %s'), $contact))
|
||||
);
|
||||
}
|
||||
return '[' . implode(', ', $links) . ']';
|
||||
}
|
||||
?>
|
||||
|
||||
<table data-base-target="_next" class="action objecthistory">
|
||||
<tbody>
|
||||
<?php foreach ($history as $event): ?>
|
||||
<?php
|
||||
$stateClass = 'invalid';
|
||||
$isService = isset($event->service_description);
|
||||
switch ($event->type) {
|
||||
case 'notify':
|
||||
$icon = 'notification';
|
||||
$title = $this->translate('Notification');
|
||||
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
|
||||
|
||||
$msg = preg_replace_callback(
|
||||
'/^\[([^\]]+)\]/',
|
||||
function($match) use ($self) { return contactsLink($match, $self); },
|
||||
$this->escape($event->output)
|
||||
);
|
||||
break;
|
||||
case 'comment':
|
||||
$icon = 'comment';
|
||||
$title = $this->translate('Comment');
|
||||
$msg = $this->escape($event->output);
|
||||
break;
|
||||
case 'comment_deleted':
|
||||
$icon = 'remove';
|
||||
$title = $this->translate('Comment deleted');
|
||||
$msg = $this->escape($event->output);
|
||||
break;
|
||||
case 'ack':
|
||||
$icon = 'acknowledgement';
|
||||
$title = $this->translate('Acknowledge');
|
||||
$msg = $this->escape($event->output);
|
||||
break;
|
||||
case 'ack_deleted':
|
||||
$icon = 'remove';
|
||||
$title = $this->translate('Ack removed');
|
||||
$msg = $this->escape($event->output);
|
||||
break;
|
||||
case 'dt_comment':
|
||||
$icon = 'in_downtime';
|
||||
$title = $this->translate('In Downtime');
|
||||
$msg = $this->escape($event->output);
|
||||
break;
|
||||
case 'dt_comment_deleted':
|
||||
$icon = 'remove';
|
||||
$title = $this->translate('Downtime removed');
|
||||
$msg = $this->escape($event->output);
|
||||
break;
|
||||
case 'flapping':
|
||||
$icon = 'flapping';
|
||||
$title = $this->translate('Flapping');
|
||||
$msg = $this->escape($event->output);
|
||||
break;
|
||||
case 'flapping_deleted':
|
||||
$icon = 'remove';
|
||||
$title = $this->translate('Flapping stopped');
|
||||
$msg = $this->escape($event->output);
|
||||
break;
|
||||
case 'hard_state':
|
||||
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output);
|
||||
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
|
||||
$icon = 'attention-alt';
|
||||
$title = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
|
||||
break;
|
||||
case 'soft_state':
|
||||
$icon = 'spinner';
|
||||
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output);
|
||||
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
|
||||
$title = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
|
||||
break;
|
||||
case 'dt_start':
|
||||
$icon = 'downtime_start';
|
||||
$title = $this->translate('Downtime Start');
|
||||
$msg = $this->escape($event->output);
|
||||
break;
|
||||
case 'dt_end':
|
||||
$icon = 'downtime_end';
|
||||
$title = $this->translate('Downtime End');
|
||||
$msg = $this->escape($event->output);
|
||||
break;
|
||||
}
|
||||
?>
|
||||
<tr class="state <?= $stateClass; ?>">
|
||||
<td class="state">
|
||||
<strong><?= $this->escape($title); ?></strong>
|
||||
<br>
|
||||
<?= date('d.m. H:i', $event->timestamp); ?>
|
||||
</td>
|
||||
<td><?php
|
||||
|
||||
$output = $this->tickets ? preg_replace_callback(
|
||||
$this->tickets->getPattern(),
|
||||
array($this->tickets, 'createLink'),
|
||||
$msg
|
||||
) : $msg;
|
||||
|
||||
?>
|
||||
<?php if ($isService): ?>
|
||||
<?= sprintf(
|
||||
$this->translate('%s on %s', 'Service running on host'),
|
||||
$hostContext ? $this->qlink(
|
||||
$event->service_display_name,
|
||||
'monitoring/show/service',
|
||||
array(
|
||||
'host' => $event->host_name,
|
||||
'service' => $event->service_description
|
||||
),
|
||||
array('title' => sprintf(
|
||||
$this->translate('Show detailed information for service %s on host %s'),
|
||||
$event->service_display_name,
|
||||
$event->host_display_name
|
||||
))
|
||||
) : $this->escape($event->service_display_name),
|
||||
$event->host_display_name
|
||||
) ?>
|
||||
<?php else: ?>
|
||||
<?= $this->escape($event->host_name); ?>
|
||||
<?php endif ?>
|
||||
<br>
|
||||
<div>
|
||||
<?= $this->icon($icon, $title); ?> <?= empty($msg) ? '' : $msg; ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
Loading…
Reference in New Issue