/** * Create a new monitoring backend */ public function createbackendAction() { $form = new BackendConfigForm(); $form->setRedirectUrl('monitoring/config'); $form->setTitle($this->translate('Create New Monitoring Backend')); $form->setIniConfig($this->Config('backends')); try { $form->setResourceConfig(ResourceFactory::getResourceConfigs()); } catch (ConfigurationError $e) { if ($this->hasPermission('config/application/resources')) { Notification::error($e->getMessage()); $this->redirectNow('config/createresource'); } throw $e; // No permission for resource configuration, show the error } $form->setOnSuccess(function (BackendConfigForm $form) { try { $form->add(array_filter($form->getValues())); } catch (Exception $e) { $form->error($e->getMessage()); return false; } if ($form->save()) { Notification::success(t('Monitoring backend successfully created')); return true; } return false; }); $form->handleRequest(); $this->view->form = $form; $this->render('form'); }
/** * Check whether ssh identity resources exists or not * * @return boolean */ public function hasResources() { $resourceConfig = ResourceFactory::getResourceConfigs(); foreach ($resourceConfig as $name => $resource) { if ($resource->type === 'ssh') { return true; } } return false; }
/** * Return the names of all configured database resources * * @return array */ protected function getDatabaseResourceNames() { $names = array(); foreach (ResourceFactory::getResourceConfigs() as $name => $config) { if (strtolower($config->type) === 'db') { $names[] = $name; } } return $names; }
/** * Display a form to create a new backend */ public function createbackendAction() { $form = new BackendConfigForm(); $form->setTitle($this->translate('Add New Backend')); $form->setIniConfig($this->Config('backends')); $form->setResourceConfig(ResourceFactory::getResourceConfigs()); $form->setRedirectUrl('monitoring/config'); $form->handleRequest(); $this->view->form = $form; }
protected static function enumResources($type) { $resources = array(); foreach (ResourceFactory::getResourceConfigs() as $name => $resource) { if ($resource->type === $type && self::resourceIsAllowed($name)) { $resources[$name] = $name; } } return $resources; }
/** * Load all available ssh identity resources * * @return $this * * @throws \Icinga\Exception\ConfigurationError */ public function loadResources() { $resourceConfig = ResourceFactory::getResourceConfigs(); $resources = array(); foreach ($resourceConfig as $name => $resource) { if ($resource->type === 'ssh') { $resources['ssh'][$name] = $name; } } if (empty($resources)) { throw new ConfigurationError($this->translate('Could not find any valid monitoring instance resources')); } $this->resources = $resources; return $this; }
/** * @see Form::createElements() */ public function createElements(array $formData) { $this->addElement('text', 'global_module_path', array('label' => $this->translate('Module Path'), 'required' => true, 'value' => implode(':', Icinga::app()->getModuleManager()->getModuleDirs()), 'description' => $this->translate('Contains the directories that will be searched for available modules, separated by ' . 'colons. Modules that don\'t exist in these directories can still be symlinked in ' . 'the module folder, but won\'t show up in the list of disabled modules.'))); $this->addElement('select', 'preferences_store', array('required' => true, 'autosubmit' => true, 'label' => $this->translate('User Preference Storage Type'), 'multiOptions' => array('ini' => $this->translate('File System (INI Files)'), 'db' => $this->translate('Database'), 'none' => $this->translate('Don\'t Store Preferences')))); if (isset($formData['preferences_store']) && $formData['preferences_store'] === 'db') { $backends = array(); foreach (ResourceFactory::getResourceConfigs()->toArray() as $name => $resource) { if ($resource['type'] === 'db') { $backends[$name] = $name; } } $this->addElement('select', 'preferences_resource', array('required' => true, 'multiOptions' => $backends, 'label' => $this->translate('Database Connection'))); } return $this; }
/** * @see Form::createElements() */ public function createElements(array $formData) { $this->addElement('checkbox', 'global_show_stacktraces', array('required' => true, 'value' => true, 'label' => $this->translate('Show Stacktraces'), 'description' => $this->translate('Set whether to show an exception\'s stacktrace by default. This can also' . ' be set in a user\'s preferences with the appropriate permission.'))); $this->addElement('text', 'global_module_path', array('label' => $this->translate('Module Path'), 'required' => true, 'value' => implode(':', Icinga::app()->getModuleManager()->getModuleDirs()), 'description' => $this->translate('Contains the directories that will be searched for available modules, separated by ' . 'colons. Modules that don\'t exist in these directories can still be symlinked in ' . 'the module folder, but won\'t show up in the list of disabled modules.'))); $this->addElement('select', 'global_config_backend', array('required' => true, 'autosubmit' => true, 'label' => $this->translate('User Preference Storage Type'), 'multiOptions' => array('ini' => $this->translate('File System (INI Files)'), 'db' => $this->translate('Database'), 'none' => $this->translate('Don\'t Store Preferences')))); if (isset($formData['global_config_backend']) && $formData['global_config_backend'] === 'db') { $backends = array(); foreach (ResourceFactory::getResourceConfigs()->toArray() as $name => $resource) { if ($resource['type'] === 'db') { $backends[$name] = $name; } } $this->addElement('select', 'global_config_resource', array('required' => true, 'multiOptions' => $backends, 'label' => $this->translate('Database Connection'))); } $this->addElement('text', 'datetime_format', array('label' => $this->translate('Datetime format'), 'required' => true, 'value' => $this->translate('Y-m-d H:i:s'), 'description' => $this->translate('Datetime format for use when displaying timestamps in history views. Uses PHP ' . 'date() format, see PHP documentation for syntax.'))); return $this; }
/** * Edit a user backend */ public function edituserbackendAction() { $this->assertPermission('config/application/userbackend'); $backendName = $this->params->getRequired('backend'); $form = new UserBackendConfigForm(); $form->setRedirectUrl('config/userbackend'); $form->setIniConfig(Config::app('authentication')); $form->setOnSuccess(function (UserBackendConfigForm $form) use($backendName) { try { $form->edit($backendName, array_map(function ($v) { return $v !== '' ? $v : null; }, $form->getValues())); } catch (Exception $e) { $form->error($e->getMessage()); return false; } if ($form->save()) { Notification::success(sprintf(t('User backend "%s" successfully updated'), $backendName)); return true; } return false; }); try { $form->load($backendName); $form->setResourceConfig(ResourceFactory::getResourceConfigs()); $form->handleRequest(); } catch (NotFoundError $_) { $this->httpNotFound(sprintf($this->translate('User backend "%s" not found'), $backendName)); } $this->renderForm($form, $this->translate('Update User Backend')); }
protected function enumResources() { $resources = array(); $allowed = array('mysql', 'pgsql'); foreach (ResourceFactory::getResourceConfigs() as $name => $resource) { if ($resource->type === 'db' && in_array($resource->db, $allowed)) { $resources[$name] = $name; } } return $resources; }
/** * Action for editing user backends */ public function edituserbackendAction() { $this->assertPermission('config/application/userbackend'); $form = new UserBackendConfigForm(); $form->setTitle($this->translate('Edit User Backend')); $form->setIniConfig(Config::app('authentication')); $form->setResourceConfig(ResourceFactory::getResourceConfigs()); $form->setRedirectUrl('config/userbackend'); $form->setAction(Url::fromRequest()); $form->handleRequest(); $this->view->form = $form; $this->render('userbackend/modify'); }
/** * Return the names of all configured LDAP resources * * @return array */ protected function getLdapResourceNames() { $names = array(); foreach (ResourceFactory::getResourceConfigs() as $name => $config) { if (in_array(strtolower($config->type), array('ldap', 'msldap'))) { $names[] = $name; } } if (empty($names)) { Notification::error($this->translate('No LDAP resources available. Please configure an LDAP resource first.')); $this->getResponse()->redirectAndExit('config/createresource'); } return $names; }