mirror of
				https://github.com/Icinga/icingaweb2.git
				synced 2025-11-04 05:05:01 +01:00 
			
		
		
		
	monitoring: It's now a command transport, not an instance anymore
refs #9651
This commit is contained in:
		
							parent
							
								
									6651d31481
								
							
						
					
					
						commit
						ec8567cbbf
					
				@ -16,12 +16,12 @@ use Icinga\Module\Monitoring\Forms\Config\SecurityConfigForm;
 | 
				
			|||||||
class Monitoring_ConfigController extends Controller
 | 
					class Monitoring_ConfigController extends Controller
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Display a list of available backends and instances
 | 
					     * Display a list of available backends and command transports
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function indexAction()
 | 
					    public function indexAction()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->view->backendsConfig = $this->Config('backends');
 | 
					        $this->view->backendsConfig = $this->Config('backends');
 | 
				
			||||||
        $this->view->instancesConfig = $this->Config('instances');
 | 
					        $this->view->transportConfig = $this->Config('commandtransports');
 | 
				
			||||||
        $this->view->tabs = $this->Module()->getConfigTabs()->activate('backends');
 | 
					        $this->view->tabs = $this->Module()->getConfigTabs()->activate('backends');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -145,31 +145,34 @@ class Monitoring_ConfigController extends Controller
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Remove a monitoring instance
 | 
					     * Remove a command transport
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function removeinstanceAction()
 | 
					    public function removetransportAction()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $instanceName = $this->params->getRequired('instance');
 | 
					        $transportName = $this->params->getRequired('transport');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $instanceForm = new InstanceConfigForm();
 | 
					        $transportForm = new InstanceConfigForm();
 | 
				
			||||||
        $instanceForm->setIniConfig($this->Config('instances'));
 | 
					        $transportForm->setIniConfig($this->Config('commandtransports'));
 | 
				
			||||||
        $form = new ConfirmRemovalForm();
 | 
					        $form = new ConfirmRemovalForm();
 | 
				
			||||||
        $form->setRedirectUrl('monitoring/config');
 | 
					        $form->setRedirectUrl('monitoring/config');
 | 
				
			||||||
        $form->setTitle(sprintf($this->translate('Remove Monitoring Instance %s'), $instanceName));
 | 
					        $form->setTitle(sprintf($this->translate('Remove Command Transport %s'), $transportName));
 | 
				
			||||||
        $form->addDescription($this->translate(
 | 
					        $form->info(
 | 
				
			||||||
            'If you have still any environments or views referring to this instance, '
 | 
					            $this->translate(
 | 
				
			||||||
            . 'you won\'t be able to send commands anymore after deletion.'
 | 
					                'If you have still any environments or views referring to this transport, '
 | 
				
			||||||
        ));
 | 
					                . 'you won\'t be able to send commands anymore after deletion.'
 | 
				
			||||||
        $form->setOnSuccess(function (ConfirmRemovalForm $form) use ($instanceName, $instanceForm) {
 | 
					            ),
 | 
				
			||||||
 | 
					            false
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        $form->setOnSuccess(function (ConfirmRemovalForm $form) use ($transportName, $transportForm) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                $instanceForm->delete($instanceName);
 | 
					                $transportForm->delete($transportName);
 | 
				
			||||||
            } catch (Exception $e) {
 | 
					            } catch (Exception $e) {
 | 
				
			||||||
                $form->error($e->getMessage());
 | 
					                $form->error($e->getMessage());
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ($instanceForm->save()) {
 | 
					            if ($transportForm->save()) {
 | 
				
			||||||
                Notification::success(sprintf(t('Monitoring instance "%s" successfully removed'), $instanceName));
 | 
					                Notification::success(sprintf(t('Command transport "%s" successfully removed'), $transportName));
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -182,19 +185,19 @@ class Monitoring_ConfigController extends Controller
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Edit a monitoring instance
 | 
					     * Edit a command transport
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function editinstanceAction()
 | 
					    public function edittransportAction()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $instanceName = $this->params->getRequired('instance');
 | 
					        $transportName = $this->params->getRequired('transport');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $form = new InstanceConfigForm();
 | 
					        $form = new InstanceConfigForm();
 | 
				
			||||||
        $form->setRedirectUrl('monitoring/config');
 | 
					        $form->setRedirectUrl('monitoring/config');
 | 
				
			||||||
        $form->setTitle(sprintf($this->translate('Edit Monitoring Instance %s'), $instanceName));
 | 
					        $form->setTitle(sprintf($this->translate('Edit Command Transport %s'), $transportName));
 | 
				
			||||||
        $form->setIniConfig($this->Config('instances'));
 | 
					        $form->setIniConfig($this->Config('commandtransports'));
 | 
				
			||||||
        $form->setOnSuccess(function (InstanceConfigForm $form) use ($instanceName) {
 | 
					        $form->setOnSuccess(function (InstanceConfigForm $form) use ($transportName) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                $form->edit($instanceName, array_map(
 | 
					                $form->edit($transportName, array_map(
 | 
				
			||||||
                    function ($v) {
 | 
					                    function ($v) {
 | 
				
			||||||
                        return $v !== '' ? $v : null;
 | 
					                        return $v !== '' ? $v : null;
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
@ -206,7 +209,7 @@ class Monitoring_ConfigController extends Controller
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ($form->save()) {
 | 
					            if ($form->save()) {
 | 
				
			||||||
                Notification::success(sprintf(t('Monitoring instance "%s" successfully updated'), $instanceName));
 | 
					                Notification::success(sprintf(t('Command transport "%s" successfully updated'), $transportName));
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -214,10 +217,10 @@ class Monitoring_ConfigController extends Controller
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            $form->load($instanceName);
 | 
					            $form->load($transportName);
 | 
				
			||||||
            $form->handleRequest();
 | 
					            $form->handleRequest();
 | 
				
			||||||
        } catch (NotFoundError $_) {
 | 
					        } catch (NotFoundError $_) {
 | 
				
			||||||
            $this->httpNotFound(sprintf($this->translate('Monitoring instance "%s" not found'), $instanceName));
 | 
					            $this->httpNotFound(sprintf($this->translate('Command transport "%s" not found'), $transportName));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->view->form = $form;
 | 
					        $this->view->form = $form;
 | 
				
			||||||
@ -225,14 +228,14 @@ class Monitoring_ConfigController extends Controller
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Create a new monitoring instance
 | 
					     * Create a new command transport
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function createinstanceAction()
 | 
					    public function createtransportAction()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $form = new InstanceConfigForm();
 | 
					        $form = new InstanceConfigForm();
 | 
				
			||||||
        $form->setRedirectUrl('monitoring/config');
 | 
					        $form->setRedirectUrl('monitoring/config');
 | 
				
			||||||
        $form->setTitle($this->translate('Create New Monitoring Instance'));
 | 
					        $form->setTitle($this->translate('Create New Command Transport'));
 | 
				
			||||||
        $form->setIniConfig($this->Config('instances'));
 | 
					        $form->setIniConfig($this->Config('commandtransports'));
 | 
				
			||||||
        $form->setOnSuccess(function (InstanceConfigForm $form) {
 | 
					        $form->setOnSuccess(function (InstanceConfigForm $form) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                $form->add(array_filter($form->getValues()));
 | 
					                $form->add(array_filter($form->getValues()));
 | 
				
			||||||
@ -242,7 +245,7 @@ class Monitoring_ConfigController extends Controller
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ($form->save()) {
 | 
					            if ($form->save()) {
 | 
				
			||||||
                Notification::success(t('Monitoring instance successfully created'));
 | 
					                Notification::success(t('Command transport successfully created'));
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -52,9 +52,9 @@ abstract class CommandForm extends Form
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getTransport(Request $request)
 | 
					    public function getTransport(Request $request)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $instance = $request->getParam('instance');
 | 
					        $transportName = $request->getParam('transport');
 | 
				
			||||||
        if ($instance !== null) {
 | 
					        if ($transportName !== null) {
 | 
				
			||||||
            $transport = CommandTransport::create($instance);
 | 
					            $transport = CommandTransport::create($transportName);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            $transport = CommandTransport::first();
 | 
					            $transport = CommandTransport::first();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ class LocalInstanceForm extends Form
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function init()
 | 
					    public function init()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->setName('form_config_monitoring_instance_local');
 | 
					        $this->setName('form_config_command_transport_local');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -10,7 +10,7 @@ use Icinga\Web\Form;
 | 
				
			|||||||
class RemoteInstanceForm extends Form
 | 
					class RemoteInstanceForm extends Form
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The available monitoring instance resources split by type
 | 
					     * The available resources split by type
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @var array
 | 
					     * @var array
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
@ -22,7 +22,7 @@ class RemoteInstanceForm extends Form
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function init()
 | 
					    public function init()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->setName('form_config_monitoring_instance_remote');
 | 
					        $this->setName('form_config_command_transport_remote');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -44,7 +44,7 @@ class RemoteInstanceForm extends Form
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (empty($resources)) {
 | 
					        if (empty($resources)) {
 | 
				
			||||||
            throw new ConfigurationError($this->translate('Could not find any valid monitoring instance resources'));
 | 
					            throw new ConfigurationError($this->translate('Could not find any valid SSH resources'));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->resources = $resources;
 | 
					        $this->resources = $resources;
 | 
				
			||||||
 | 
				
			|||||||
@ -13,36 +13,36 @@ use Icinga\Module\Monitoring\Forms\Config\Instance\LocalInstanceForm;
 | 
				
			|||||||
use Icinga\Module\Monitoring\Forms\Config\Instance\RemoteInstanceForm;
 | 
					use Icinga\Module\Monitoring\Forms\Config\Instance\RemoteInstanceForm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Form for managing monitoring instances
 | 
					 * Form for managing command transports
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class InstanceConfigForm extends ConfigForm
 | 
					class InstanceConfigForm extends ConfigForm
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The instance to load when displaying the form for the first time
 | 
					     * The transport to load when displaying the form for the first time
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @var string
 | 
					     * @var string
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected $instanceToLoad;
 | 
					    protected $transportToLoad;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Initialize this form
 | 
					     * Initialize this form
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function init()
 | 
					    public function init()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->setName('form_config_monitoring_instance');
 | 
					        $this->setName('form_config_command_transports');
 | 
				
			||||||
        $this->setSubmitLabel($this->translate('Save Changes'));
 | 
					        $this->setSubmitLabel($this->translate('Save Changes'));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Return a form object for the given instance type
 | 
					     * Return a form object for the given transport type
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param   string  $type               The instance type for which to return a form
 | 
					     * @param   string  $type               The transport type for which to return a form
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return  Form
 | 
					     * @return  Form
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @throws  InvalidArgumentException    In case the given instance type is invalid
 | 
					     * @throws  InvalidArgumentException    In case the given transport type is invalid
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getInstanceForm($type)
 | 
					    public function getTransportForm($type)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        switch (strtolower($type)) {
 | 
					        switch (strtolower($type)) {
 | 
				
			||||||
            case LocalCommandFile::TRANSPORT:
 | 
					            case LocalCommandFile::TRANSPORT:
 | 
				
			||||||
@ -51,41 +51,41 @@ class InstanceConfigForm extends ConfigForm
 | 
				
			|||||||
                return new RemoteInstanceForm();
 | 
					                return new RemoteInstanceForm();
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                throw new InvalidArgumentException(
 | 
					                throw new InvalidArgumentException(
 | 
				
			||||||
                    sprintf($this->translate('Invalid monitoring instance type "%s" given'), $type)
 | 
					                    sprintf($this->translate('Invalid command transport type "%s" given'), $type)
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Populate the form with the given instance's config
 | 
					     * Populate the form with the given transport's config
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param   string  $name
 | 
					     * @param   string  $name
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return  $this
 | 
					     * @return  $this
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @throws  NotFoundError   In case no instance with the given name is found
 | 
					     * @throws  NotFoundError   In case no transport with the given name is found
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function load($name)
 | 
					    public function load($name)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (! $this->config->hasSection($name)) {
 | 
					        if (! $this->config->hasSection($name)) {
 | 
				
			||||||
            throw new NotFoundError('No monitoring instance called "%s" found', $name);
 | 
					            throw new NotFoundError('No command transport called "%s" found', $name);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->instanceToLoad = $name;
 | 
					        $this->transportToLoad = $name;
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Add a new instance
 | 
					     * Add a new command transport
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * The instance to add is identified by the array-key `name'.
 | 
					     * The transport to add is identified by the array-key `name'.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param   array   $data
 | 
					     * @param   array   $data
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return  $this
 | 
					     * @return  $this
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @throws  InvalidArgumentException    In case $data does not contain a instance name
 | 
					     * @throws  InvalidArgumentException    In case $data does not contain a transport name
 | 
				
			||||||
     * @throws  IcingaException             In case a instance with the same name already exists
 | 
					     * @throws  IcingaException             In case a transport with the same name already exists
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function add(array $data)
 | 
					    public function add(array $data)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -93,36 +93,36 @@ class InstanceConfigForm extends ConfigForm
 | 
				
			|||||||
            throw new InvalidArgumentException('Key \'name\' missing');
 | 
					            throw new InvalidArgumentException('Key \'name\' missing');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $instanceName = $data['name'];
 | 
					        $transportName = $data['name'];
 | 
				
			||||||
        if ($this->config->hasSection($instanceName)) {
 | 
					        if ($this->config->hasSection($transportName)) {
 | 
				
			||||||
            throw new IcingaException(
 | 
					            throw new IcingaException(
 | 
				
			||||||
                $this->translate('A monitoring instance with the name "%s" does already exist'),
 | 
					                $this->translate('A command transport with the name "%s" does already exist'),
 | 
				
			||||||
                $instanceName
 | 
					                $transportName
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        unset($data['name']);
 | 
					        unset($data['name']);
 | 
				
			||||||
        $this->config->setSection($instanceName, $data);
 | 
					        $this->config->setSection($transportName, $data);
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Edit an existing instance
 | 
					     * Edit an existing command transport
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param   string  $name
 | 
					     * @param   string  $name
 | 
				
			||||||
     * @param   array   $data
 | 
					     * @param   array   $data
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return  $this
 | 
					     * @return  $this
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @throws  NotFoundError   In case no instance with the given name is found
 | 
					     * @throws  NotFoundError   In case no transport with the given name is found
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function edit($name, array $data)
 | 
					    public function edit($name, array $data)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (! $this->config->hasSection($name)) {
 | 
					        if (! $this->config->hasSection($name)) {
 | 
				
			||||||
            throw new NotFoundError('No monitoring instance called "%s" found', $name);
 | 
					            throw new NotFoundError('No command transport called "%s" found', $name);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $instanceConfig = $this->config->getSection($name);
 | 
					        $transportConfig = $this->config->getSection($name);
 | 
				
			||||||
        if (isset($data['name'])) {
 | 
					        if (isset($data['name'])) {
 | 
				
			||||||
            if ($data['name'] !== $name) {
 | 
					            if ($data['name'] !== $name) {
 | 
				
			||||||
                $this->config->removeSection($name);
 | 
					                $this->config->removeSection($name);
 | 
				
			||||||
@ -132,19 +132,19 @@ class InstanceConfigForm extends ConfigForm
 | 
				
			|||||||
            unset($data['name']);
 | 
					            unset($data['name']);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $instanceConfig->merge($data);
 | 
					        $transportConfig->merge($data);
 | 
				
			||||||
        foreach ($instanceConfig->toArray() as $k => $v) {
 | 
					        foreach ($transportConfig->toArray() as $k => $v) {
 | 
				
			||||||
            if ($v === null) {
 | 
					            if ($v === null) {
 | 
				
			||||||
                unset($instanceConfig->$k);
 | 
					                unset($transportConfig->$k);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->config->setSection($name, $instanceConfig);
 | 
					        $this->config->setSection($name, $transportConfig);
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Remove a instance
 | 
					     * Remove a command transport
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param   string  $name
 | 
					     * @param   string  $name
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -168,9 +168,9 @@ class InstanceConfigForm extends ConfigForm
 | 
				
			|||||||
            'name',
 | 
					            'name',
 | 
				
			||||||
            array(
 | 
					            array(
 | 
				
			||||||
                'required'      => true,
 | 
					                'required'      => true,
 | 
				
			||||||
                'label'         => $this->translate('Instance Name'),
 | 
					                'label'         => $this->translate('Transport Name'),
 | 
				
			||||||
                'description'   => $this->translate(
 | 
					                'description'   => $this->translate(
 | 
				
			||||||
                    'The name of this monitoring instance that is used to differentiate it from others'
 | 
					                    'The name of this command transport that is used to differentiate it from others'
 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
                'validators'    => array(
 | 
					                'validators'    => array(
 | 
				
			||||||
                    array(
 | 
					                    array(
 | 
				
			||||||
@ -189,14 +189,14 @@ class InstanceConfigForm extends ConfigForm
 | 
				
			|||||||
            )
 | 
					            )
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $instanceTypes = array(
 | 
					        $transportTypes = array(
 | 
				
			||||||
            LocalCommandFile::TRANSPORT     => $this->translate('Local Command File'),
 | 
					            LocalCommandFile::TRANSPORT     => $this->translate('Local Command File'),
 | 
				
			||||||
            RemoteCommandFile::TRANSPORT    => $this->translate('Remote Command File')
 | 
					            RemoteCommandFile::TRANSPORT    => $this->translate('Remote Command File')
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $instanceType = isset($formData['transport']) ? $formData['transport'] : null;
 | 
					        $transportType = isset($formData['transport']) ? $formData['transport'] : null;
 | 
				
			||||||
        if ($instanceType === null) {
 | 
					        if ($transportType === null) {
 | 
				
			||||||
            $instanceType = key($instanceTypes);
 | 
					            $transportType = key($transportTypes);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->addElements(array(
 | 
					        $this->addElements(array(
 | 
				
			||||||
@ -206,24 +206,23 @@ class InstanceConfigForm extends ConfigForm
 | 
				
			|||||||
                array(
 | 
					                array(
 | 
				
			||||||
                    'required'      => true,
 | 
					                    'required'      => true,
 | 
				
			||||||
                    'autosubmit'    => true,
 | 
					                    'autosubmit'    => true,
 | 
				
			||||||
                    'label'         => $this->translate('Instance Type'),
 | 
					                    'label'         => $this->translate('Transport Type'),
 | 
				
			||||||
                    'description'   => $this->translate('The type of transport to use for this monitoring instance'),
 | 
					                    'multiOptions'  => $transportTypes
 | 
				
			||||||
                    'multiOptions'  => $instanceTypes
 | 
					 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        ));
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->addSubForm($this->getInstanceForm($instanceType)->create($formData), 'instance_form');
 | 
					        $this->addSubForm($this->getTransportForm($transportType)->create($formData), 'transport_form');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Populate the configuration of the instance to load
 | 
					     * Populate the configuration of the transport to load
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function onRequest()
 | 
					    public function onRequest()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if ($this->instanceToLoad) {
 | 
					        if ($this->transportToLoad) {
 | 
				
			||||||
            $data = $this->config->getSection($this->instanceToLoad)->toArray();
 | 
					            $data = $this->config->getSection($this->transportToLoad)->toArray();
 | 
				
			||||||
            $data['name'] = $this->instanceToLoad;
 | 
					            $data['name'] = $this->transportToLoad;
 | 
				
			||||||
            $this->populate($data);
 | 
					            $this->populate($data);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -238,8 +237,8 @@ class InstanceConfigForm extends ConfigForm
 | 
				
			|||||||
    public function getValues($suppressArrayNotation = false)
 | 
					    public function getValues($suppressArrayNotation = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $values = parent::getValues();
 | 
					        $values = parent::getValues();
 | 
				
			||||||
        $values = array_merge($values, $values['instance_form']);
 | 
					        $values = array_merge($values, $values['transport_form']);
 | 
				
			||||||
        unset($values['instance_form']);
 | 
					        unset($values['transport_form']);
 | 
				
			||||||
        return $values;
 | 
					        return $values;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -10,23 +10,23 @@ class InstancePage extends Form
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public function init()
 | 
					    public function init()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->setName('setup_monitoring_instance');
 | 
					        $this->setName('setup_command_transport');
 | 
				
			||||||
        $this->setTitle($this->translate('Monitoring Instance', 'setup.page.title'));
 | 
					        $this->setTitle($this->translate('Command Transport', 'setup.page.title'));
 | 
				
			||||||
        $this->addDescription($this->translate(
 | 
					        $this->addDescription($this->translate(
 | 
				
			||||||
            'Please define the settings specific to your monitoring instance below.'
 | 
					            'Please define below how you want to send commands to your monitoring instance.'
 | 
				
			||||||
        ));
 | 
					        ));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function createElements(array $formData)
 | 
					    public function createElements(array $formData)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $instanceConfigForm = new InstanceConfigForm();
 | 
					        $transportConfigForm = new InstanceConfigForm();
 | 
				
			||||||
        $this->addSubForm($instanceConfigForm, 'instance_form');
 | 
					        $this->addSubForm($transportConfigForm, 'transport_form');
 | 
				
			||||||
        $instanceConfigForm->create($formData);
 | 
					        $transportConfigForm->create($formData);
 | 
				
			||||||
        $instanceConfigForm->getElement('name')->setValue('icinga');
 | 
					        $transportConfigForm->getElement('name')->setValue('icinga2');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getValues($suppressArrayNotation = false)
 | 
					    public function getValues($suppressArrayNotation = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->getSubForm('instance_form')->getValues($suppressArrayNotation);
 | 
					        return $this->getSubForm('transport_form')->getValues($suppressArrayNotation);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -47,28 +47,28 @@
 | 
				
			|||||||
    <?php endforeach; ?>
 | 
					    <?php endforeach; ?>
 | 
				
			||||||
    </tbody>
 | 
					    </tbody>
 | 
				
			||||||
  </table>
 | 
					  </table>
 | 
				
			||||||
  <h1><?= $this->translate('Monitoring Instances') ?></h1>
 | 
					  <h1><?= $this->translate('Command Transports') ?></h1>
 | 
				
			||||||
  <p>
 | 
					  <p>
 | 
				
			||||||
    <a href="<?= $this->href('/monitoring/config/createinstance'); ?>">
 | 
					    <a href="<?= $this->href('/monitoring/config/createtransport'); ?>">
 | 
				
			||||||
      <?= $this->icon('plus'); ?> <?= $this->translate('Create New Instance'); ?>
 | 
					      <?= $this->icon('plus'); ?> <?= $this->translate('Create New Transport'); ?>
 | 
				
			||||||
    </a>
 | 
					    </a>
 | 
				
			||||||
  </p>
 | 
					  </p>
 | 
				
			||||||
  <table class="action alternating">
 | 
					  <table class="action alternating">
 | 
				
			||||||
    <thead>
 | 
					    <thead>
 | 
				
			||||||
      <th><?= $this->translate('Instance'); ?></th>
 | 
					      <th><?= $this->translate('Transport'); ?></th>
 | 
				
			||||||
      <th style="width: 5em"><?= $this->translate('Remove'); ?></th>
 | 
					      <th style="width: 5em"><?= $this->translate('Remove'); ?></th>
 | 
				
			||||||
    </thead>
 | 
					    </thead>
 | 
				
			||||||
    <tbody>
 | 
					    <tbody>
 | 
				
			||||||
    <?php foreach ($this->instancesConfig as $instanceName => $config): ?>
 | 
					    <?php foreach ($this->transportConfig as $transportName => $config): ?>
 | 
				
			||||||
      <tr>
 | 
					      <tr>
 | 
				
			||||||
        <td>
 | 
					        <td>
 | 
				
			||||||
          <?= $this->qlink(
 | 
					          <?= $this->qlink(
 | 
				
			||||||
            $instanceName,
 | 
					            $transportName,
 | 
				
			||||||
            '/monitoring/config/editinstance',
 | 
					            '/monitoring/config/edittransport',
 | 
				
			||||||
            array('instance' => $instanceName),
 | 
					            array('transport' => $transportName),
 | 
				
			||||||
            array(
 | 
					            array(
 | 
				
			||||||
                'icon'  => 'edit',
 | 
					                'icon'  => 'edit',
 | 
				
			||||||
                'title' => sprintf($this->translate('Edit monitoring instance %s'), $instanceName)
 | 
					                'title' => sprintf($this->translate('Edit command transport %s'), $transportName)
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
          ); ?>
 | 
					          ); ?>
 | 
				
			||||||
          <small>(<?= sprintf(
 | 
					          <small>(<?= sprintf(
 | 
				
			||||||
@ -79,11 +79,11 @@
 | 
				
			|||||||
        <td>
 | 
					        <td>
 | 
				
			||||||
          <?= $this->qlink(
 | 
					          <?= $this->qlink(
 | 
				
			||||||
            '',
 | 
					            '',
 | 
				
			||||||
            '/monitoring/config/removeinstance',
 | 
					            '/monitoring/config/removetransport',
 | 
				
			||||||
            array('instance' => $instanceName),
 | 
					            array('transport' => $transportName),
 | 
				
			||||||
            array(
 | 
					            array(
 | 
				
			||||||
                'icon'  => 'trash',
 | 
					                'icon'  => 'trash',
 | 
				
			||||||
                'title' => sprintf($this->translate('Remove monitoring instance %s'), $instanceName)
 | 
					                'title' => sprintf($this->translate('Remove command transport %s'), $transportName)
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
          ); ?>
 | 
					          ); ?>
 | 
				
			||||||
        </td>
 | 
					        </td>
 | 
				
			||||||
 | 
				
			|||||||
@ -21,13 +21,13 @@ class InstanceStep extends Step
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function apply()
 | 
					    public function apply()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $instanceConfig = $this->data['instanceConfig'];
 | 
					        $transportConfig = $this->data['transportConfig'];
 | 
				
			||||||
        $instanceName = $instanceConfig['name'];
 | 
					        $transportName = $transportConfig['name'];
 | 
				
			||||||
        unset($instanceConfig['name']);
 | 
					        unset($transportConfig['name']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            Config::fromArray(array($instanceName => $instanceConfig))
 | 
					            Config::fromArray(array($transportName => $transportConfig))
 | 
				
			||||||
                ->setConfigFile(Config::resolvePath('modules/monitoring/instances.ini'))
 | 
					                ->setConfigFile(Config::resolvePath('modules/monitoring/commandtransports.ini'))
 | 
				
			||||||
                ->saveIni();
 | 
					                ->saveIni();
 | 
				
			||||||
        } catch (Exception $e) {
 | 
					        } catch (Exception $e) {
 | 
				
			||||||
            $this->error = $e;
 | 
					            $this->error = $e;
 | 
				
			||||||
@ -40,16 +40,16 @@ class InstanceStep extends Step
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function getSummary()
 | 
					    public function getSummary()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $pageTitle = '<h2>' . mt('monitoring', 'Monitoring Instance', 'setup.page.title') . '</h2>';
 | 
					        $pageTitle = '<h2>' . mt('monitoring', 'Command Transport', 'setup.page.title') . '</h2>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isset($this->data['instanceConfig']['host'])) {
 | 
					        if (isset($this->data['transportConfig']['host'])) {
 | 
				
			||||||
            $pipeHtml = '<p>' . sprintf(
 | 
					            $pipeHtml = '<p>' . sprintf(
 | 
				
			||||||
                mt(
 | 
					                mt(
 | 
				
			||||||
                    'monitoring',
 | 
					                    'monitoring',
 | 
				
			||||||
                    'Icinga Web 2 will use the named pipe located on a remote machine at "%s" to send commands'
 | 
					                    'Icinga Web 2 will use the named pipe located on a remote machine at "%s" to send commands'
 | 
				
			||||||
                    . ' to your monitoring instance by using the connection details listed below:'
 | 
					                    . ' to your monitoring instance by using the connection details listed below:'
 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
                $this->data['instanceConfig']['path']
 | 
					                $this->data['transportConfig']['path']
 | 
				
			||||||
            ) . '</p>';
 | 
					            ) . '</p>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $pipeHtml .= ''
 | 
					            $pipeHtml .= ''
 | 
				
			||||||
@ -57,15 +57,15 @@ class InstanceStep extends Step
 | 
				
			|||||||
                . '<tbody>'
 | 
					                . '<tbody>'
 | 
				
			||||||
                . '<tr>'
 | 
					                . '<tr>'
 | 
				
			||||||
                . '<td><strong>' . mt('monitoring', 'Remote Host') . '</strong></td>'
 | 
					                . '<td><strong>' . mt('monitoring', 'Remote Host') . '</strong></td>'
 | 
				
			||||||
                . '<td>' . $this->data['instanceConfig']['host'] . '</td>'
 | 
					                . '<td>' . $this->data['transportConfig']['host'] . '</td>'
 | 
				
			||||||
                . '</tr>'
 | 
					                . '</tr>'
 | 
				
			||||||
                . '<tr>'
 | 
					                . '<tr>'
 | 
				
			||||||
                . '<td><strong>' . mt('monitoring', 'Remote SSH Port') . '</strong></td>'
 | 
					                . '<td><strong>' . mt('monitoring', 'Remote SSH Port') . '</strong></td>'
 | 
				
			||||||
                . '<td>' . $this->data['instanceConfig']['port'] . '</td>'
 | 
					                . '<td>' . $this->data['transportConfig']['port'] . '</td>'
 | 
				
			||||||
                . '</tr>'
 | 
					                . '</tr>'
 | 
				
			||||||
                . '<tr>'
 | 
					                . '<tr>'
 | 
				
			||||||
                . '<td><strong>' . mt('monitoring', 'Remote SSH User') . '</strong></td>'
 | 
					                . '<td><strong>' . mt('monitoring', 'Remote SSH User') . '</strong></td>'
 | 
				
			||||||
                . '<td>' . $this->data['instanceConfig']['user'] . '</td>'
 | 
					                . '<td>' . $this->data['transportConfig']['user'] . '</td>'
 | 
				
			||||||
                . '</tr>'
 | 
					                . '</tr>'
 | 
				
			||||||
                . '</tbody>'
 | 
					                . '</tbody>'
 | 
				
			||||||
                . '</table>';
 | 
					                . '</table>';
 | 
				
			||||||
@ -76,7 +76,7 @@ class InstanceStep extends Step
 | 
				
			|||||||
                    'Icinga Web 2 will use the named pipe located at "%s"'
 | 
					                    'Icinga Web 2 will use the named pipe located at "%s"'
 | 
				
			||||||
                    . ' to send commands to your monitoring instance.'
 | 
					                    . ' to send commands to your monitoring instance.'
 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
                $this->data['instanceConfig']['path']
 | 
					                $this->data['transportConfig']['path']
 | 
				
			||||||
            ) . '</p>';
 | 
					            ) . '</p>';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -87,17 +87,17 @@ class InstanceStep extends Step
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if ($this->error === false) {
 | 
					        if ($this->error === false) {
 | 
				
			||||||
            return array(sprintf(
 | 
					            return array(sprintf(
 | 
				
			||||||
                mt('monitoring', 'Monitoring instance configuration has been successfully created: %s'),
 | 
					                mt('monitoring', 'Command transport configuration has been successfully created: %s'),
 | 
				
			||||||
                Config::resolvePath('modules/monitoring/instances.ini')
 | 
					                Config::resolvePath('modules/monitoring/commandtransports.ini')
 | 
				
			||||||
            ));
 | 
					            ));
 | 
				
			||||||
        } elseif ($this->error !== null) {
 | 
					        } elseif ($this->error !== null) {
 | 
				
			||||||
            return array(
 | 
					            return array(
 | 
				
			||||||
                sprintf(
 | 
					                sprintf(
 | 
				
			||||||
                    mt(
 | 
					                    mt(
 | 
				
			||||||
                        'monitoring',
 | 
					                        'monitoring',
 | 
				
			||||||
                        'Monitoring instance configuration could not be written to: %s. An error occured:'
 | 
					                        'Command transport configuration could not be written to: %s. An error occured:'
 | 
				
			||||||
                    ),
 | 
					                    ),
 | 
				
			||||||
                    Config::resolvePath('modules/monitoring/instances.ini')
 | 
					                    Config::resolvePath('modules/monitoring/commandtransports.ini')
 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
                sprintf(mt('setup', 'ERROR: %s'), IcingaException::describe($this->error))
 | 
					                sprintf(mt('setup', 'ERROR: %s'), IcingaException::describe($this->error))
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
				
			|||||||
@ -151,7 +151,7 @@ class MonitoringWizard extends Wizard implements SetupWizard
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $setup->addStep(
 | 
					        $setup->addStep(
 | 
				
			||||||
            new InstanceStep(array(
 | 
					            new InstanceStep(array(
 | 
				
			||||||
                'instanceConfig'    => $pageData['setup_monitoring_instance']
 | 
					                'transportConfig'    => $pageData['setup_command_transport']
 | 
				
			||||||
            ))
 | 
					            ))
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user