monitoring/commands: Move toggle instance feature command forms into a single form

refs #6593
This commit is contained in:
Eric Lippmann 2014-09-11 17:16:13 +02:00
parent 22771e6f6f
commit 92571599df
12 changed files with 179 additions and 420 deletions

View File

@ -1,33 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\ToggleActiveHostChecks;
/**
* Form for enabling/disabling active host checks on an Icinga instance
*/
class ToggleActiveHostChecksCommandForm extends ToggleFeatureCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Toggle Active Host Checks'));
$this->setFeature('active_host_checks_enabled', mt('monitoring', 'Active Host Checks Being Executed'));
}
/**
* Get the command which is to be sent to an Icinga instance
*
* @return ToggleActiveHostChecks
*/
public function getCommand()
{
return new ToggleActiveHostChecks();
}
}

View File

@ -1,33 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\ToggleActiveServiceChecks;
/**
* Form for enabling/disabling active service checks on an Icinga instance
*/
class ToggleActiveServiceChecksCommandForm extends ToggleFeatureCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Toggle Active Service Checks'));
$this->setFeature('active_service_checks_enabled', mt('monitoring', 'Active Service Checks Being Executed'));
}
/**
* Get the command which is to be sent to an Icinga instance
*
* @return ToggleActiveServiceChecks
*/
public function getCommand()
{
return new ToggleActiveServiceChecks();
}
}

View File

@ -1,33 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\ToggleEventHandlers;
/**
* Form for enabling/disabling host and service event handlers on an Icinga instance
*/
class ToggleEventHandlersCommandForm extends ToggleFeatureCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Toggle Event Handlers'));
$this->setFeature('event_handlers_enabled', mt('monitoring', 'Event Handlers Enabled'));
}
/**
* Get the command which is to be sent to an Icinga instance
*
* @return ToggleEventHandlers
*/
public function getCommand()
{
return new ToggleEventHandlers();
}
}

View File

@ -1,90 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Form\Command\CommandForm;
use Icinga\Web\Notification;
use Icinga\Web\Request;
/**
* Base class for forms enabling/disabling features of an Icinga instance
*/
abstract class ToggleFeatureCommandForm extends CommandForm
{
/**
* @var string
*/
protected $feature;
/**
* @var string
*/
protected $label;
/**
* Get the command which is to be sent to an Icinga instance
*
* @return \Icinga\Module\Monitoring\Command\ToggleFeature
*/
abstract public function getCommand();
/**
* Set the feature the form enables or disables
*
* @param string $feature
* @param string $label
*
* @return $this
*/
public function setFeature($feature, $label)
{
$this->feature = $feature;
$this->label = $label;
return $this;
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation.
*/
public function createElements(array $formData = array())
{
if (isset($formData[$this->feature])) {
$enabled = (bool) $formData[$this->feature];
} else {
$enabled = (bool) $this->backend
->select()
->from(
'programstatus',
array($this->feature)
)
->getQuery()
->fetchRow();
}
$this->addElement(
'checkbox',
$this->feature,
array(
'label' => $this->label,
'autosubmit' => $this->inline,
'value' => $enabled
)
);
return $this;
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess(Request $request)
{
$toggleFeature = $this->getCommand();
(bool) $request->getParam($this->feature) === true ? $toggleFeature->enable() : $toggleFeature->disable();
$this->getTransport($request)->send($toggleFeature);
Notification::success(mt('monitoring', 'Command sent'));
return true;
}
}

View File

@ -1,33 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\ToggleFlapDetection;
/**
* Form for enabling/disabling host and service flap detection on an Icinga instance
*/
class ToggleFlapDetectionCommandForm extends ToggleFeatureCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Toggle Flap Detection'));
$this->setFeature('flap_detection_enabled', mt('monitoring', 'Flap Detection Enabled'));
}
/**
* Get the command which is to be sent to an Icinga instance
*
* @return ToggleFlapDetection
*/
public function getCommand()
{
return new ToggleFlapDetection();
}
}

View File

@ -0,0 +1,179 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\ToggleInstanceFeatureCommand;
use Icinga\Module\Monitoring\Form\Command\CommandForm;
use Icinga\Web\Notification;
use Icinga\Web\Request;
/**
* Form for enabling or disabling features of Icinga objects, i.e. hosts or services
*/
class ToggleInstanceFeaturesCommandForm extends CommandForm
{
/**
* Instance status
*
* @var object
*/
protected $status;
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setAttrib('class', 'inline');
}
/**
* Set the instance status
*
* @param object $status
*
* @return $this
*/
public function setStatus($status)
{
$this->status = (object) $status;
return $this;
}
/**
* Get the instance status
*
* @return object
*/
public function getStatus()
{
return $this->status;
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation.
*/
public function createElements(array $formData = array())
{
$this->addElements(array(
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS,
array(
'label' => mt('monitoring', 'Active Host Checks Being Executed'),
'autosubmit' => true
)
),
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS,
array(
'label' => mt('monitoring', 'Active Service Checks Being Executed'),
'autosubmit' => true
)
),
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS,
array(
'label' => mt('monitoring', 'Event Handlers Enabled'),
'autosubmit' => true
)
),
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION,
array(
'label' => mt('monitoring', 'Flap Detection Enabled'),
'autosubmit' => true
)
),
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS,
array(
'label' => mt('monitoring', 'Notifications Enabled'),
'autosubmit' => true
)
),
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_HOST_OBSESSING,
array(
'label' => mt('monitoring', 'Obsessing Over Hosts'),
'autosubmit' => true
)
),
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_SERVICE_OBSESSING,
array(
'label' => mt('monitoring', 'Obsessing Over Services'),
'autosubmit' => true
)
),
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_HOST_CHECKS,
array(
'label' => mt('monitoring', 'Passive Host Checks Being Accepted'),
'autosubmit' => true
)
),
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_SERVICE_CHECKS,
array(
'label' => mt('monitoring', 'Passive Service Checks Being Accepted'),
'autosubmit' => true
)
),
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA,
array(
'label' => mt('monitoring', 'Performance Data Being Processed'),
'autosubmit' => true
)
)
));
return $this;
}
/**
* Load feature status
*
* @param object $instanceStatus
*
* @return $this
*/
public function load($instanceStatus)
{
$this->create();
foreach ($this->getValues() as $feature => $enabled) {
$this->getElement($feature)->setChecked($instanceStatus->{$feature});
}
return $this;
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess(Request $request)
{
foreach ($this->getValues() as $feature => $enabled) {
$toggleFeature = new ToggleInstanceFeatureCommand();
$toggleFeature
->setFeature($feature)
->setEnabled($enabled);
$this->getTransport($request)->send($toggleFeature);
}
Notification::success(mt('monitoring', 'Toggling feature..'));
return true;
}
}

View File

@ -1,33 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\ToggleNotifications;
/**
* Form for enabling/disabling host and service notifications on an Icinga instance
*/
class ToggleNotificationsCommandForm extends ToggleFeatureCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Toggle Notifications'));
$this->setFeature('notifications_enabled', mt('monitoring', 'Notifications Enabled'));
}
/**
* Get the command which is to be sent to an Icinga instance
*
* @return ToggleNotifications
*/
public function getCommand()
{
return new ToggleNotifications();
}
}

View File

@ -1,33 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\ToggleObsessingOverHostChecks;
/**
* Form for enabling/disabling processing of host checks via the OCHP command on an Icinga instance
*/
class ToggleObsessingOverHostChecksCommandForm extends ToggleFeatureCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Toggle Obsessing Over Host Checks'));
$this->setFeature('obsess_over_hosts', mt('monitoring', 'Obsessing Over Hosts'));
}
/**
* Get the command which is to be sent to an Icinga instance
*
* @return ToggleObsessingOverHostChecks
*/
public function getCommand()
{
return new ToggleObsessingOverHostChecks();
}
}

View File

@ -1,33 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\ToggleObsessingOverServiceChecks;
/**
* Form for enabling/disabling processing of service checks via the OCHP command on an Icinga instance
*/
class ToggleObsessingOverServiceChecksCommandForm extends ToggleFeatureCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Toggle Obsessing Over Service Checks'));
$this->setFeature('obsess_over_services', mt('monitoring', 'Obsessing Over Services'));
}
/**
* Get the command which is to be sent to an Icinga instance
*
* @return ToggleObsessingOverServiceChecks
*/
public function getCommand()
{
return new ToggleObsessingOverServiceChecks();
}
}

View File

@ -1,33 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\TogglePassiveHostChecks;
/**
* Form for enabling/disabling passive host checks on an Icinga instance
*/
class TogglePassiveHostChecksCommandForm extends ToggleFeatureCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Toggle Passive Host Checks'));
$this->setFeature('passive_host_checks_enabled', mt('monitoring', 'Passive Host Checks Being Accepted'));
}
/**
* Get the command which is to be sent to an Icinga instance
*
* @return TogglePassiveHostChecks
*/
public function getCommand()
{
return new TogglePassiveHostChecks();
}
}

View File

@ -1,33 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\TogglePassiveServiceChecks;
/**
* Form for enabling/disabling passive service checks on an Icinga instance
*/
class TogglePassiveServiceChecksCommandForm extends ToggleFeatureCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Toggle Passive Service Checks'));
$this->setFeature('passive_service_checks_enabled', mt('monitoring', 'Passive Service Checks Being Accepted'));
}
/**
* Get the command which is to be sent to an Icinga instance
*
* @return TogglePassiveServiceChecks
*/
public function getCommand()
{
return new TogglePassiveServiceChecks();
}
}

View File

@ -1,33 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\TogglePerformanceData;
/**
* Form for enabling/disabling the processing of host and service performance data on an Icinga instance
*/
class TogglePerformanceDataCommandForm extends ToggleFeatureCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Toggle Performance Data'));
$this->setFeature('process_performance_data', mt('monitoring', 'Performance Data Being Processed'));
}
/**
* Get the command which is to be sent to an Icinga instance
*
* @return TogglePerformanceData
*/
public function getCommand()
{
return new TogglePerformanceData();
}
}