diff --git a/application/views/helpers/FormDate.php b/application/views/helpers/FormDate.php index 74aef7f23..4e35e00d3 100644 --- a/application/views/helpers/FormDate.php +++ b/application/views/helpers/FormDate.php @@ -1,4 +1,29 @@ + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} /** * Helper to generate a text input with a datepicker being attached @@ -27,4 +52,4 @@ class Zend_View_Helper_FormDate extends \Zend_View_Helper_FormText } } -?> +// @codingStandardsIgnoreStop \ No newline at end of file diff --git a/application/views/helpers/FormDateTime.php b/application/views/helpers/FormDateTime.php new file mode 100644 index 000000000..240d4ac2a --- /dev/null +++ b/application/views/helpers/FormDateTime.php @@ -0,0 +1,55 @@ + + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +/** + * Helper to generate a text input with a datepicker being attached + */ +class Zend_View_Helper_FormDateTime extends \Zend_View_Helper_FormText +{ + /** + * Generates a html date input + * + * @access public + * + * @param string $name The element name. + * @param string $value The default value. + * @param array $attribs Attributes which should be added to the input tag. + * + * @return string The input tag and options XHTML. + */ + public function formDateTime($name, $value = null, $attribs = null) + { + return '_htmlAttribs($attribs) + . $this->getClosingBracket(); + } +} + +// @codingStandardsIgnoreStop \ No newline at end of file diff --git a/application/views/helpers/FormNumber.php b/application/views/helpers/FormNumber.php index 558c1f24c..fbbf57fcf 100644 --- a/application/views/helpers/FormNumber.php +++ b/application/views/helpers/FormNumber.php @@ -1,4 +1,29 @@ + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} /** * Helper to generate a number input @@ -27,4 +52,4 @@ class Zend_View_Helper_FormNumber extends \Zend_View_Helper_FormText } } -?> +// @codingStandardsIgnoreStop \ No newline at end of file diff --git a/application/views/helpers/FormTime.php b/application/views/helpers/FormTime.php index a3986af58..511ae602e 100644 --- a/application/views/helpers/FormTime.php +++ b/application/views/helpers/FormTime.php @@ -1,4 +1,29 @@ + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} /** * Helper to generate a text input with a timepicker being attached @@ -27,4 +52,4 @@ class Zend_View_Helper_FormTime extends \Zend_View_Helper_FormText } } -?> +// @codingStandardsIgnoreStop \ No newline at end of file diff --git a/application/views/helpers/Format.php b/application/views/helpers/Format.php index ca3377774..141b76dad 100644 --- a/application/views/helpers/Format.php +++ b/application/views/helpers/Format.php @@ -1,4 +1,29 @@ + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} use Icinga\Util\Format; @@ -10,3 +35,4 @@ class Zend_View_Helper_Format extends Zend_View_Helper_Abstract } } +// @codingStandardsIgnoreStop \ No newline at end of file diff --git a/application/views/helpers/Img.php b/application/views/helpers/Img.php index 48f79fda2..110a6d844 100644 --- a/application/views/helpers/Img.php +++ b/application/views/helpers/Img.php @@ -1,8 +1,33 @@ + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +/** + * Class Zend_View_Helper_Img + */ class Zend_View_Helper_Img extends Zend_View_Helper_Abstract { public function img($url, array $properties = array()) @@ -27,3 +52,4 @@ class Zend_View_Helper_Img extends Zend_View_Helper_Abstract } } +// @codingStandardsIgnoreStart \ No newline at end of file diff --git a/application/views/helpers/QUrl.php b/application/views/helpers/QUrl.php index 80b4e59cd..56f1d704e 100644 --- a/application/views/helpers/QUrl.php +++ b/application/views/helpers/QUrl.php @@ -1,4 +1,29 @@ + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} use Icinga\Web\Url; @@ -19,3 +44,4 @@ class Zend_View_Helper_QUrl extends Zend_View_Helper_Abstract } } +// @codingStandardsIgnoreStop \ No newline at end of file diff --git a/application/views/helpers/Qlink.php b/application/views/helpers/Qlink.php index aef823152..6747db786 100755 --- a/application/views/helpers/Qlink.php +++ b/application/views/helpers/Qlink.php @@ -1,10 +1,38 @@ + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} -// TODO: Search for the best and safest quoting -// TODO: Check whether attributes are safe. Script, title in combination with -// Hover-Tips etc. Eventually create a whitelist for a few options only. use Icinga\Web\Url; +/** + * Class Zend_View_Helper_Qlink + * TODO: Search for the best and safest quoting + * TODO: Check whether attributes are safe. Script, title in combination with + * Hover-Tips etc. Eventually create a whitelist for a few options only. + */ class Zend_View_Helper_Qlink extends Zend_View_Helper_Abstract { @@ -90,3 +118,4 @@ class Zend_View_Helper_Qlink extends Zend_View_Helper_Abstract */ } +// @codingStandardsIgnoreStop \ No newline at end of file diff --git a/application/views/helpers/TimeSince.php b/application/views/helpers/TimeSince.php index 410ce15d3..9f51f7ac7 100644 --- a/application/views/helpers/TimeSince.php +++ b/application/views/helpers/TimeSince.php @@ -1,5 +1,33 @@ + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +/** + * Class Zend_View_Helper_TimeSince + */ class Zend_View_Helper_TimeSince extends Zend_View_Helper_Abstract { public function timeSince($timestamp) @@ -42,3 +70,5 @@ class Zend_View_Helper_TimeSince extends Zend_View_Helper_Abstract return floor($hour / 24) . 'd ' . ($hour % 24) . 'h'; } } + +// @codingStandardsIgnoreStop \ No newline at end of file diff --git a/application/views/helpers/Util.php b/application/views/helpers/Util.php index 6448db486..1066327ad 100644 --- a/application/views/helpers/Util.php +++ b/application/views/helpers/Util.php @@ -1,5 +1,33 @@ + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +/** + * Class Zend_View_Helper_Util + */ class Zend_View_Helper_Util extends Zend_View_Helper_Abstract { public function util() { @@ -112,3 +140,4 @@ class Zend_View_Helper_Util extends Zend_View_Helper_Abstract } } +// @codingStandardsIgnoreStop \ No newline at end of file diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 3965313aa..7b1e9dbab 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -26,6 +26,7 @@ namespace Icinga\Web; use Icinga\Exception\ProgrammingError; +use Zend_View_Interface; /** * Class Form @@ -68,7 +69,14 @@ abstract class Form extends \Zend_Form if (!$this->tokenDisabled) { $this->initCsrfToken(); } - $this->create(); + } + + public function render(Zend_View_Interface $view = null) + { + if ($this->_isRendered === false) { + $this->create(); + } + return parent::render($view); } /** diff --git a/library/Icinga/Web/Form/Element/Date.php b/library/Icinga/Web/Form/Element/Date.php new file mode 100644 index 000000000..b87421ead --- /dev/null +++ b/library/Icinga/Web/Form/Element/Date.php @@ -0,0 +1,43 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Web\Form\Element; + +/** + * Date form element + * + * @TODO: The given label for this element is not displayed. (Reason unknown) + */ +class Date extends \Zend_Form_Element_Xhtml +{ + /** + * Default form view helper to use for rendering + * @var string + */ + public $helper = "formDate"; +} diff --git a/library/Icinga/Web/Form/Element/DateTime.php b/library/Icinga/Web/Form/Element/DateTime.php new file mode 100644 index 000000000..f25b3f814 --- /dev/null +++ b/library/Icinga/Web/Form/Element/DateTime.php @@ -0,0 +1,40 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Web\Form\Element; + +use Zend_Form_Element_Xhtml; + +class DateTime extends Zend_Form_Element_Xhtml +{ + /** + * Default form view helper to use for rendering + * @var string + */ + public $helper = "formDateTime"; +} \ No newline at end of file diff --git a/library/Icinga/Web/Form/Element/Note.php b/library/Icinga/Web/Form/Element/Note.php new file mode 100644 index 000000000..b093bdd23 --- /dev/null +++ b/library/Icinga/Web/Form/Element/Note.php @@ -0,0 +1,43 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Web\Form\Element; + +use Zend_Form_Element_Xhtml; + +/** + * Implements note element for Zend forms + */ +class Note extends Zend_Form_Element_Xhtml +{ + /** + * Name of the view helper + * @var string + */ + public $helper = 'formNote'; +} \ No newline at end of file diff --git a/library/Icinga/Web/Form/Element/Number.php b/library/Icinga/Web/Form/Element/Number.php new file mode 100644 index 000000000..926d7622c --- /dev/null +++ b/library/Icinga/Web/Form/Element/Number.php @@ -0,0 +1,43 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Web\Form\Element; + +/** + * Number form element + * + * @TODO: The given label for this element is not displayed. (Reason unknown) + */ +class Number extends \Zend_Form_Element_Xhtml +{ + /** + * Default form view helper to use for rendering + * @var string + */ + public $helper = "formNumber"; +} diff --git a/library/Icinga/Web/Form/Element/Time.php b/library/Icinga/Web/Form/Element/Time.php new file mode 100644 index 000000000..f699b25be --- /dev/null +++ b/library/Icinga/Web/Form/Element/Time.php @@ -0,0 +1,43 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Web\Form\Element; + +/** + * Time form element + * + * @TODO: The given label for this element is not displayed. (Reason unknown) + */ +class Time extends \Zend_Form_Element_Xhtml +{ + /** + * Default form view helper to use for rendering + * @var string + */ + public $helper = "formTime"; +} diff --git a/library/Icinga/Web/Form/Elements/Date.php b/library/Icinga/Web/Form/Elements/Date.php deleted file mode 100644 index 47dfe68f7..000000000 --- a/library/Icinga/Web/Form/Elements/Date.php +++ /dev/null @@ -1,18 +0,0 @@ - diff --git a/library/Icinga/Web/Form/Elements/Number.php b/library/Icinga/Web/Form/Elements/Number.php deleted file mode 100644 index 758fc80e1..000000000 --- a/library/Icinga/Web/Form/Elements/Number.php +++ /dev/null @@ -1,18 +0,0 @@ - diff --git a/library/Icinga/Web/Form/Elements/Time.php b/library/Icinga/Web/Form/Elements/Time.php deleted file mode 100644 index b8f055835..000000000 --- a/library/Icinga/Web/Form/Elements/Time.php +++ /dev/null @@ -1,18 +0,0 @@ - diff --git a/modules/monitoring/application/controllers/CommandController.php b/modules/monitoring/application/controllers/CommandController.php index bc351fc5a..09f6cdbd2 100644 --- a/modules/monitoring/application/controllers/CommandController.php +++ b/modules/monitoring/application/controllers/CommandController.php @@ -1,7 +1,32 @@ + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + use Icinga\Backend; -use Icinga\Form\SendCommand; -use Icinga\Form\Confirmation; use Icinga\Application\Config; use Icinga\Authentication\Manager; use Icinga\Web\ModuleActionController; @@ -10,41 +35,67 @@ use Icinga\Protocol\Commandpipe\CommandPipe; use Icinga\Protocol\Commandpipe\Acknowledgement; use Icinga\Exception\ConfigurationError; use Icinga\Exception\MissingParameterException; +use Monitoring\Form\Command\Acknowledge; +use Monitoring\Form\Command\Comment as CommentForm; +use Monitoring\Form\Command\Confirmation; +use Monitoring\Form\Command\CustomNotification; +use Monitoring\Form\Command\RescheduleNextCheck; +use Monitoring\Form\Command\SubmitPassiveCheckResult; +/** + * Class Monitoring_CommandController + * + * Interface to send commands and display forms + */ class Monitoring_CommandController extends ModuleActionController { + const DEFAULT_VIEW_SCRIPT = 'renderform'; + /** * @var \Icinga\Protocol\Commandpipe\CommandPipe */ public $target; + /** + * Controller configuration + * @throws Icinga\Exception\ConfigurationError + */ public function init() { - if ($this->_request->isPost()) { - // We do not need to display a view.. - $this->_helper->viewRenderer->setNoRender(true); - // ..nor the overall site layout in case its a POST request. - $this->_helper->layout()->disableLayout(); +// if ($this->_request->isPost()) { +// // We do not need to display a view.. +// $this->_helper->viewRenderer->setNoRender(true); +// // ..nor the overall site layout in case its a POST request. +// $this->_helper->layout()->disableLayout(); +// +// $instance = $this->_request->getPost("instance"); +// $target_config = Config::getInstance()->getModuleConfig("instances", "monitoring"); +// if ($instance) { +// if (isset($target_config[$instance])) { +// $this->target = new CommandPipe($target_config[$instance]); +// } else { +// throw new ConfigurationError("Instance $instance is not configured"); +// } +// } else { +// $target_info = $target_config->current(); // Take the very first section +// if ($target_info === false) { +// throw new ConfigurationError("Not any instances are configured yet"); +// } else { +// $this->target = new CommandPipe($target_info); +// } +// } +// } - $instance = $this->_request->getPost("instance"); - $target_config = Config::getInstance()->getModuleConfig("instances", "monitoring"); - if ($instance) { - if (isset($target_config[$instance])) { - $this->target = new CommandPipe($target_config[$instance]); - } else { - throw new ConfigurationError("Instance $instance is not configured"); - } - } else { - $target_info = $target_config->current(); // Take the very first section - if ($target_info === false) { - throw new ConfigurationError("Not any instances are configured yet"); - } else { - $this->target = new CommandPipe($target_info); - } - } - } + $this->_helper->viewRenderer->setRender(self::DEFAULT_VIEW_SCRIPT); } + /** + * Retrieve all existing targets for host- and service combination + * @param string $hostname + * @param string $servicename + * @return array + * @throws Icinga\Exception\MissingParameterException + */ private function selectCommandTargets($hostname, $servicename = null) { $target = "hostlist"; @@ -62,6 +113,13 @@ class Monitoring_CommandController extends ModuleActionController return Backend::getInstance()->select()->from($target)->applyFilters($filter)->fetchAll(); } + /** + * Getter for request parameters + * @param string $name + * @param bool $mandatory + * @return mixed + * @throws Icinga\Exception\MissingParameterException + */ private function getParameter($name, $mandatory = true) { $value = $this->_request->getParam($name); @@ -71,587 +129,350 @@ class Monitoring_CommandController extends ModuleActionController return $value; } - public function restartAction() + // ------------------------------------------------------------------------ + // Commands for hosts / services + // ------------------------------------------------------------------------ + + public function disableactivechecksAction() { - $form = new Confirmation("Restart Icinga?", Confirmation::YES_NO); - if ($this->_request->isPost()) { - if ($form->isValid() && $form->isConfirmed()) { - $this->target->restartIcinga(); - } - } else { - $form->setAction($this->view->url()); - $this->view->form = $form; + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Disable active checks')); + $form->addNote(t('Disable active checks for this object.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } - public function schedulecheckAction() - { - $form = new SendCommand("Schedule Host/Service check"); - $form->addDatePicker("checkDate", "Check date", date("m-d-Y")); - $form->addTimePicker("checkTime", "Check time", date("h:i A")); - $form->addCheckbox("forceCheck", "Force check", false); - - if ($this->_request->isPost()) { - if ($form->isValid()) { - $withChilds = false; - $services = $form->getServices(); - $time = sprintf("%s %s", $form->getDate("checkDate"), $form->getTime("checkTime")); - - if (!$services || $services === "all") { - $withChilds = $services === "all"; - $targets = $this->selectCommandTargets($form->getHosts()); - } else { - $targets = $this->selectCommandTargets($form->getHosts(), $services); - } - - if ($form->isChecked("forceCheck")) { - $this->target->scheduleForcedCheck($targets, $time, $withChilds); - } else { - $this->target->scheduleCheck($targets, $time, $withChilds); - } - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; - } - } - - public function sendScheduledowntime() - { - $author = "AUTHOR"; //@TODO: get from auth backend - $comment = $this->getMandatoryParameter("comment"); - $persistent = $this->_request->getPost("persistent", false) == "true"; - $commentObj = new \Icinga\Protocol\Commandpipe\Comment($author, $comment, $persistent); - - $start = intval($this->_request->getPost("start", time())); - $end = intval($this->getMandatoryParameter("end")); - $duration = $this->_request->getPost("duration", false); - if ($duration !== false) { - $duration = intval($duration); - } - $downtime = new \Icinga\Protocol\Commandpipe\Downtime($start, $end, $commentObj, $duration); - - $this->target->scheduleDowntime($this->selectCommandTargets(), $downtime); - } - public function enableactivechecksAction() { - // @TODO: Elaborate how "withChilds" and "forHosts" can be utilised - $form = new SendCommand("Enable active checks?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $withChilds = $forHosts = false; - $services = $form->getServices(); + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Enable active checks')); + $form->addNote(t('Enable active checks for this object.')); + $this->view->form = $form; - if ($services) { - $withChilds = $services === "all"; - $form->addCheckbox("forHosts", "", false); - $forHosts = $form->isChecked("forHosts"); - if ($withChilds) { - $targets = $this->selectCommandTargets($form->getHosts()); - } else { - $targets = $this->selectCommandTargets($form->getHosts(), $services); - } - } else { - $targets = $this->selectCommandTargets($form->getHosts()); - } - - $this->target->enableActiveChecks($targets); - } - } else { - $services = $this->getParameter("services", false); - if ($services) { - $form->addCheckbox("forHosts", "Enable for hosts too?", false); - } - $form->setServices($services); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } - public function disableactivechecksAction() + public function reschedulenextcheckAction() { - // @TODO: Elaborate how "withChilds" and "forHosts" can be utilised - $form = new SendCommand("Disable active checks?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $withChilds = $forHosts = false; - $services = $form->getServices(); + $form = new RescheduleNextCheck(); + $form->setRequest($this->getRequest()); - if ($services) { - $withChilds = $services === "all"; - $form->addCheckbox("forHosts", "", false); - $forHosts = $form->isChecked("forHosts"); - if ($withChilds) { - $targets = $this->selectCommandTargets($form->getHosts()); - } else { - $targets = $this->selectCommandTargets($form->getHosts(), $services); - } - } else { - $targets = $this->selectCommandTargets($form->getHosts()); - } + $this->view->form = $form; - $this->target->disableActiveChecks($targets); - } - } else { - $services = $this->getParameter("services", false); - if ($services) { - $form->addCheckbox("forHosts", "Disable for hosts too?", false); - } - $form->setServices($services); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } - public function enablenotificationsAction() + public function submitpassivecheckresultAction() { - // @TODO: Elaborate how "withChilds", "childHosts" and "forHosts" can be utilised - $form = new SendCommand("Enable notifications?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $services = $form->getServices(); - $withChilds = $forHosts = $childHosts = false; + $type = SubmitPassiveCheckResult::TYPE_SERVICE; - if ($services) { - $withChilds = $services === "all"; - $form->addCheckbox("forHosts", "", false); - $forHosts = $form->isChecked("forHosts"); - if ($withChilds) { - $targets = $this->selectCommandTargets($form->getHosts()); - } else { - $targets = $this->selectCommandTargets($form->getHosts(), $services); - } - } else { - $form->addCheckbox("childHosts", "", false); - $childHosts = $form->isChecked("childHosts"); - $targets = $this->selectCommandTargets($form->getHosts()); - } + $form = new SubmitPassiveCheckResult(); + $form->setRequest($this->getRequest()); + $form->setType($type); - $this->target->enableNotifications($targets); - } - } else { - $services = $this->getParameter("services", false); - if ($services) { - $form->addCheckbox("forHosts", "Enable for hosts too?", false); - } else { - $form->addCheckbox("childHosts", "Enable notifications for ". - "child hosts too?", false); - } - $form->setServices($services); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; - } - } + $this->view->form = $form; - public function disablenotificationsAction() - { - // @TODO: Elaborate how "withChilds", "childHosts" and "forHosts" can be utilised - $form = new SendCommand("Disable notifications?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $services = $form->getServices(); - $withChilds = $forHosts = $childHosts = false; - - if ($services) { - $withChilds = $services === "all"; - $form->addCheckbox("forHosts", "", false); - $forHosts = $form->isChecked("forHosts"); - if ($withChilds) { - $targets = $this->selectCommandTargets($form->getHosts()); - } else { - $targets = $this->selectCommandTargets($form->getHosts(), $services); - } - } else { - $form->addCheckbox("childHosts", "", false); - $childHosts = $form->isChecked("childHosts"); - $targets = $this->selectCommandTargets($form->getHosts()); - } - - $this->target->disableNotifications($targets); - } - } else { - $services = $this->getParameter("services", false); - if ($services) { - $form->addCheckbox("forHosts", "Disable for hosts too?", false); - } else { - $form->addCheckbox("childHosts", "Disable notifications for ". - "child hosts too?", false); - } - $form->setServices($services); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; - } - } - - public function enableeventhandlingAction() - { - $form = new SendCommand("Enable event handler?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->enableEventHandler($targets); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; - } - } - - public function disableeventhandlingAction() - { - $form = new SendCommand("Disable event handler?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->disableEventHandler($targets); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; - } - } - - public function enableflapdetectionAction() - { - $form = new SendCommand("Enable flap detection?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->enableFlappingDetection($targets); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; - } - } - - public function disableflapdetectionAction() - { - $form = new SendCommand("Disable flap detection?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->disableFlappingDetection($targets); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; - } - } - - public function enablepassivechecksAction() - { - $form = new SendCommand("Enable passive checks?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->enablePassiveChecks($targets); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; - } - } - - public function disablepassivechecksAction() - { - $form = new SendCommand("Disable passive checks?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->disablePassiveChecks($targets); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; - } - } - - public function startobsessingAction() - { - $form = new SendCommand("Start obsessing?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->startObsessing($targets); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } public function stopobsessingAction() { - $form = new SendCommand("Stop obsessing?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->stopObsessing($targets); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Stop obsessing')); + $form->addNote(t('Stop obsessing over this object.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } - public function placeacknowledgementAction() + public function startobsessingAction() { - $form = new SendCommand("Place acknowledgement?"); - $form->addTextBox("author", "Author (Your name):", "", true); - $form->addTextBox("comment", "Comment:", "", false, true); - $form->addCheckbox("persistent", "Persistent comment:", false); - $form->addDatePicker("expireDate", "Expire date:", ""); - $form->addTimePicker("expireTime", "Expire time:", ""); - $form->addCheckbox("sticky", "Sticky acknowledgement:", true); - $form->addCheckbox("notify", "Send notification:", true); + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Start obsessing')); + $form->addNote(t('Start obsessing over this object.')); + $this->view->form = $form; - if ($this->_request->isPost()) { - if ($form->isValid()) { - $raw_time = strptime(sprintf("%s %s", $form->getDate("expireDate"), - $form->getTime("expireTime")), "%m-%d-%Y %I:%M %p"); - if ($raw_time) { - $time = mktime($raw_time['tm_hour'], $raw_time['tm_min'], $raw_time['tm_sec'], - $raw_time['tm_mon'], $raw_time['tm_mday'], $raw_time['tm_year']); - } else { - $time = -1; - } - - $comment = new Comment($form->getText("author"), $form->getText("comment"), - $form->isChecked("persistent")); - $acknowledgement = new Acknowledgement($comment, $form->isChecked("notify"), - $time, $form->isChecked("sticky")); - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->acknowledge($targets, $acknowledgement); - } - } else { - $form->getElement("author")->setValue(Manager::getInstance()->getUser()->getUsername()); - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } - public function deleteacknowledgementAction() + public function stopacceptingpassivechecksAction() { - $form = new SendCommand("Remove acknowledgements?"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->removeAcknowledge($targets); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Stop accepting passive checks')); + $form->addNote(t('Passive checks for this object will be omitted.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } - public function submitcheckresultAction() + public function startacceptingpassivechecksAction() { - // @TODO: How should the "perfdata" be handled? (The interface function does not accept it) - $form = new SendCommand("Submit passive check result"); - $form->addChoice("state", "Check result:", array("UP", "DOWN", "UNREACHABLE")); - $form->addTextBox("output", "Check output:", "", false, true); - $form->addTextBox("perfdata", "Performance data:", "", false, true); + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Start accepting passive checks')); + $form->addNote(t('Passive checks for this object will be accepted.')); + $this->view->form = $form; - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->submitCheckResult($targets, $form->getChoice("state"), - $form->getText("output")); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function disablenotificationsAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Disable notifications')); + $form->addNote(t('Notifications for this object will be disabled.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function enablenotificationsAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Enable notifications')); + $form->addNote(t('Notifications for this object will be enabled.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } public function sendcustomnotificationAction() { - $form = new SendCommand("Send custom notification"); - $form->addTextBox("author", "Author (Your name):", "", true); - $form->addTextBox("comment", "Comment:", "", false, true); - $form->addCheckbox("force", "Forced:", false); - $form->addCheckbox("broadcast", "Broadcast:", false); + $form = new CustomNotification(); + $form->setRequest($this->getRequest()); + $this->view->form = $form; - if ($this->_request->isPost()) { - if ($form->isValid()) { - $comment = new Comment($form->getText("author"), $form->getText("comment")); - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - - if ($form->isChecked("force")) { - $this->target->sendForcedCustomNotification($targets, $comment, - $form->isChecked("broadcast")); - } else { - $this->target->sendCustomNotification($targets, $comment, - $form->isChecked("broadcast")); - } - } - } else { - $form->getElement("author")->setValue(Manager::getInstance()->getUser()->getUsername()); - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } - public function delaynotificationAction() + public function scheduledowntimeAction() { - $form = new SendCommand("Delay a notification"); - $form->addNumberBox("delay", "Notification delay (minutes from now):"); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->delayNotification($targets, $form->getNumber("delay")); - } - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + } + + public function scheduledowntimeswithchildrenAction() + { + + } + + public function removedowntimeswithchildrenAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Remove downtime(s)')); + $form->addNote(t('Remove downtime(s) from this host and its services.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function disablenotificationswithchildrenAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Disable notifications')); + $form->addNote(t('Notifications for this host and its services will be disabled.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function enablenotificationswithchildrenAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Enable notifications')); + $form->addNote(t('Notifications for this host and its services will be enabled.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function reschedulenextcheckwithchildrenAction() + { + $form = new RescheduleNextCheck(); + $form->setRequest($this->getRequest()); + + $form->setWithChildred(true); + + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function disableactivecheckswithchildrenAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Disable active checks')); + $form->addNote(t('Disable active checks for this host and its services.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function enableactivecheckswithchildrenAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Enable active checks')); + $form->addNote(t('Enable active checks for this host and its services.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function disableeventhandlerAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Disable event handler')); + $form->addNote(t('Disable event handler for this object.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function enableeventhandlerAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Enable event handler')); + $form->addNote(t('Enable event handler for this object.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function disableflapdetectionAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Disable flapping detection')); + $form->addNote(t('Disable flapping detection for this object.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); + } + } + + public function enableflapdetectionAction() + { + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Enable flapping detection')); + $form->addNote(t('Enable flapping detection for this object.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } public function addcommentAction() { - $form = new SendCommand("Add comment"); - $form->addTextBox("author", "Author (Your name):", "", true); - $form->addTextBox("comment", "Comment:", "", false, true); - $form->addCheckbox("persistent", "Persistent:", false); + $form = new CommentForm(); + $form->setRequest($this->getRequest()); - if ($this->_request->isPost()) { - if ($form->isValid()) { - $comment = new Comment($form->getText("author"), $form->getText("comment"), - $form->isChecked("persistent")); - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->addComment($targets, $comment); - } - } else { - $form->getElement("author")->setValue(Manager::getInstance()->getUser()->getUsername()); - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } - public function deletecommentAction() + public function resetattributesAction() { - $form = new SendCommand("Delete comment"); - // @TODO: How should this form look like? + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Reset attributes')); + $form->addNote(t('Reset modified attributes to its default.')); + $this->view->form = $form; - if ($this->_request->isPost()) { - if ($form->isValid()) { - $comments = $form->getValue("comments"); - if ($comments) { - // @TODO: Which data structure should be used to transmit comment details? - $this->target->removeComment($comments); - } else { - $targets = $this->selectCommandTargets($form->getHosts(), $form->getServices()); - $this->target->removeComment($targets); - } - } - } else { - $comments = $this->getParameter("comments", false); - if ($comments) { - // @TODO: Which data structure should be used to transmit comment details? - } else { - $form->setServices($this->getParameter("services", false)); - $form->setHosts($this->getParameter("hosts")); - } - - $form->setAction($this->view->url()); - $form->addSubmitButton("Commit"); - $this->view->form = $form; + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } - public function sendDeletecomment() + public function acknowledgeproblemAction() { - if ($this->_request->getPost("comments")) { - $comments = array(); - foreach ($this->_request->getPost("comments") as $id => $content) { - $comment = new StdClass(); - $comment->comment_id = $id; - $value = explode(";", $content, 2); - $comment->host_name = $value[0]; - if (isset($value[1])) { - $comment->service_description = $value[1]; - } - $comments[] = $comment; - } - $this->target->removeComment($comments); - } else { - $this->target->removeComment($this->selectCommandTargets()); + $form = new Acknowledge(); + $form->setRequest($this->getRequest()); + + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } - public function sendDeletedowntime() + public function removeacknowledgementAction() { - if ($this->_request->getPost("downtimes")) { - $downtimes = array(); - foreach ($this->_request->getPost("comments") as $id => $content) { - $downtime = new StdClass(); - $downtime->downtime_id = $id; - $value = explode(";", $content, 2); - $downtime->host_name = $value[0]; - if (isset($value[1])) { - $downtime->service_description = $value[1]; - } - $downtimes[] = $downtime; - } - $this->target->removeDowntime($downtimes); - } else { - $this->target->removeDowntime($this->selectCommandTargets()); + $form = new Confirmation(); + $form->setRequest($this->getRequest()); + $form->setSubmitLabel(t('Remove problem acknowledgement')); + $form->addNote(t('Remove problem acknowledgement for this object.')); + $this->view->form = $form; + + if ($form->isValid($this->getRequest()) && $this->getRequest()->isPost()) { + throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__); } } + + public function delaynotificationAction() + { + + } + + public function removedowntimeAction() + { + // DOWNTIME ID + } } diff --git a/modules/monitoring/application/forms/Command/AbstractCommand.php b/modules/monitoring/application/forms/Command/AbstractCommand.php new file mode 100644 index 000000000..d00354b0c --- /dev/null +++ b/modules/monitoring/application/forms/Command/AbstractCommand.php @@ -0,0 +1,202 @@ + +* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 +* @author Icinga Development Team +*/ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Monitoring\Form\Command; + +use Icinga\Web\Form; +use Icinga\Web\Form\Element\Note; +use Zend_Form_Element_Hidden; + +/** + * Class AbstractCommand + */ +abstract class AbstractCommand extends Form +{ + /** + * Label for submit button + * + * If omitted, no button will be shown. + * + * @var string + */ + private $submitLabel; + + /** + * Label for cancel button + * + * If omitted, no button will be shown. + * + * @var string + */ + private $cancelLabel; + + /** + * Array of messages + * @var string[] + */ + private $notes = array(); + + /** + * Setter for cancel label + * @param string $cancelLabel + */ + public function setCancelLabel($cancelLabel) + { + $this->cancelLabel = $cancelLabel; + } + + /** + * Getter for cancel label + * @return string + */ + public function getCancelLabel() + { + return $this->cancelLabel; + } + + /** + * Setter for submit label + * @param string $submitLabel + */ + public function setSubmitLabel($submitLabel) + { + $this->submitLabel = $submitLabel; + } + + /** + * Getter for submit label + * @return string + */ + public function getSubmitLabel() + { + return $this->submitLabel; + } + + /** + * Add message to stack + * @param string $message + */ + public function addNote($message) + { + $this->notes[] = $message; + } + + /** + * Purge messages from stack + */ + public function purgeNotes() + { + $this->notes = array(); + } + + /** + * Getter for notes + * @return string[] + */ + public function getNotes() + { + return $this->notes; + } + + /** + * Add elements to this form (used by extending classes) + */ + protected function create() + { + if (count($this->getNotes())) { + foreach ($this->getNotes() as $nodeid => $note) { + $element = new Note( + array( + 'name' => 'note_'. $nodeid, + 'value' => $note + ) + ); + $this->addElement($element); + } + } + + if ($this->getCancelLabel()) { + $cancelLabel = new \Zend_Form_Element_Reset( + array( + 'name' => 'reset', + 'label' => $this->getCancelLabel(), + 'class' => 'btn pull-right' + ) + ); + $this->addElement($cancelLabel); + } + + if ($this->getSubmitLabel()) { + $submitButton = new \Zend_Form_Element_Submit( + array( + 'name' => 'submit', + 'label' => $this->getSubmitLabel(), + 'class' => 'btn btn-primary pull-right' + ) + ); + $this->addElement($submitButton); + } + } + + /** + * Get the author name + * TODO(mh): This should work on the request, at present it's fix + */ + protected function getAuthorName() + { + return 'Iwan IV. Wassiljewitsch, der Schreckliche'; + } + + /** + * Creator for author field + * @return Zend_Form_Element_Hidden + */ + protected function createAuthorField() + { + $authorName = $this->getAuthorName(); + + $authorField = new Zend_Form_Element_Hidden( + array( + 'name' => 'author', + 'value' => $authorName, + 'label' => t('Author name') + ) + ); + + $authorField->addDecorator( + 'Callback', + array( + 'callback' => function () use ($authorName) { + return sprintf('%s', $authorName); + } + ) + ); + + return $authorField; + } +} \ No newline at end of file diff --git a/modules/monitoring/application/forms/Command/Acknowledge.php b/modules/monitoring/application/forms/Command/Acknowledge.php new file mode 100644 index 000000000..ecf4c2315 --- /dev/null +++ b/modules/monitoring/application/forms/Command/Acknowledge.php @@ -0,0 +1,85 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Monitoring\Form\Command; + +/** + * Form for acknowledge commands + */ +class Acknowledge extends AbstractCommand +{ + /** + * Interface method to build the form + * @see Form::create() + */ + protected function create() + { + $this->addElement($this->createAuthorField()); + + $this->addElement( + 'textarea', + 'comment', + array( + 'label' => t('Comment'), + 'rows' => 4 + ) + ); + + $this->addElement( + 'checkbox', + 'persistent', + array( + 'label' => t('Persistent comment'), + 'value' => false + ) + ); + + $this->addElement( + 'checkbox', + 'sticky', + array( + 'label' => t('Sticky acknowledgement'), + 'value' => false + ) + ); + + $this->addElement( + 'checkbox', + 'notify', + array( + 'label' => t('Send notification'), + 'value' => false + ) + ); + + $this->setSubmitLabel(t('Acknowledge problem')); + + parent::create(); + } + +} \ No newline at end of file diff --git a/modules/monitoring/application/forms/Command/Comment.php b/modules/monitoring/application/forms/Command/Comment.php new file mode 100644 index 000000000..d0a83f771 --- /dev/null +++ b/modules/monitoring/application/forms/Command/Comment.php @@ -0,0 +1,63 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Monitoring\Form\Command; + +class Comment extends AbstractCommand +{ + /** + * Interface method to build the form + * @see Form::create() + */ + protected function create() + { + $this->addElement($this->createAuthorField()); + + $this->addElement( + 'textarea', + 'comment', + array( + 'label' => t('Comment'), + 'rows' => 4 + ) + ); + + $this->addElement( + 'checkbox', + 'persistent', + array( + 'label' => t('Persistent'), + 'value' => false + ) + ); + + $this->setSubmitLabel(t('Post comment')); + + parent::create(); + } +} \ No newline at end of file diff --git a/modules/monitoring/application/forms/Command/Confirmation.php b/modules/monitoring/application/forms/Command/Confirmation.php new file mode 100644 index 000000000..0f555da2b --- /dev/null +++ b/modules/monitoring/application/forms/Command/Confirmation.php @@ -0,0 +1,38 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Monitoring\Form\Command; + +/** + * Simple confirmation form + * + * Exist to make the abstract form concrete. + */ +class Confirmation extends AbstractCommand +{ +} diff --git a/modules/monitoring/application/forms/Command/CustomNotification.php b/modules/monitoring/application/forms/Command/CustomNotification.php new file mode 100644 index 000000000..0cf1a344b --- /dev/null +++ b/modules/monitoring/application/forms/Command/CustomNotification.php @@ -0,0 +1,75 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Monitoring\Form\Command; + +use Zend_Form_Element_Hidden; + +/** + * For for command CustomNotification + */ +class CustomNotification extends AbstractCommand +{ + /** + * Interface method to build the form + * @see Form::create() + */ + protected function create() + { + $this->addElement($this->createAuthorField()); + + $this->addElement( + 'textarea', + 'comment', + array( + 'label' => t('Comment'), + 'rows' => 4 + ) + ); + + $this->addElement( + 'checkbox', + 'force', + array( + 'label' => t('Forced') + ) + ); + + $this->addElement( + 'checkbox', + 'broadcast', + array( + 'label' => t('Broadcast') + ) + ); + + $this->setSubmitLabel(t('Send custom notification')); + + parent::create(); + } +} diff --git a/modules/monitoring/application/forms/Command/RescheduleNextCheck.php b/modules/monitoring/application/forms/Command/RescheduleNextCheck.php new file mode 100644 index 000000000..be864cb6f --- /dev/null +++ b/modules/monitoring/application/forms/Command/RescheduleNextCheck.php @@ -0,0 +1,100 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Monitoring\Form\Command; + +use Icinga\Web\Form\Element\DateTime; +use Zend_Form_Element_Checkbox; +use DateTime as PhpDateTime; + +/** + * Form for RescheduleNextCheck + */ +class RescheduleNextCheck extends AbstractCommand +{ + + private $withChildren = false; + + /** + * Setter for withChildren + * @param bool $flag + */ + public function setWithChildred($flag = true) + { + $this->withChildren = $flag; + } + + /** + * Getter for withChildren + * @return bool + */ + public function getWithChildren() + { + return $this->withChildren; + } + + /** + * Interface method to build the form + * @see Form::create() + */ + protected function create() + { + + $now = new PhpDateTime(); + + $dateElement = new DateTime( + array( + 'name' => 'checktime', + 'label' => t('Check time'), + 'value' => $now->format('Y-m-d H:i:s') + ) + ); + + $this->addElement($dateElement); + + $checkBox = new Zend_Form_Element_Checkbox( + array( + 'name' => 'forcecheck', + 'label' => t('Force check'), + 'value' => true + ) + ); + + $this->addElement($checkBox); + + if ($this->getWithChildren() === true) { + $this->addNote(t('Reschedule next check for this host and its services.')); + } else { + $this->addNote(t('Reschedule next check for this object.')); + } + + $this->setSubmitLabel(t('Reschedule check')); + + parent::create(); + } +} diff --git a/modules/monitoring/application/forms/Command/SubmitPassiveCheckResult.php b/modules/monitoring/application/forms/Command/SubmitPassiveCheckResult.php new file mode 100644 index 000000000..676388451 --- /dev/null +++ b/modules/monitoring/application/forms/Command/SubmitPassiveCheckResult.php @@ -0,0 +1,151 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Monitoring\Form\Command; + +use Icinga\Exception\ProgrammingError; + +/** + * Form for command SubmitPassiveCheckResult + */ +class SubmitPassiveCheckResult extends AbstractCommand +{ + /** + * Type constant for host form + */ + const TYPE_HOST = 'host'; + + /** + * Type constant for service form + */ + const TYPE_SERVICE = 'service'; + + private static $options = array(); + + /** + * Type of form + * @var string + */ + private $type; + + /** + * Setup plugin states + */ + public function init() + { + if (!count(self::$options)) { + self::$options = array( + self::TYPE_HOST => array( + 0 => t('UP'), + 1 => t('DOWN'), + 2 => t('UNREACHABLE') + ), + self::TYPE_SERVICE => array( + 0 => t('OK'), + 1 => t('WARNING'), + 2 => t('CRITICAL'), + 3 => t('UNKNOWN') + ) + ); + } + + parent::init(); + } + + + /** + * Setter for type + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * Getter for type + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Return array of options + * @return array + * @throws \Icinga\Exception\ProgrammingError + */ + private function getOptions() + { + if (in_array($this->getType(), array(self::TYPE_HOST, self::TYPE_SERVICE)) === false) { + throw new ProgrammingError('Type is not valid'); + } + + return self::$options[$this->getType()]; + } + + /** + * Interface method to build the form + * @see Form::create() + */ + protected function create() + { + + $this->addElement( + 'select', + 'pluginstate', + array( + 'label' => t('Plugin state'), + 'multiOptions' => $this->getOptions() + ) + ); + + $this->addElement( + 'textarea', + 'checkoutput', + array( + 'label' => t('Check output'), + 'rows' => 2 + ) + ); + + $this->addElement( + 'textarea', + 'performancedata', + array( + 'label' => t('Performance data'), + 'rows' => 2 + ) + ); + + $this->setSubmitLabel(t('Submit passive check result')); + + parent::create(); + } +} diff --git a/modules/monitoring/application/views/scripts/command/addcomment.phtml b/modules/monitoring/application/views/scripts/command/addcomment.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/addcomment.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/delaynotification.phtml b/modules/monitoring/application/views/scripts/command/delaynotification.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/delaynotification.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/deleteacknowledgement.phtml b/modules/monitoring/application/views/scripts/command/deleteacknowledgement.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/deleteacknowledgement.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/deletecomment.phtml b/modules/monitoring/application/views/scripts/command/deletecomment.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/deletecomment.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/disableactivechecks.phtml b/modules/monitoring/application/views/scripts/command/disableactivechecks.phtml deleted file mode 100644 index 3ded5a7be..000000000 --- a/modules/monitoring/application/views/scripts/command/disableactivechecks.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> diff --git a/modules/monitoring/application/views/scripts/command/disableeventhandling.phtml b/modules/monitoring/application/views/scripts/command/disableeventhandling.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/disableeventhandling.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/disableflapdetection.phtml b/modules/monitoring/application/views/scripts/command/disableflapdetection.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/disableflapdetection.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/disablenotifications.phtml b/modules/monitoring/application/views/scripts/command/disablenotifications.phtml deleted file mode 100644 index 3ded5a7be..000000000 --- a/modules/monitoring/application/views/scripts/command/disablenotifications.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> diff --git a/modules/monitoring/application/views/scripts/command/disablepassivechecks.phtml b/modules/monitoring/application/views/scripts/command/disablepassivechecks.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/disablepassivechecks.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/enableactivechecks.phtml b/modules/monitoring/application/views/scripts/command/enableactivechecks.phtml deleted file mode 100644 index 3ded5a7be..000000000 --- a/modules/monitoring/application/views/scripts/command/enableactivechecks.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> diff --git a/modules/monitoring/application/views/scripts/command/enableeventhandling.phtml b/modules/monitoring/application/views/scripts/command/enableeventhandling.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/enableeventhandling.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/enableflapdetection.phtml b/modules/monitoring/application/views/scripts/command/enableflapdetection.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/enableflapdetection.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/enablenotifications.phtml b/modules/monitoring/application/views/scripts/command/enablenotifications.phtml deleted file mode 100644 index 3ded5a7be..000000000 --- a/modules/monitoring/application/views/scripts/command/enablenotifications.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> diff --git a/modules/monitoring/application/views/scripts/command/enablepassivechecks.phtml b/modules/monitoring/application/views/scripts/command/enablepassivechecks.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/enablepassivechecks.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/placeacknowledgement.phtml b/modules/monitoring/application/views/scripts/command/placeacknowledgement.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/placeacknowledgement.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/renderform.phtml b/modules/monitoring/application/views/scripts/command/renderform.phtml new file mode 100644 index 000000000..eb10f07da --- /dev/null +++ b/modules/monitoring/application/views/scripts/command/renderform.phtml @@ -0,0 +1,4 @@ +
+ form; ?> +
+
\ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/restart.phtml b/modules/monitoring/application/views/scripts/command/restart.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/restart.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/schedulecheck.phtml b/modules/monitoring/application/views/scripts/command/schedulecheck.phtml deleted file mode 100644 index 3ded5a7be..000000000 --- a/modules/monitoring/application/views/scripts/command/schedulecheck.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> diff --git a/modules/monitoring/application/views/scripts/command/sendcustomnotification.phtml b/modules/monitoring/application/views/scripts/command/sendcustomnotification.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/sendcustomnotification.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/startobsessing.phtml b/modules/monitoring/application/views/scripts/command/startobsessing.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/startobsessing.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/stopobsessing.phtml b/modules/monitoring/application/views/scripts/command/stopobsessing.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/stopobsessing.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/submitcheckresult.phtml b/modules/monitoring/application/views/scripts/command/submitcheckresult.phtml deleted file mode 100644 index 4bae1498a..000000000 --- a/modules/monitoring/application/views/scripts/command/submitcheckresult.phtml +++ /dev/null @@ -1 +0,0 @@ -form ?> \ No newline at end of file