Implement monitoring instance and backend configuration forms
refs #3776
This commit is contained in:
parent
4c5d26fe9a
commit
83d053965f
|
@ -74,7 +74,6 @@ class SecureShell implements Transport
|
|||
$this->host = isset($config->host) ? $config->host : "localhost";
|
||||
$this->port = isset($config->port) ? $config->port : 22;
|
||||
$this->user = isset($config->user) ? $config->user : null;
|
||||
$this->password = isset($config->password) ? $config->password : null;
|
||||
$this->path = isset($config->path) ? $config->path : "/usr/local/icinga/var/rw/icinga.cmd";
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,30 @@
|
|||
|
||||
use \Icinga\Web\Controller\BaseConfigController;
|
||||
use \Icinga\Web\Widget\Tab;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Web\Url;
|
||||
use \Icinga\Config\PreservingIniWriter;
|
||||
|
||||
use \Monitoring\Form\Config\ConfirmRemovalForm;
|
||||
use \Monitoring\Form\Config\Backend\EditBackendForm;
|
||||
use \Monitoring\Form\Config\Backend\CreateBackendForm;
|
||||
|
||||
use \Monitoring\Form\Config\Instance\EditInstanceForm;
|
||||
use \Monitoring\Form\Config\Instance\CreateInstanceForm;
|
||||
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* Configuration controller for editing monitoring resources
|
||||
*
|
||||
*/
|
||||
class Monitoring_ConfigController extends BaseConfigController {
|
||||
|
||||
/**
|
||||
* Create the tabs for being available via the applications 'Config' view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function createProvidedTabs()
|
||||
{
|
||||
return array(
|
||||
|
@ -44,10 +64,226 @@ class Monitoring_ConfigController extends BaseConfigController {
|
|||
);
|
||||
}
|
||||
|
||||
public function backendAction()
|
||||
/**
|
||||
* Display a list of available backends and instances
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$this->redirectNow('/config');
|
||||
$this->view->backends = IcingaConfig::module('monitoring', 'backends')->toArray();
|
||||
$this->view->instances = IcingaConfig::module('monitoring', 'instances')->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to modify the backend identified by the 'backend' parameter of the request
|
||||
*
|
||||
*/
|
||||
public function editbackendAction()
|
||||
{
|
||||
$backend = $this->getParam('backend');
|
||||
if (!$this->isExistingBackend($backend)) {
|
||||
$this->view->error = "Unknown backend " . htmlentities($backend);
|
||||
return;
|
||||
}
|
||||
$backendForm = new EditBackendForm();
|
||||
$backendForm->setRequest($this->getRequest());
|
||||
$backendForm->setBackendConfiguration(IcingaConfig::module('monitoring', 'backends')->get($backend));
|
||||
|
||||
if ($backendForm->isSubmittedAndValid()) {
|
||||
|
||||
$newConfig = $backendForm->getConfig();
|
||||
$config = IcingaConfig::module('monitoring', 'backends');
|
||||
$config->$backend = $newConfig;
|
||||
if ($this->writeConfiguration($config, 'backends')) {
|
||||
$this->redirectNow('monitoring/config');
|
||||
} else {
|
||||
$this->render('show-configuration');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->view->name = $backend;
|
||||
$this->view->form = $backendForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to create a new backend
|
||||
* s
|
||||
*/
|
||||
public function createbackendAction()
|
||||
{
|
||||
$form = new CreateBackendForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
$configArray = IcingaConfig::module('monitoring', 'backends')->toArray();
|
||||
$configArray[$form->getBackendName()] = $form->getConfig();
|
||||
|
||||
if ($this->writeConfiguration(new Zend_Config($configArray), 'backends')) {
|
||||
$this->redirectNow('monitoring/config');
|
||||
} else {
|
||||
$this->render('show-configuration');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->view->form = $form;
|
||||
$this->render('editbackend');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a confirmation form to remove the backend identified by the 'backend' parameter
|
||||
*
|
||||
*/
|
||||
public function removebackendAction()
|
||||
{
|
||||
$backend = $this->getParam('backend');
|
||||
if (!$this->isExistingBackend($backend)) {
|
||||
$this->view->error = "Unknown backend " . $backend;
|
||||
return;
|
||||
}
|
||||
$form = new ConfirmRemovalForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setRemoveTarget('backend', $backend);
|
||||
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
$configArray = IcingaConfig::module('monitoring', 'backends')->toArray();
|
||||
unset($configArray[$backend]);
|
||||
|
||||
if ($this->writeConfiguration(new Zend_Config($configArray), 'backends')) {
|
||||
$this->redirectNow('monitoring/config');
|
||||
} else {
|
||||
$this->render('show-configuration');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
$this->view->name = $backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to remove the instance identified by the 'instance' parameter
|
||||
*
|
||||
*/
|
||||
public function removeinstanceAction()
|
||||
{
|
||||
$instance = $this->getParam('instance');
|
||||
if (!$this->isExistingInstance($instance)) {
|
||||
$this->view->error = "Unknown instance " . $instance;
|
||||
return;
|
||||
}
|
||||
|
||||
$form = new ConfirmRemovalForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setRemoveTarget('instance', $instance);
|
||||
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
$configArray = IcingaConfig::module('monitoring', 'instances')->toArray();
|
||||
unset($configArray[$instance]);
|
||||
|
||||
if ($this->writeConfiguration(new Zend_Config($configArray), 'instances')) {
|
||||
$this->redirectNow('monitoring/config');
|
||||
} else {
|
||||
$this->render('show-configuration');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
$this->view->name = $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to edit the instance identified by the 'instance' parameter of the request
|
||||
*/
|
||||
public function editinstanceAction()
|
||||
{
|
||||
$instance = $this->getParam('instance');
|
||||
if (!$this->isExistingInstance($instance)) {
|
||||
$this->view->error = "Unknown instance " . htmlentities($instance);
|
||||
return;
|
||||
}
|
||||
$form = new EditInstanceForm();
|
||||
$form->setInstanceConfiguration(IcingaConfig::module('monitoring', 'instances')->get($instance));
|
||||
$form->setRequest($this->getRequest());
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
$instanceConfig = IcingaConfig::module('monitoring', 'instances')->toArray();
|
||||
$instanceConfig[$instance] = $form->getConfig();
|
||||
if ($this->writeConfiguration(new Zend_Config($instanceConfig), 'instances')) {
|
||||
$this->redirectNow('monitoring/config');
|
||||
} else {
|
||||
$this->render('show-configuration');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to create a new instance
|
||||
*
|
||||
*/
|
||||
public function createinstanceAction()
|
||||
{
|
||||
$form = new CreateInstanceForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
$instanceConfig = IcingaConfig::module('monitoring', 'instances')->toArray();
|
||||
$instanceConfig[$form->getInstanceName()] = $form->getConfig()->toArray();
|
||||
if ($this->writeConfiguration(new Zend_Config($instanceConfig), 'instances')) {
|
||||
$this->redirectNow('monitoring/config');
|
||||
} else {
|
||||
$this->render('show-configuration');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->view->form = $form;
|
||||
$this->render('editinstance');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to remove the instance identified by the 'instance' parameter
|
||||
*
|
||||
*/
|
||||
private function writeConfiguration($config, $file)
|
||||
{
|
||||
$writer = new PreservingIniWriter(array(
|
||||
'filename' => IcingaConfig::module('monitoring', $file)->getConfigFile(),
|
||||
'config' => $config
|
||||
));
|
||||
|
||||
try {
|
||||
$writer->write();
|
||||
return true;
|
||||
} catch (Exception $exc) {
|
||||
$this->view->exceptionMessage = $exc->getMessage();
|
||||
$this->view->iniConfigurationString = $writer->render();
|
||||
$this->view->file = IcingaConfig::module('monitoring', $file)->getConfigFile();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the backend exists in the current configuration
|
||||
*
|
||||
* @param string $backend The name of the backend to check for existence
|
||||
*
|
||||
* @return bool True if the backend name exists, otherwise false
|
||||
*/
|
||||
private function isExistingBackend($backend)
|
||||
{
|
||||
$backendCfg = IcingaConfig::module('monitoring', 'backends');
|
||||
return $backend && $backendCfg->get($backend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the instance exists in the current configuration
|
||||
*
|
||||
* @param string $backend The name of the instance to check for existence
|
||||
*
|
||||
* @return bool True if the instance name exists, otherwise false
|
||||
*/
|
||||
private function isExistingInstance($instance)
|
||||
{
|
||||
$instanceCfg = IcingaConfig::module('monitoring', 'instances');
|
||||
return $instanceCfg && $instanceCfg->get($instance);
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga 2 Web.
|
||||
*
|
||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
|
||||
namespace Monitoring\Form\Config\Backend;
|
||||
|
||||
use \Zend_Config;
|
||||
|
||||
/**
|
||||
* Extended EditBackendForm for creating new Backends
|
||||
*
|
||||
* @see EditBackendForm
|
||||
*/
|
||||
class CreateBackendForm extends EditBackendForm
|
||||
{
|
||||
/**
|
||||
* Create this form
|
||||
*
|
||||
* @see EditBackendForm::create()
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->setBackendConfiguration(new Zend_Config(array('type' => 'ido')));
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_name',
|
||||
array(
|
||||
'label' => 'Backend Name',
|
||||
'required' => true,
|
||||
'helptext' => 'This will be the identifier of this backend'
|
||||
)
|
||||
);
|
||||
parent::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the backend that is to be created
|
||||
*
|
||||
* @return string The name of the backend as entered in the form
|
||||
*/
|
||||
public function getBackendName()
|
||||
{
|
||||
return $this->getValue('backend_name');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,291 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga 2 Web.
|
||||
*
|
||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Monitoring\Form\Config\Backend;
|
||||
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\Logger;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
|
||||
use \Icinga\Web\Form;
|
||||
use \Icinga\Web\Form\Element\Note;
|
||||
use \Zend_Config;
|
||||
|
||||
/**
|
||||
* Form for modifying a monitoring backend
|
||||
*
|
||||
*/
|
||||
class EditBackendForm extends Form
|
||||
{
|
||||
/**
|
||||
* Database resources to use instead of the one's from DBAdapterFactory (used for testing)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $resources;
|
||||
|
||||
/**
|
||||
* The Backend configuration to use for populating the form
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $backend;
|
||||
|
||||
/**
|
||||
* Mapping from form fields to configuration fields
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $propertyMapping = array(
|
||||
'livestatus' => array(
|
||||
'backend_livestatus_socket' => 'socket'
|
||||
),
|
||||
'ido' => array(
|
||||
'backend_ido_resource' => 'resource'
|
||||
),
|
||||
'statusdat' => array(
|
||||
'backend_statusdat_statusfile' => 'status_file',
|
||||
'backend_statusdat_objectfile' => 'object_file'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Set the configuration to be used for initial population of the form
|
||||
*
|
||||
* @param Zend_Form $config
|
||||
*/
|
||||
public function setBackendConfiguration($config)
|
||||
{
|
||||
$this->backend = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a custom array of resources to be used in this form instead of the ones from DbAdapterFactory
|
||||
* (used for testing)
|
||||
*
|
||||
*/
|
||||
public function setResources($resources)
|
||||
{
|
||||
$this->resources = $resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content of the resources.ini or previously set resources for displaying in the database selection field
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
if ($this->resources === null) {
|
||||
return DbAdapterFactory::getResources();
|
||||
} else {
|
||||
return $this->resources;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all database resource ready to be used as the multiOptions
|
||||
* attribute in a Zend_Form_Element_Select object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getDatabaseResources()
|
||||
{
|
||||
$backends = array();
|
||||
foreach ($this->getResources() as $resname => $resource) {
|
||||
if ($resource['type'] !== 'db') {
|
||||
continue;
|
||||
}
|
||||
$backends[$resname] = $resname;
|
||||
}
|
||||
return $backends;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add form elements used for setting IDO backend parameters
|
||||
*
|
||||
*/
|
||||
private function addIdoBackendForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'select',
|
||||
'backend_ido_resource',
|
||||
array(
|
||||
'label' => 'Ido Connection',
|
||||
'value' => $this->backend->resource,
|
||||
'required' => true,
|
||||
'multiOptions' => $this->getDatabaseResources(),
|
||||
'helptext' => 'The database to use for querying monitoring data',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add form elements used for setting status.dat backend parameters
|
||||
*
|
||||
*/
|
||||
private function addStatusDatForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_statusdat_statusfile',
|
||||
array (
|
||||
'label' => 'Status.dat File',
|
||||
'value' => $this->backend->status_file,
|
||||
'required' => true,
|
||||
'helptext' => 'Location of your icinga status.dat file'
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_statusdat_objectfile',
|
||||
array (
|
||||
'label' => 'Objects.cache File',
|
||||
'value' => $this->backend->status_file,
|
||||
'required' => true,
|
||||
'helptext' => 'Location of your icinga objects.cache file'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add form elements used for setting livstatus parameters
|
||||
*
|
||||
*/
|
||||
private function addLivestatusForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_livestatus_socket',
|
||||
array(
|
||||
'label' => 'Livestatus Socket Location',
|
||||
'required' => true,
|
||||
'helptext' => 'The path to your livestatus socket used for querying monitoring data',
|
||||
'value' => $this->backend->socket,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a checkbox to disable this backends
|
||||
*
|
||||
*/
|
||||
private function addDisableButton()
|
||||
{
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
'backend_disable',
|
||||
array(
|
||||
'label' => 'Disable this Backend',
|
||||
'required' => true,
|
||||
'value' => $this->backend->disabled
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a select box for choosing the type to use for this backend
|
||||
*
|
||||
*/
|
||||
private function addTypeSelectionBox()
|
||||
{
|
||||
$this->addElement(
|
||||
'select',
|
||||
'backend_type',
|
||||
array(
|
||||
'label' => 'Backend Type',
|
||||
'value' => $this->backend->type,
|
||||
'required' => true,
|
||||
'helptext' => 'The data source used for retrieving monitoring information',
|
||||
'multiOptions' => array(
|
||||
'ido' => 'IDO Backend',
|
||||
'statusdat' => 'Status.dat',
|
||||
'livestatus' => 'Livestatus'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->enableAutoSubmit(array('backend_type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this form
|
||||
*
|
||||
* @see Icinga\Web\Form::create()
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->addTypeSelectionBox();
|
||||
switch ($this->getRequest()->getParam('backend_type', $this->backend->type)) {
|
||||
case 'ido':
|
||||
$this->addIdoBackendForm();
|
||||
break;
|
||||
case 'statusdat':
|
||||
$this->addStatusDatForm();
|
||||
break;
|
||||
case 'livestatus':
|
||||
$this->addLivestatusForm();
|
||||
break;
|
||||
default:
|
||||
$this->removeElement('backend_type');
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'error_note',
|
||||
'value' => 'Unknown Backend Type "' . $this->backend->type. '"'
|
||||
)
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
$this->addDisableButton();
|
||||
$this->setSubmitLabel('Save Changes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a configuration containing the backend settings entered in this form
|
||||
*
|
||||
* @return Zend_Config The updated configuration for this backend
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$values = $this->getValues();
|
||||
$type = $values['backend_type'];
|
||||
|
||||
$map = $this->propertyMapping[$type];
|
||||
$result = array(
|
||||
'type' => $type,
|
||||
'disabled' => $values['backend_disable']
|
||||
);
|
||||
foreach ($map as $formKey => $mappedKey) {
|
||||
$result[$mappedKey] = $values[$formKey];
|
||||
}
|
||||
return new Zend_Config($result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga 2 Web.
|
||||
*
|
||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
|
||||
namespace Monitoring\Form\Config;
|
||||
|
||||
use Icinga\Web\Form;
|
||||
|
||||
/**
|
||||
* Form for confirming removal of an object
|
||||
*/
|
||||
class ConfirmRemovalForm extends Form
|
||||
{
|
||||
|
||||
/**
|
||||
* The value of the target to remove
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $removeTarget;
|
||||
|
||||
/**
|
||||
* The name of the target parameter to remove
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $targetName;
|
||||
|
||||
/**
|
||||
* Set the remove target in this field to be a hidden field with $name and value $target
|
||||
*
|
||||
* @param string $name The name to be set in the hidden field
|
||||
* @param string $target The value to be set in the hidden field
|
||||
*/
|
||||
public function setRemoveTarget($name, $target)
|
||||
{
|
||||
$this->targetName = $name;
|
||||
$this->removeTarget = $target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the confirmation form
|
||||
*
|
||||
* @see Icinga\Web\Form
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
$this->targetName,
|
||||
array(
|
||||
'value' => $this->removeTarget,
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
$this->setSubmitLabel('Confirm removal');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga 2 Web.
|
||||
*
|
||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
|
||||
namespace Monitoring\Form\Config\Instance;
|
||||
|
||||
use \Icinga\Web\Form;
|
||||
use \Zend_Config;
|
||||
|
||||
/**
|
||||
* Form for creating new instances
|
||||
*
|
||||
* @see EditInstanceFor,
|
||||
*/
|
||||
class CreateInstanceForm extends EditInstanceForm
|
||||
{
|
||||
|
||||
/**
|
||||
* Create the form elements
|
||||
*
|
||||
* @see EditInstanceForm::create()
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->setInstanceConfiguration(new Zend_Config(array()));
|
||||
$this->addElement(
|
||||
'text',
|
||||
'instance_name',
|
||||
array(
|
||||
'label' => 'Instance Name',
|
||||
'helptext' => 'Please enter the name for the instance to create'
|
||||
)
|
||||
);
|
||||
parent::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the instance to be created
|
||||
*
|
||||
* @return string The name of the instance as entered in the form
|
||||
*/
|
||||
public function getInstanceName()
|
||||
{
|
||||
return $this->getValue('instance_name');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga 2 Web.
|
||||
*
|
||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
|
||||
namespace Monitoring\Form\Config\Instance;
|
||||
|
||||
use \Icinga\Web\Form;
|
||||
use \Icinga\Web\Form\Element\Note;
|
||||
use \Zend_Config;
|
||||
|
||||
/**
|
||||
* Form for editing existing instances
|
||||
*
|
||||
*/
|
||||
class EditInstanceForm extends Form
|
||||
{
|
||||
/**
|
||||
* The instance to edit
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $instance;
|
||||
|
||||
/**
|
||||
* The type of the instance
|
||||
*
|
||||
* 'local' when no host is given, otherwise 'remote'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $instanceType = 'local';
|
||||
|
||||
/**
|
||||
* Set instance configuration to be used for initial form population
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
*/
|
||||
public function setInstanceConfiguration($config)
|
||||
{
|
||||
$this->instance = $config;
|
||||
if (isset($this->instance->host)) {
|
||||
$this->instanceType = 'remote';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a form field for selecting the command pipe type (local or remote)
|
||||
*
|
||||
*/
|
||||
private function addTypeSelection()
|
||||
{
|
||||
$this->addElement(
|
||||
'select',
|
||||
'instance_type',
|
||||
array(
|
||||
'value' => $this->instanceType,
|
||||
'multiOptions' => array(
|
||||
'local' => 'Local Command Pipe',
|
||||
'remote' => 'Remote Command Pipe'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->enableAutoSubmit(array('instance_type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add form elements for remote instance
|
||||
*
|
||||
*/
|
||||
private function addRemoteInstanceForm()
|
||||
{
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'note_ssh_info',
|
||||
'value' => 'When configuring a remote host, you need to setup passwordless key authentication'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'instance_remote_host',
|
||||
array(
|
||||
'label' => 'Remote Host',
|
||||
'required' => true,
|
||||
'value' => $this->instance->host,
|
||||
'helptext' => 'Enter the hostname or address of the machine on which the icinga instance is running'
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'instance_remote_port',
|
||||
array(
|
||||
'label' => 'Remote SSH Port',
|
||||
'required' => true,
|
||||
'value' => $this->instance->get('port', 22),
|
||||
'helptext' => 'Enter the ssh port to use for connecting to the remote icigna instance'
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'instance_remote_user',
|
||||
array(
|
||||
'label' => 'Remote SSH User',
|
||||
'value' => $this->instance->user,
|
||||
'helptext' => 'Enter the username to use for connecting '
|
||||
. 'to the remote machine or leave blank for default'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this form
|
||||
*
|
||||
* @see Icinga\Web\Form::create
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->addTypeSelection();
|
||||
if ($this->getRequest()->getParam('instance_type', $this->instanceType) === 'remote') {
|
||||
$this->addRemoteInstanceForm();
|
||||
}
|
||||
$this->addElement(
|
||||
'text',
|
||||
'instance_path',
|
||||
array(
|
||||
'label' => 'Remote Pipe Filepath',
|
||||
'required' => true,
|
||||
'value' => $this->instance->get('path', '/usr/local/icinga/var/rw/icinga.cmd'),
|
||||
'helptext' => 'The file path where the icinga commandpipe can be found'
|
||||
)
|
||||
);
|
||||
$this->setSubmitLabel('Save');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configuration set by this form
|
||||
*
|
||||
* @return Zend_Config The configuration set in this form
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$values = $this->getValues();
|
||||
$config = array(
|
||||
'path' => $values['instance_path']
|
||||
);
|
||||
if ($values['instance_type'] === 'remote') {
|
||||
$config['host'] = $values['instance_remote_host'];
|
||||
$config['port'] = $values['instance_remote_port'];
|
||||
if (isset($values['instance_remote_user']) && $values['instance_remote_user'] != '') {
|
||||
$config['user'] = $values['instance_remote_user'];
|
||||
}
|
||||
}
|
||||
return new Zend_Config($config);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?= $this->tabs->render($this); ?>
|
||||
<?php if ($this->name): ?>
|
||||
<h4>Edit backend <?= $this->escape($this->name) ?></h4>
|
||||
<?php else: ?>
|
||||
<h4>Create new backend</h4>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($this->error): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?= $this->escape($this->error); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?= $this->form; ?>
|
|
@ -0,0 +1,15 @@
|
|||
<?= $this->tabs->render($this); ?>
|
||||
|
||||
<?php if (isset($this->name)): ?>
|
||||
<h4>Edit instance configuration for <?= $this->escape($this->name) ?></h4>
|
||||
<?php else: ?>
|
||||
<h4>Configure new icinga instance</h4>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($this->error): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?= $this->escape($this->error); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?= $this->form; ?>
|
|
@ -0,0 +1,51 @@
|
|||
<?php use Icinga\Web\Url; ?>
|
||||
<?= $this->tabs->render($this); ?>
|
||||
|
||||
<h3>Backends</h3>
|
||||
|
||||
<div>
|
||||
<a href="<?= Url::fromPath('/monitoring/config/createbackend')->getAbsoluteUrl();?>">Create new backend</a>
|
||||
</div>
|
||||
<br/>
|
||||
|
||||
<?php foreach ($this->backends as $backendName => $config): ?>
|
||||
<div>
|
||||
<?php $removeUrl = Url::fromPath('/monitoring/config/removebackend', array('backend' => $backendName)); ?>
|
||||
<?php $editUrl = Url::fromPath('/monitoring/config/editbackend', array('backend' => $backendName)); ?>
|
||||
<b><?= $this->escape($backendName); ?></b>
|
||||
<small>(Type: <?= $this->escape($config["type"]); ?>)</small>
|
||||
<?php if ($config['disabled']): ?>
|
||||
- <b>Disabled</b>
|
||||
<?php endif; ?>
|
||||
<div>
|
||||
<a href="<?= $removeUrl; ?>">Remove this backend</a><br/>
|
||||
<a href="<?= $editUrl; ?>">Edit this backend</a>
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<br/>
|
||||
|
||||
<h3>Montoring instances</h3>
|
||||
|
||||
<div>
|
||||
<a href="<?= Url::fromPath('/monitoring/config/createinstance')->getAbsoluteUrl();?>">Create new instance </a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<?php foreach ($this->instances as $instanceName => $config): ?>
|
||||
<?php $removeUrl = Url::fromPath('/monitoring/config/removeinstance', array('instance' => $instanceName)); ?>
|
||||
<?php $editUrl = Url::fromPath('/monitoring/config/editinstance', array('instance' => $instanceName)); ?>
|
||||
<div>
|
||||
<b><?= $this->escape($instanceName); ?></b>
|
||||
<small>(Type: <?= isset($config["host"]) ? 'Remote' : 'Local'; ?>)</small>
|
||||
|
||||
<div>
|
||||
<a href="<?= $removeUrl; ?>">Remove this instance</a><br/>
|
||||
<a href="<?= $editUrl; ?>">Edit this instance</a>
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<?php endforeach; ?>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?= $this->tabs->render($this); ?>
|
||||
<h4>Remove backend <?= $this->escape($this->name) ?></h4>
|
||||
|
||||
<p>
|
||||
Are you sure you want to remove the backend <?= $this->escape($this->name) ?>?
|
||||
</p>
|
||||
|
||||
<?= $this->form; ?>
|
|
@ -0,0 +1,13 @@
|
|||
<?= $this->tabs->render($this); ?>
|
||||
<h4>Remove instance <?= $this->escape($this->name) ?></h4>
|
||||
|
||||
<p>
|
||||
Are you sure you want to remove the instance <?= $this->escape($this->name) ?>?
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you have still any environments or views refering to this instance, you won't be able to send commands anymore
|
||||
after deletion.
|
||||
</p>
|
||||
|
||||
<?= $this->form; ?>
|
|
@ -0,0 +1,30 @@
|
|||
<?= $this->tabs->render($this); ?>
|
||||
<br/>
|
||||
<div class="alert alert-error">
|
||||
<h4><i class="icon-warning-sign"> </i>Saving <?= $this->escape($this->file); ?>failed</h4>
|
||||
<br/>
|
||||
<p>
|
||||
Your <?= $this->escape($this->file); ?> configuration couldn't be stored (error: "<?= $this->exceptionMessage; ?>").<br/>
|
||||
This could have one or more of the following reasons:
|
||||
</p>
|
||||
<ul>
|
||||
<li>You don't have file-system permissions to write to the <?= $this->escape($this->file); ?> file</li>
|
||||
<li>Something went wrong while writing the file</li>
|
||||
<li>There's an application error preventing you from persisting the configuration</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Details can be seen in your application log (if you don't have access to this file, call your administrator in this case).
|
||||
<br/>
|
||||
In case you can access the configuration file (config/<?= $this->escape($this->file); ?>) by yourself, you can open it and
|
||||
insert the config manually:
|
||||
|
||||
</p>
|
||||
<p>
|
||||
<pre>
|
||||
<code>
|
||||
<?= $this->escape($this->iniConfigurationString); ?>
|
||||
</code>
|
||||
</pre>
|
||||
</p>
|
|
@ -99,9 +99,12 @@ class Backend
|
|||
public static function getBackendConfigs()
|
||||
{
|
||||
if (self::$backendConfigs === null) {
|
||||
$resources = IcingaConfig::app('resources');
|
||||
foreach ($resources as $resource) {
|
||||
|
||||
}
|
||||
$backends = IcingaConfig::module('monitoring', 'backends');
|
||||
foreach ($backends as $name => $config) {
|
||||
// TODO: Check if access to this backend is allowed
|
||||
self::$backendConfigs[$name] = $config;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue