Skip to content

Commit

Permalink
Add config page: monitoring integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Nov 9, 2019
1 parent 5fed0e7 commit 4f513fa
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
23 changes: 23 additions & 0 deletions application/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Icinga\Application\Config;
use Icinga\Module\Masifupgrader\Forms\BackendForm;
use Icinga\Module\Masifupgrader\Forms\IntegrationForm;
use Icinga\Module\Masifupgrader\Forms\ServicesForm;
use Icinga\Web\Controller;

class ConfigController extends Controller
Expand All @@ -18,4 +20,25 @@ public function backendAction()

$this->view->tabs = $this->Module()->getConfigTabs()->activate('backend');
}

public function integrationAction()
{
$this->assertPermission('config/modules');

$cfg = Config::module('masifupgrader');

$this->view->form1 = $form1 = new IntegrationForm();
$form1->setIniConfig($cfg)
->handleRequest();

if ($cfg->get('integration', 'monitoring', '0')) {
$this->view->form2 = $form2 = new ServicesForm();
$form2->setIniConfig($cfg)
->handleRequest();
} else {
$this->view->form2 = null;
}

$this->view->tabs = $this->Module()->getConfigTabs()->activate('integration');
}
}
28 changes: 28 additions & 0 deletions application/forms/IntegrationForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Icinga\Module\Masifupgrader\Forms;

use Icinga\Application\Icinga;
use Icinga\Forms\ConfigForm;

class IntegrationForm extends ConfigForm
{
public function init()
{
$this->setName('form_config_integration');
$this->setTitle($this->translate('Monitoring integration'));
$this->setSubmitLabel($this->translate('Save changes'));
}

public function createElements(array $formData)
{
$this->addElement('checkbox', 'integration_monitoring', [
'label' => $this->translate('Monitoring module'),
'description' => $this->translate('Integrate into the monitoring module (IDO)')
]);

if (!Icinga::app()->getModuleManager()->hasEnabled('monitoring')) {
$this->getElement('integration_monitoring')->disabled = true;
}
}
}
34 changes: 34 additions & 0 deletions application/forms/ServicesForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Icinga\Module\Masifupgrader\Forms;

use Icinga\Forms\ConfigForm;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use PDO;

class ServicesForm extends ConfigForm
{
public function init()
{
$this->setName('form_config_services');
$this->setTitle($this->translate('Services'));
$this->setSubmitLabel($this->translate('Save changes'));
}

public function createElements(array $formData)
{
/** @var PDO $pdo */
$pdo = MonitoringBackend::instance()->getResource()->getDbAdapter()->getConnection();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $pdo->prepare('SELECT DISTINCT name2 FROM icinga_objects WHERE objecttype_id = 2 ORDER BY name2');
$stmt->execute();

foreach ($stmt->fetchAll(PDO::FETCH_COLUMN) as $service) {
$this->addElement('checkbox', "services_$service", [
'label' => $this->translate($service),
'description' => sprintf($this->translate('Integrate into services named "%s"'), $service)
]);
}
}
}
7 changes: 7 additions & 0 deletions application/views/scripts/config/integration.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="controls">
<?= /** @var \Icinga\Web\Widget\Tabs $tabs */ $tabs ?>
</div>
<div class="content">
<?= /** @var \Icinga\Web\Form $form1 */ $form1 ?>
<?= /** @var \Icinga\Web\Form $form2 */ $form2 ?>
</div>
6 changes: 6 additions & 0 deletions configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
'title' => $this->translate('Database backend')
]);

$this->provideConfigTab('integration', [
'url' => 'config/integration',
'label' => $this->translate('Integration'),
'title' => $this->translate('Monitoring integration')
]);

$section = $this->menuSection(N_('Masif Upgrader'), [
'icon' => 'reschedule'
]);
Expand Down

0 comments on commit 4f513fa

Please sign in to comment.