Handle not readable monitoring config files more intelligent
This commit is contained in:
parent
91b1a649a7
commit
5c3df3db15
|
@ -44,6 +44,8 @@ use Icinga\Module\Monitoring\Form\Config\Backend\CreateBackendForm;
|
|||
use Icinga\Module\Monitoring\Form\Config\Instance\EditInstanceForm;
|
||||
use Icinga\Module\Monitoring\Form\Config\Instance\CreateInstanceForm;
|
||||
|
||||
use Icinga\Exception\NotReadableError;
|
||||
|
||||
/**
|
||||
* Configuration controller for editing monitoring resources
|
||||
*/
|
||||
|
@ -71,17 +73,17 @@ class Monitoring_ConfigController extends BaseConfigController {
|
|||
public function indexAction()
|
||||
{
|
||||
$this->view->messageBox = new AlertMessageBox(true);
|
||||
$monitoring_backends = IcingaConfig::module('monitoring', 'backends');
|
||||
$monitoring_instances = IcingaConfig::module('monitoring', 'instances');
|
||||
if ($monitoring_backends === null) {
|
||||
$this->view->backends = array();
|
||||
} else {
|
||||
$this->view->backends = $monitoring_backends->toArray();
|
||||
}
|
||||
if ($monitoring_instances === null) {
|
||||
$this->view->instances = array();
|
||||
} else {
|
||||
$this->view->instances = $monitoring_instances->toArray();
|
||||
foreach (array('backends', 'instances') as $element) {
|
||||
try {
|
||||
$elementConfig = IcingaConfig::module('monitoring', $element);
|
||||
if ($elementConfig === null) {
|
||||
$this->view->{$element} = array();
|
||||
} else {
|
||||
$this->view->{$element} = $elementConfig->toArray();
|
||||
}
|
||||
} catch (NotReadableError $e) {
|
||||
$this->view->{$element} = $e;
|
||||
}
|
||||
}
|
||||
$this->render('index');
|
||||
}
|
||||
|
|
|
@ -1,27 +1,41 @@
|
|||
<?php use Icinga\Web\Url; ?>
|
||||
<?php
|
||||
use Icinga\Web\Url;
|
||||
|
||||
$fileNotReadable = array();
|
||||
foreach (array('backends', 'instances') as $element) {
|
||||
if (is_object($this->{$element}) &&
|
||||
get_class($this->{$element}) === 'Icinga\Exception\NotReadableError') {
|
||||
$fileNotReadable[$element] = $this->{$element}->getMessage();
|
||||
} else {
|
||||
$fileNotReadable[$element] = false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="controls">
|
||||
<?= $this->tabs->render($this); ?>
|
||||
</div>
|
||||
|
||||
<div class="content" data-base-target="_next">
|
||||
<h1>Monitoring Backends</h1>
|
||||
<?php if ($fileNotReadable['backends'] === false): ?>
|
||||
<h1>Monitoring Backends</h1>
|
||||
|
||||
<?php if (isset($this->messageBox)): ?>
|
||||
<?= $this->messageBox->render() ?>
|
||||
<?php endif ?>
|
||||
<?php if (isset($this->messageBox)): ?>
|
||||
<?= $this->messageBox->render() ?>
|
||||
<?php endif ?>
|
||||
|
||||
<p>
|
||||
<a href="<?= Url::fromPath('/monitoring/config/createbackend')->getAbsoluteUrl();?>">
|
||||
<?= $this->icon('create.png'); ?> Create New Monitoring Backend
|
||||
</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="<?= Url::fromPath('/monitoring/config/createbackend')->getAbsoluteUrl();?>">
|
||||
<?= $this->icon('create.png'); ?> Create New Monitoring Backend
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<table class="action">
|
||||
<thead>
|
||||
<table class="action">
|
||||
<thead>
|
||||
<th>Monitoring Backend</th>
|
||||
<th style="width: 5em">Remove</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($this->backends as $backendName => $config): ?>
|
||||
<?php
|
||||
$removeUrl = Url::fromPath('/monitoring/config/removebackend', array('backend' => $backendName));
|
||||
|
@ -37,38 +51,49 @@
|
|||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php else: ?>
|
||||
<p class="fileNotReadable">
|
||||
<?= $this->escape($fileNotReadable['backends']) ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
|
||||
<h1>Monitoring Instances</h1>
|
||||
<?php if ($fileNotReadable['instances'] === false): ?>
|
||||
<h1>Monitoring Instances</h1>
|
||||
|
||||
<p>
|
||||
<a href="<?= Url::fromPath('/monitoring/config/createinstance')->getAbsoluteUrl();?>">
|
||||
<?= $this->icon('create.png'); ?> Create New Instance
|
||||
</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="<?= Url::fromPath('/monitoring/config/createinstance')->getAbsoluteUrl();?>">
|
||||
<?= $this->icon('create.png'); ?> Create New Instance
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<table class="action">
|
||||
<thead>
|
||||
<th>Instance</th>
|
||||
<th style="width: 5em">Remove</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($this->instances as $instanceName => $config): ?>
|
||||
<?php
|
||||
$removeUrl = Url::fromPath('/monitoring/config/removeinstance', array('instance' => $instanceName));
|
||||
$editUrl = Url::fromPath('/monitoring/config/editinstance', array('instance' => $instanceName));
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<?= $editUrl; ?>"><?= $this->icon('edit.png'); ?> <?= $this->escape($instanceName); ?></a>
|
||||
<small>(Type: <?= isset($config['host']) ? 'Remote' : 'Local'; ?>)</small>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?= $removeUrl; ?>"><?= $this->icon('remove.png'); ?></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="action">
|
||||
<thead>
|
||||
<th>Instance</th>
|
||||
<th style="width: 5em">Remove</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($this->instances as $instanceName => $config): ?>
|
||||
<?php
|
||||
$removeUrl = Url::fromPath('/monitoring/config/removeinstance', array('instance' => $instanceName));
|
||||
$editUrl = Url::fromPath('/monitoring/config/editinstance', array('instance' => $instanceName));
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<?= $editUrl; ?>"><?= $this->icon('edit.png'); ?> <?= $this->escape($instanceName); ?></a>
|
||||
<small>(Type: <?= isset($config['host']) ? 'Remote' : 'Local'; ?>)</small>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?= $removeUrl; ?>"><?= $this->icon('remove.png'); ?></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php else: ?>
|
||||
<p class="fileNotReadable">
|
||||
<?= $this->escape($fileNotReadable['instances']) ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
|
|
|
@ -278,3 +278,9 @@ html {
|
|||
margin-right: 2%;
|
||||
}
|
||||
|
||||
.fileNotReadable {
|
||||
padding: 0.5em;
|
||||
background-color: @colorCritical;
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue