Merge branch 'feature/comment-overview-4714'

resolves #4714
This commit is contained in:
Eric Lippmann 2013-10-09 09:39:00 +02:00
commit a1ac44362f
16 changed files with 1053 additions and 129 deletions

View File

@ -9,12 +9,13 @@
;Changes.route = "/monitoring/list/services?sort=service_last_state_change" ;Changes.route = "/monitoring/list/services?sort=service_last_state_change"
;_1 = 1 ;Spacer after this section ;_1 = 1 ;Spacer after this section
Hosts = "/monitoring/list/hosts" Hosts = "/monitoring/list/hosts"
Services = "/monitoring/list/services" Services = "/monitoring/list/services"
Downtimes = "/monitoring/list/downtimes" Downtimes = "/monitoring/list/downtimes"
Notifications = "/monitoring/list/notifications" Notifications = "/monitoring/list/notifications"
Contacts = "/monitoring/list/contacts" Comments = "/monitoring/list/comments"
Contact Groups = "/monitoring/list/contactgroups" Contacts = "/monitoring/list/contacts"
Contact Groups = "/monitoring/list/contactgroups"
;Remove component as of #4583 since it's not working ;Remove component as of #4583 since it's not working
;Summaries = "/monitoring/summary/group/by/hostgroup" ;Summaries = "/monitoring/summary/group/by/hostgroup"

View File

@ -27,24 +27,25 @@
*/ */
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
use \Icinga\Application\Icinga; use Icinga\Application\Icinga;
use \Icinga\Application\Config; use Icinga\Application\Config;
use \Icinga\Application\Logger; use Icinga\Application\Logger;
use \Icinga\Web\Form; use Icinga\Module\Monitoring\Form\Command\SingleArgumentCommandForm;
use \Icinga\Web\Controller\ActionController; use Icinga\Web\Form;
use \Icinga\Protocol\Commandpipe\CommandPipe; use Icinga\Web\Controller\ActionController;
use \Icinga\Exception\ConfigurationError; use Icinga\Protocol\Commandpipe\CommandPipe;
use \Icinga\Exception\MissingParameterException; use Icinga\Exception\ConfigurationError;
use \Icinga\Module\Monitoring\Backend; use Icinga\Exception\MissingParameterException;
use \Icinga\Module\Monitoring\Form\Command\AcknowledgeForm; use Icinga\Module\Monitoring\Backend;
use \Icinga\Module\Monitoring\Form\Command\CommentForm; use Icinga\Module\Monitoring\Form\Command\AcknowledgeForm;
use \Icinga\Module\Monitoring\Form\Command\CommandForm; use Icinga\Module\Monitoring\Form\Command\CommentForm;
use \Icinga\Module\Monitoring\Form\Command\CommandWithIdentifierForm; use Icinga\Module\Monitoring\Form\Command\CommandForm;
use \Icinga\Module\Monitoring\Form\Command\CustomNotificationForm; use Icinga\Module\Monitoring\Form\Command\CommandWithIdentifierForm;
use \Icinga\Module\Monitoring\Form\Command\DelayNotificationForm; use Icinga\Module\Monitoring\Form\Command\CustomNotificationForm;
use \Icinga\Module\Monitoring\Form\Command\RescheduleNextCheckForm; use Icinga\Module\Monitoring\Form\Command\DelayNotificationForm;
use \Icinga\Module\Monitoring\Form\Command\ScheduleDowntimeForm; use Icinga\Module\Monitoring\Form\Command\RescheduleNextCheckForm;
use \Icinga\Module\Monitoring\Form\Command\SubmitPassiveCheckResultForm; use Icinga\Module\Monitoring\Form\Command\ScheduleDowntimeForm;
use Icinga\Module\Monitoring\Form\Command\SubmitPassiveCheckResultForm;
/** /**
* Class Monitoring_CommandController * Class Monitoring_CommandController
@ -100,7 +101,17 @@ class Monitoring_CommandController extends ActionController
if ($this->form->isSubmittedAndValid()) { if ($this->form->isSubmittedAndValid()) {
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout()->disableLayout(); $this->_helper->layout()->disableLayout();
$requested = strtolower($this->_request->getHeader('x-requested-with'));
$ajaxRequest = $requested === 'xmlhttprequest' ? true : false;
if ($this->_request->getHeader('referer') && $ajaxRequest === false) {
$this->redirect($this->_request->getHeader('referer'));
}
return;
} }
$this->view->form = $this->form; $this->view->form = $this->form;
} }
parent::postDispatch(); parent::postDispatch();
@ -169,8 +180,26 @@ class Monitoring_CommandController extends ActionController
$fields[] = "service_description"; $fields[] = "service_description";
$fields[] = "service_state"; $fields[] = "service_state";
} }
$query = Backend::getInstance($this->_getParam('backend'))->select()->from("status", $fields);
return $query->applyFilters($filter)->fetchAll(); // Implemented manuall search because api is not ready.
// @TODO Implement this using the database api #4663 (mh)
$query = Backend::createBackend($this->_getParam('backend'))->select()->from("status", $fields);
$data = $query->fetchAll();
$out = array();
foreach ($data as $o) {
$test = (array)$o;
if ($test['host_name'] === $hostname) {
if (!$servicename) {
$out[] = (object) $o;
} elseif ($servicename && strtolower($test['service_description']) === strtolower($servicename)) {
$out[] = (object) $o;
}
}
}
return $out;
} catch (\Exception $e) { } catch (\Exception $e) {
Logger::error( Logger::error(
"CommandController: SQL Query '%s' failed (message %s) ", "CommandController: SQL Query '%s' failed (message %s) ",
@ -180,6 +209,29 @@ class Monitoring_CommandController extends ActionController
} }
} }
/**
* Convert other params into valid command structure
*
* @param array $supported Array of supported parameter names
* @param array $params Parameters from request
*
* @return array Return
*/
private function selectOtherTargets(array $supported, array $params)
{
$others = array_diff_key($supported, array('host' => true, 'service' => true));
$otherParams = array_intersect_key($params, $others);
$out = array();
foreach ($otherParams as $name => $value) {
$data = new stdClass();
$data->{$name} = $value;
$out[] = $data;
}
return $out;
}
/** /**
* Displays a list of all commands * Displays a list of all commands
* *
@ -208,25 +260,24 @@ class Monitoring_CommandController extends ActionController
*/ */
private function setSupportedParameters(array $supported) private function setSupportedParameters(array $supported)
{ {
$given = array_intersect_key(array_flip($supported), $this->getRequest()->getParams()); $objects = array();
$supported = array_flip($supported);
$given = array_intersect_key($supported, $this->getRequest()->getParams());
if (empty($given)) { if (empty($given)) {
throw new \Exception('Missing parameter, supported: '.implode(', ', $supported)); throw new \Exception('Missing parameter, supported: '.implode(', ', $supported));
} }
if (isset($given["host"])) {
$this->view->objects = $this->selectCommandTargets(!in_array("service", $supported)); if (isset($given['host'])) {
if (empty($this->view->objects)) { $objects = $this->selectCommandTargets(!in_array("service", $supported));
if (empty($objects)) {
throw new \Exception("No objects found for your command"); throw new \Exception("No objects found for your command");
} }
} elseif (in_array("downtimeid", $supported)) {
$this->view->objects = array();
$downtimes = $this->getParam("downtimeid");
if (!is_array($downtimes)) {
$downtimes = array($downtimes);
}
foreach ($downtimes as $downtimeId) {
$this->view->objects[] = (object) array("downtime_id" => $downtimeId);
}
} }
$this->view->objects = $objects;
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -239,14 +290,16 @@ class Monitoring_CommandController extends ActionController
public function disableactivechecksAction() public function disableactivechecksAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setCommand('DISABLE_HOST_CHECK', 'DISABLE_SVC_CHECK');
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable Active Checks')); $form->setSubmitLabel(t('Disable Active Checks'));
$form->addNote(t('Disable active checks for this object.')); $form->addNote(t('Disable active checks for this object.'));
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->disableActiveChecks($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -256,14 +309,16 @@ class Monitoring_CommandController extends ActionController
public function enableactivechecksAction() public function enableactivechecksAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setCommand('ENABLE_HOST_CHECK', 'ENABLE_SVC_CHECK');
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable active checks')); $form->setSubmitLabel(t('Enable Active Checks'));
$form->addNote(t('Enable active checks for this object.')); $form->addNote(t('Enable active checks for this object.'));
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->enableActiveChecks($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -312,14 +367,15 @@ class Monitoring_CommandController extends ActionController
public function stopobsessingAction() public function stopobsessingAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Stop obsessing')); $form->setSubmitLabel(t('Stop obsessing'));
$form->addNote(t('Stop obsessing over this object.')); $form->addNote(t('Stop obsessing over this object.'));
$form->setCommand('STOP_OBSESSING_OVER_HOST', 'STOP_OBSESSING_OVER_SVC');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->stopObsessing($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -329,14 +385,15 @@ class Monitoring_CommandController extends ActionController
public function startobsessingAction() public function startobsessingAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Start obsessing')); $form->setSubmitLabel(t('Start obsessing'));
$form->addNote(t('Start obsessing over this object.')); $form->addNote(t('Start obsessing over this object.'));
$form->setCommand('START_OBSESSING_OVER_HOST', 'START_OBSESSING_OVER_SVC');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->startObsessing($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -346,14 +403,15 @@ class Monitoring_CommandController extends ActionController
public function stopacceptingpassivechecksAction() public function stopacceptingpassivechecksAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Stop Accepting Passive Checks')); $form->setSubmitLabel(t('Stop Accepting Passive Checks'));
$form->addNote(t('Passive checks for this object will be omitted.')); $form->addNote(t('Passive checks for this object will be omitted.'));
$form->setCommand('STOP_ACCEPTING_PASSIVE_HOST_CHECKS', 'STOP_ACCEPTING_PASSIVE_SVC_CHECKS');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->disablePassiveChecks($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -363,14 +421,15 @@ class Monitoring_CommandController extends ActionController
public function startacceptingpassivechecksAction() public function startacceptingpassivechecksAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Start Accepting Passive Checks')); $form->setSubmitLabel(t('Start Accepting Passive Checks'));
$form->addNote(t('Passive checks for this object will be accepted.')); $form->addNote(t('Passive checks for this object will be accepted.'));
$form->setCommand('START_ACCEPTING_PASSIVE_HOST_CHECKS', 'START_ACCEPTING_PASSIVE_SVC_CHECKS');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->enableActiveChecks($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -380,14 +439,15 @@ class Monitoring_CommandController extends ActionController
public function disablenotificationsAction() public function disablenotificationsAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable Notifications')); $form->setSubmitLabel(t('Disable Notifications'));
$form->addNote(t('Notifications for this object will be disabled.')); $form->addNote(t('Notifications for this object will be disabled.'));
$form->setCommand('DISABLE_HOST_NOTIFICATIONS', 'DISABLE_SVC_NOTIFICATIONS');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->disableNotifications($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -396,14 +456,16 @@ class Monitoring_CommandController extends ActionController
*/ */
public function enablenotificationsAction() public function enablenotificationsAction()
{ {
$form = new CommandForm(); $this->setSupportedParameters(array('host', 'service'));
$form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable Notifications')); $form->setSubmitLabel(t('Enable Notifications'));
$form->addNote(t('Notifications for this object will be enabled.')); $form->addNote(t('Notifications for this object will be enabled.'));
$form->setCommand('ENABLE_HOST_NOTIFICATIONS', 'ENABLE_SVC_NOTIFICATIONS');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->enableNotifications($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -462,14 +524,15 @@ class Monitoring_CommandController extends ActionController
public function removedowntimeswithchildrenAction() public function removedowntimeswithchildrenAction()
{ {
$this->setSupportedParameters(array('host')); $this->setSupportedParameters(array('host'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Remove Downtime(s)')); $form->setSubmitLabel(t('Remove Downtime(s)'));
$form->addNote(t('Remove downtime(s) from this host and its services.')); $form->addNote(t('Remove downtime(s) from this host and its services.'));
$form->setCommand('DEL_DOWNTIME_BY_HOST_NAME', 'DEL_DOWNTIME_BY_HOST_NAME');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->removeDowntime($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -479,15 +542,18 @@ class Monitoring_CommandController extends ActionController
public function disablenotificationswithchildrenAction() public function disablenotificationswithchildrenAction()
{ {
$this->setSupportedParameters(array('host')); $this->setSupportedParameters(array('host'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable Notifications')); $form->setSubmitLabel(t('Disable Notifications'));
$form->addNote(t('Notifications for this host and its services will be disabled.')); $form->addNote(t('Notifications for this host and its services will be disabled.'));
$form->setCommand('DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->disableNotifications($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
$this->target->disableNotificationsForServices($this->view->objects); $form->setCommand('DISABLE_HOST_NOTIFICATIONS', 'DISABLE_SVC_NOTIFICATIONS');
$this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -497,15 +563,17 @@ class Monitoring_CommandController extends ActionController
public function enablenotificationswithchildrenAction() public function enablenotificationswithchildrenAction()
{ {
$this->setSupportedParameters(array('host')); $this->setSupportedParameters(array('host'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable Notifications')); $form->setSubmitLabel(t('Enable Notifications'));
$form->addNote(t('Notifications for this host and its services will be enabled.')); $form->addNote(t('Notifications for this host and its services will be enabled.'));
$form->setCommand('ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->enableNotifications($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
$this->target->enableNotificationsForServices($this->view->objects); $form->setCommand('ENABLE_HOST_NOTIFICATIONS', 'ENABLE_SVC_NOTIFICATIONS');
$this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -533,15 +601,16 @@ class Monitoring_CommandController extends ActionController
public function disableactivecheckswithchildrenAction() public function disableactivecheckswithchildrenAction()
{ {
$this->setSupportedParameters(array('host')); $this->setSupportedParameters(array('host'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable Active Checks')); $form->setSubmitLabel(t('Disable Active Checks'));
$form->addNote(t('Disable active checks for this host and its services.')); $form->addNote(t('Disable active checks for this host and its services.'));
$form->setCommand('DISABLE_HOST_CHECK');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->disableActiveChecks($this->view->objects); // @TODO(mh): Missing child command
$this->target->disableActiveChecksWithChildren($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -551,15 +620,16 @@ class Monitoring_CommandController extends ActionController
public function enableactivecheckswithchildrenAction() public function enableactivecheckswithchildrenAction()
{ {
$this->setSupportedParameters(array('host')); $this->setSupportedParameters(array('host'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable Active Checks')); $form->setSubmitLabel(t('Enable Active Checks'));
$form->addNote(t('Enable active checks for this host and its services.')); $form->addNote(t('Enable active checks for this host and its services.'));
$form->setCommand('ENABLE_HOST_CHECK');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->enableActiveChecks($this->view->objects); // @TODO(mh): Missing child command
$this->target->enableActiveChecksWithChildren($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -569,14 +639,15 @@ class Monitoring_CommandController extends ActionController
public function disableeventhandlerAction() public function disableeventhandlerAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable Event Handler')); $form->setSubmitLabel(t('Disable Event Handler'));
$form->addNote(t('Disable event handler for this object.')); $form->addNote(t('Disable event handler for this object.'));
$form->setCommand('DISABLE_HOST_EVENT_HANDLER', 'DISABLE_SVC_EVENT_HANDLER');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->disableEventHandler($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -586,14 +657,15 @@ class Monitoring_CommandController extends ActionController
public function enableeventhandlerAction() public function enableeventhandlerAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable Event Handler')); $form->setSubmitLabel(t('Enable Event Handler'));
$form->addNote(t('Enable event handler for this object.')); $form->addNote(t('Enable event handler for this object.'));
$form->setCommand('ENABLE_HOST_EVENT_HANDLER', 'ENABLE_SVC_EVENT_HANDLER');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->enableEventHandler($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -603,14 +675,15 @@ class Monitoring_CommandController extends ActionController
public function disableflapdetectionAction() public function disableflapdetectionAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable Flapping Detection')); $form->setSubmitLabel(t('Disable Flapping Detection'));
$form->addNote(t('Disable flapping detection for this object.')); $form->addNote(t('Disable flapping detection for this object.'));
$form->setCommand('DISABLE_HOST_FLAP_DETECTION', 'DISABLE_SVC_FLAP_DETECTION');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->disableFlappingDetection($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -620,14 +693,15 @@ class Monitoring_CommandController extends ActionController
public function enableflapdetectionAction() public function enableflapdetectionAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable Flapping Detection')); $form->setSubmitLabel(t('Enable Flapping Detection'));
$form->addNote(t('Enable flapping detection for this object.')); $form->addNote(t('Enable flapping detection for this object.'));
$form->setCommand('ENABLE_HOST_FLAP_DETECTION', 'ENABLE_SVC_FLAP_DETECTION');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->enableFlappingDetection($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -638,7 +712,7 @@ class Monitoring_CommandController extends ActionController
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommentForm(); $form = new CommentForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->_request);
$this->setForm($form); $this->setForm($form);
@ -647,20 +721,41 @@ class Monitoring_CommandController extends ActionController
} }
} }
/**
* Remove a single comment
*/
public function removecommentAction()
{
$this->setSupportedParameters(array('commentid', 'host', 'service'));
$form = new SingleArgumentCommandForm();
$form->setRequest($this->_request);
$form->setCommand('DEL_HOST_COMMENT', 'DEL_SVC_COMMENT');
$form->setParameterName('commentid');
$form->setSubmitLabel(t('Remove comment'));
$form->setObjectIgnoreFlag(true);
$this->setForm($form);
if ($form->IsSubmittedAndValid() === true) {
$this->target->sendCommand($form->createCommand(), $this->view->objects);
}
}
/** /**
* Handle command resetattributes * Handle command resetattributes
*/ */
public function resetattributesAction() public function resetattributesAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Reset Attributes')); $form->setSubmitLabel(t('Reset Attributes'));
$form->addNote(t('Reset modified attributes to its default.')); $form->addNote(t('Reset modified attributes to its default.'));
$form->setCommand('CHANGE_HOST_MODATTR', 'CHANGE_SVC_MODATTR');
$form->setParameterValue(0);
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->resetAttributes($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }
@ -687,14 +782,15 @@ class Monitoring_CommandController extends ActionController
public function removeacknowledgementAction() public function removeacknowledgementAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$form = new CommandForm(); $form = new SingleArgumentCommandForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Remove Problem Acknowledgement')); $form->setSubmitLabel(t('Remove Problem Acknowledgement'));
$form->addNote(t('Remove problem acknowledgement for this object.')); $form->addNote(t('Remove problem acknowledgement for this object.'));
$form->setCommand('REMOVE_HOST_ACKNOWLEDGEMENT', 'REMOVE_SVC_ACKNOWLEDGEMENT');
$this->setForm($form); $this->setForm($form);
if ($form->IsSubmittedAndValid() === true) { if ($form->IsSubmittedAndValid() === true) {
$this->target->removeAcknowledge($this->view->objects); $this->target->sendCommand($form->createCommand(), $this->view->objects);
} }
} }

View File

@ -45,6 +45,7 @@ use Icinga\Module\Monitoring\DataView\Downtime as DowntimeView;
use Icinga\Module\Monitoring\DataView\Contact as ContactView; use Icinga\Module\Monitoring\DataView\Contact as ContactView;
use Icinga\Module\Monitoring\DataView\Contactgroup as ContactgroupView; use Icinga\Module\Monitoring\DataView\Contactgroup as ContactgroupView;
use Icinga\Module\Monitoring\DataView\HostAndServiceStatus as HostAndServiceStatusView; use Icinga\Module\Monitoring\DataView\HostAndServiceStatus as HostAndServiceStatusView;
use Icinga\Module\Monitoring\DataView\Comment as CommentView;
class Monitoring_ListController extends ActionController class Monitoring_ListController extends ActionController
{ {
@ -306,6 +307,37 @@ class Monitoring_ListController extends ActionController
$this->handleFormatRequest($query); $this->handleFormatRequest($query);
} }
public function commentsAction()
{
$query = CommentView::fromRequest(
$this->_request,
array(
'comment_objecttype_id',
'comment_id',
'comment_data',
'comment_author',
'comment_timestamp',
'comment_type',
'comment_is_persistent',
'comment_expiration_timestamp',
'host_name',
'service_name'
)
)->getQuery();
$this->view->comments = $query->paginate();
$this->setupSortControl(
array(
'comment_timestamp' => 'Comment Timestamp',
'host_service' => 'Host and Service',
'comment_id' => 'Comment Id',
'comment_expires' => 'Expiration Timestamp'
)
);
$this->handleFormatRequest($query);
}
/** /**
* Handle the 'format' and 'view' parameter * Handle the 'format' and 'view' parameter
* *

View File

@ -28,14 +28,15 @@
namespace Icinga\Module\Monitoring\Form\Command; namespace Icinga\Module\Monitoring\Form\Command;
use \Zend_Config; use Zend_Config;
use \Icinga\Web\Form; use Zend_Form_Element_Hidden;
use \Zend_Form_Element_Hidden; use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
use Icinga\Web\Form;
/** /**
* Simple confirmation command * Simple confirmation command
*/ */
class CommandForm extends Form abstract class CommandForm extends Form
{ {
/** /**
* Create an instance name containing hidden field * Create an instance name containing hidden field
@ -126,4 +127,11 @@ class CommandForm extends Form
) )
); );
} }
/**
* Create command object for CommandPipe protocol
*
* @return AcknowledgeCommand
*/
abstract public function createCommand();
} }

View File

@ -0,0 +1,149 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command;
use \Zend_Form_Element_Hidden;
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
use Icinga\Module\Monitoring\Command\SingleArgumentCommand;
/**
* Sending commands to core which only have one value
*/
class SingleArgumentCommandForm extends CommandForm
{
/**
* Name of host command
*
* @var string
*/
private $hostCommand;
/**
* Name of service command
*
* @var string
*/
private $serviceCommand;
/**
* Name of the parameter used as value
*
* @var string
*/
private $parameterName;
/**
* Value of used parameter
*
* @var mixed
*/
private $parameterValue;
/**
* Flag to ignore object name
*
* @var bool
*/
private $ignoreObject = false;
/**
* Set command names
*
* @param string $hostCommand Name of host command
* @param string $serviceCommand Name of service command
*/
public function setCommand($hostCommand, $serviceCommand = null)
{
$this->hostCommand = $hostCommand;
if ($serviceCommand !== null) {
$this->serviceCommand = $serviceCommand;
}
}
/**
* Use an explicit value to send with command
*
* @param mixed $parameterValue
*/
public function setParameterValue($parameterValue)
{
$this->parameterValue = $parameterValue;
}
/**
* Use a form field to take the value from
*
* @param string $parameterName
*/
public function setParameterName($parameterName)
{
$this->parameterName = $parameterName;
}
public function setObjectIgnoreFlag($flag = true)
{
$this->ignoreObject = (bool) $flag;
}
/**
*
*/
protected function create()
{
if ($this->parameterName) {
$field = new Zend_Form_Element_Hidden($this->parameterName);
$value = $this->getRequest()->getParam($field->getName());
$field->setValue($value);
$this->addElement($field);
}
parent::create();
}
/**
* Create command object for CommandPipe protocol
*
* @return SingleArgumentCommand
*/
public function createCommand()
{
$command = new SingleArgumentCommand();
$command->setCommand($this->hostCommand, $this->serviceCommand);
if ($this->parameterValue !== null) {
$command->setValue($this->parameterValue);
} else {
$command->setValue($this->getValue($this->parameterName));
}
$command->setObjectIgnoreFlag($this->ignoreObject);
return $command;
}
}

View File

@ -0,0 +1,45 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Icinga;
use Icinga\Web\Form;
/**
* Helper to build inline html command forms
*/
class Zend_View_Helper_CommandForm extends Zend_View_Helper_Abstract
{
/**
* Creates a simple form without additional input fields
*
* @param string $commandName Name of command (icinga 2 web name)
* @param string $submitLabel Label of submit button
* @param array $arguments Add parameter as hidden fields
*
* @return string Html form content
*/
public function simpleForm($commandName, $submitLabel, array $arguments = array())
{
$form = new Form();
$form->setIgnoreChangeDiscarding(true);
$form->setAttrib('data-icinga-component', 'app/ajaxPostSubmitForm');
$form->setRequest(Zend_Controller_Front::getInstance()->getRequest());
$form->setSubmitLabel($submitLabel !== null ? $submitLabel : 'Submit');
$form->setAction($this->view->href('monitoring/command/' . $commandName));
foreach ($arguments as $elementName => $elementValue) {
$hiddenField = new Zend_Form_Element_Hidden($elementName);
$hiddenField->setValue($elementValue);
$form->addElement($hiddenField);
}
return $form->render();
}
}
// @codingStandardsIgnoreStop

View File

@ -0,0 +1,130 @@
<?php
$dateHelper = $this->getHelper('DateFormat');
$commandHelper = $this->getHelper('CommandForm');
?>
<?= $this->tabs->render($this); ?>
<?php
$viewHelper = $this->getHelper('MonitoringState');
?>
<h1>Comments</h1>
<div data-icinga-component="app/mainDetailGrid">
<?= $this->sortControl->render($this); ?>
<?= $this->paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?>
<table class="table table-condensed">
<thead>
<tr>
<th colspan="2">Comment Id</th>
<th>Type</th>
<th>Host</th>
<th>Service</th>
<th>Entry Time</th>
<th>Author</th>
<th>Comment</th>
<th>Persistent</th>
<th colspan="2">Expires</th>
</tr>
</thead>
<tbody>
<?php foreach ($comments as $comment): ?>
<?php
$objectType = ($comment->comment_objecttype_id === '1') ? 'host' : 'service';
$objectName = ($objectType === 'host') ? $comment->host_name : $comment->service_name;
$hrefParameters = array(
$objectType => $objectName,
'comment_id' => $comment->comment_id
);
if ($objectType === 'service') {
$hrefParameters['host'] = $comment->host_name;
}
$detailLink = $this->href(
'monitoring/show/' . $objectType,
$hrefParameters
);
$hostLink = $this->href(
'monitoring/show/host',
array(
'host' => $comment->host_name
)
);
?>
<tr <?= ($this->activeRowHref === $detailLink) ? 'class="active"' : ''; ?>>
<td>
<a class="hidden" href="<?= $detailLink; ?>"></a>
<?php if ($comment->comment_objecttype_id === '1'): ?>
{{{ICON_HOST}}}
<?php elseif ($comment->comment_objecttype_id === '2'): ?>
{{{ICON_SERVICE}}}
<?php endif; ?>
</td>
<td>
<?= $comment->comment_id; ?>
</td>
<td>
<?= $comment->comment_type; ?>
</td>
<td>
<a href="<?= $hostLink ?>">
<?= $comment->host_name; ?>
</a>
</td>
<td>
<?php if ($comment->service_name): ?>
<a href="<?= $detailLink ?>">
<?= $comment->service_name ?>
</a>
<?php else: ?>
&nbsp;
<?php endif; ?>
</td>
<td>
<?= $dateHelper->formatDateTime($comment->comment_timestamp); ?>
</td>
<td>
<?= $comment->comment_author; ?>
</td>
<td>
<span data-icinga-component="app/ellipsisText">
<?= $comment->comment_data; ?>
</span>
</td>
<td>
<?= ($comment->comment_is_persistent === '1') ? 'Yes' : 'No'; ?>
</td>
<td>
<?=
($comment->comment_expiration_timestamp) ?
$dateHelper->formatDateTime($comment->comment_expiration_timestamp) :
'Never';
?>
</td>
<td>
<?php
$data = array(
'commentid' => $comment->comment_id,
'host' => $comment->host_name
);
if ($objectType === 'service') {
$data['service'] = $comment->service_name;
}
echo $commandHelper->simpleForm(
'removecomment',
'Remove Comment',
$data
);
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?= $this->paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?>
</div>

View File

@ -1,23 +1,61 @@
<?php <?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Backend\Ido\Query; namespace Icinga\Module\Monitoring\Backend\Ido\Query;
/**
* Query map for comments
*/
class CommentQuery extends AbstractQuery class CommentQuery extends AbstractQuery
{ {
protected $columnMap = array( protected $columnMap = array(
'comments' => array( 'comments' => array(
'comment_data' => 'cm.comment_data', 'comment_objecttype_id' => 'co.objecttype_id',
'comment_author' => 'cm.author_name', 'comment_id' => 'cm.internal_comment_id',
//'comment_timestamp' => 'UNIX_TIMESTAMP(cm.entry_time)', 'comment_internal_id' => 'cm.internal_comment_id',
'comment_timestamp' => 'UNIX_TIMESTAMP(cm.comment_time)', 'comment_data' => 'cm.comment_data',
'comment_type' => "CASE cm.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'downtime' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END", 'comment_author' => 'cm.author_name COLLATE latin1_general_ci',
'comment_timestamp' => 'UNIX_TIMESTAMP(cm.comment_time)',
'comment_type' => "CASE cm.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'downtime' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END",
'comment_is_persistent' => 'cm.is_persistent',
'comment_expiration_timestamp' => 'CASE cm.expires WHEN 1 THEN UNIX_TIMESTAMP(cm.expiration_time) ELSE NULL END'
), ),
'hosts' => array( 'hosts' => array(
'host_name' => 'ho.name1', 'host_name' => 'ho.name1 COLLATE latin1_general_ci',
'host' => 'ho.name1 COLLATE latin1_general_ci',
), ),
'services' => array( 'services' => array(
'service_host_name' => 'so.name1 COLLATE latin1_general_ci', 'service_host_name' => 'so.name1 COLLATE latin1_general_ci',
'service_description' => 'so.name2 COLLATE latin1_general_ci', 'service' => 'so.name2 COLLATE latin1_general_ci',
'service_name' => 'so.name2 COLLATE latin1_general_ci',
'service_description' => 'so.name2 COLLATE latin1_general_ci',
) )
); );
@ -28,6 +66,13 @@ class CommentQuery extends AbstractQuery
array() array()
); );
$this->baseQuery->join(
array(
'co' => $this->prefix . 'objects'
),
'cm.object_id = co.' . $this->object_id . ' AND co.is_active = 1'
);
$this->joinedVirtualTables = array('comments' => true); $this->joinedVirtualTables = array('comments' => true);
} }
@ -35,16 +80,16 @@ class CommentQuery extends AbstractQuery
{ {
$this->baseQuery->join( $this->baseQuery->join(
array('ho' => $this->prefix . 'objects'), array('ho' => $this->prefix . 'objects'),
'cm.object_id = ho.' . $this->object_id . ' AND ho.is_active = 1 AND ho.objecttype_id = 1', 'co.name1 = ho.name1 AND ho.is_active = 1 AND ho.objecttype_id = 1',
array() array()
); );
} }
protected function joinServices() protected function joinServices()
{ {
$this->baseQuery->join( $this->baseQuery->joinLeft(
array('so' => $this->prefix . 'objects'), array('so' => $this->prefix . 'objects'),
'cm.object_id = so.' . $this->object_id . ' AND so.is_active = 1 AND so.objecttype_id = 2', 'co.name1 = so.name1 AND co.name2 = so.name2 AND so.is_active = 1 AND so.objecttype_id = 2',
array() array()
); );
} }

View File

@ -0,0 +1,157 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command;
use Icinga\Protocol\Commandpipe\Command;
/**
* Configurable simple command
*/
class SingleArgumentCommand extends Command
{
/**
* Value used for this command
*
* @var mixed
*/
private $value;
/**
* Name of host command
*
* @var string
*/
private $hostCommand;
/**
* Name of service command
*
* @var string
*/
private $serviceCommand;
/**
* Ignore host in command string
*
* @var bool
*/
private $ignoreObject = false;
/**
* Setter for this value
*
* @param mixed $value
*/
public function setValue($value)
{
$this->value = $value;
}
/**
* Setter for command names
*
* @param string $hostCommand
* @param string $serviceCommand
*/
public function setCommand($hostCommand, $serviceCommand)
{
$this->hostCommand = $hostCommand;
$this->serviceCommand = $serviceCommand;
}
/**
* Ignore object values upon command creation
*
* @param bool $flag
*/
public function setObjectIgnoreFlag($flag = true)
{
$this->ignoreObject = (bool) $flag;
}
/**
* Return this command's arguments in the order expected by the actual command definition
*
* @return array
*/
public function getArguments()
{
if ($this->value !== null) {
return array($this->value);
} else {
return array();
}
}
/**
* Build the argument string based on objects and arguments
*
* @param array $objectNames
*
* @return string String to append to command
*/
private function getArgumentString(array $objectNames)
{
$data = array();
if ($this->ignoreObject === true) {
$data = $this->getArguments();
} else {
$data = array_merge($objectNames, $this->getArguments());
}
return implode(';', $data);
}
/**
* Return the command as a string with the given host being inserted
*
* @param string $hostname The name of the host to insert
*
* @return string The string representation of the command
*/
public function getHostCommand($hostname)
{
return strtoupper($this->hostCommand). ';' . $this->getArgumentString(array($hostname));
}
/**
* Return the command as a string with the given host and service being inserted
*
* @param string $hostname The name of the host to insert
* @param string $servicename The name of the service to insert
*
* @return string The string representation of the command
*/
public function getServiceCommand($hostname, $servicename)
{
return strtoupper($this->serviceCommand)
. ';'
. $this->getArgumentString(array($hostname, $servicename));
}
}

View File

@ -0,0 +1,84 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\DataView;
/**
* View representation for comments
*/
class Comment extends DataView
{
/**
* Retrieve columns provided by this view
*
* @return array
*/
public function getColumns()
{
return array(
'comment_objecttype_id',
'comment_id',
'comment_data',
'comment_author',
'comment_timestamp',
'comment_type',
'comment_is_persistent',
'comment_expiration_timestamp',
'host_name',
'service_name'
);
}
/**
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
*
* @return array
*/
public function getSortRules()
{
return array(
'comment_timestamp' => array(
'order' => self::SORT_DESC
),
'host_service' => array(
'columns' => array(
'host_name',
'service_name'
),
'order' => self::SORT_ASC
),
'comment_id' => array(
'order' => self::SORT_ASC
),
'comment_expires' => array(
'order' => self::SORT_DESC
)
);
}
}

View File

@ -29,8 +29,15 @@ abstract class AbstractObject
public function __construct(Backend $backend, $name1, $name2 = null) public function __construct(Backend $backend, $name1, $name2 = null)
{ {
$this->backend = $backend; $this->backend = $backend;
$this->name1 = $name1; $this->name1 = $name1;
$this->name2 = $name2; $this->name2 = $name2;
if ($name1 && $name2) {
$this->type = 2;
} elseif ($name1 && !$name2) {
$this->type = 1;
}
$this->properties = (array) $this->fetchObject(); $this->properties = (array) $this->fetchObject();
} }
@ -125,7 +132,7 @@ abstract class AbstractObject
'comment_author', 'comment_author',
'comment_data', 'comment_data',
'comment_type', 'comment_type',
)) ))->where('comment_objecttype_id', $this->type)
)->fetchAll(); )->fetchAll();
return $this; return $this;
} }

View File

@ -1,26 +0,0 @@
<?php
namespace Icinga\Module\Monitoring\View;
class CommentView extends AbstractView
{
protected $query;
protected $availableColumns = array(
'comment_data',
'comment_author',
'comment_timestamp',
'comment_type',
'host_name',
'service_host_name',
'service_description',
);
protected $specialFilters = array();
protected $sortDefaults = array(
'comment_timestamp' => array(
'default_dir' => self::SORT_DESC
)
);
}

View File

@ -0,0 +1,92 @@
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
/*global Icinga:false define:false require:false base_url:false console:false */
/**
* Icinga app/ajaxPostSubmitForm component.
*
* This component converts generic post forms into ajax
* submit forms.
*/
define(['components/app/container', 'jquery'], function(Container, $) {
"use strict";
/**
* Returns owner container
*
* @param {Element} targetElement
* @returns {Container}
*/
var getOwnerContainer = function(targetElement) {
var me = new Container(targetElement);
return new Container(me.findNearestContainer(targetElement));
};
/**
* Handler for ajax post submit
*
* @param {Event} e
*/
var submitHandler = function(e) {
var form = $(this);
var url = form.attr('action');
var submit = form.find('input[type="submit"]');
var data = form.serialize();
e.preventDefault();
// Submit name is missing for valid submission
if (data) {
data += '&';
}
data += submit.attr('name') + '=1';
$.ajax({
url: url,
type: 'POST',
data: data,
beforeSend: function() {
submit.prop('disabled', true);
}
}).done(function() {
var container = getOwnerContainer(form);
container.replaceDomFromUrl(container.getContainerHref());
}).error(function() {
submit.removeProp('disabled');
});
};
/**
* The component bootstrap
*
* @param {Element} targetElement
*/
return function(targetForm) {
var form = $(targetForm);
form.submit(submitHandler);
};
});

View File

@ -91,7 +91,7 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe
* @returns {HTMLElement|null} The nearest container found or null if target is no container * @returns {HTMLElement|null} The nearest container found or null if target is no container
* and no container is above target * and no container is above target
*/ */
var findNearestContainer = function(target) { this.findNearestContainer = function(target) {
target = $(target); target = $(target);
if (target.attr('data-icinga-component') === 'app/container' || if (target.attr('data-icinga-component') === 'app/container' ||
target.attr('id') === 'icingamain' || target.attr('id') === 'icingadetail') { target.attr('id') === 'icingamain' || target.attr('id') === 'icingadetail') {
@ -106,7 +106,7 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe
* @param {HTMLElement, jQuery, String} target A jQuery resultset, dom element or matcher string * @param {HTMLElement, jQuery, String} target A jQuery resultset, dom element or matcher string
*/ */
this.construct = function(target) { this.construct = function(target) {
this.containerDom = $(findNearestContainer(target)); this.containerDom = $(this.findNearestContainer(target));
this.containerType = CONTAINER_TYPES.GENERIC; this.containerType = CONTAINER_TYPES.GENERIC;
if (this.containerDom.attr('id') === CONTAINER_TYPES.MAIN) { if (this.containerDom.attr('id') === CONTAINER_TYPES.MAIN) {

View File

@ -0,0 +1,99 @@
/*global Icinga:false, Modernizr: false, document: false, History: false, define:false require:false base_url:false console:false */
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Icinga app/ellipsisText component
*
* This component adds ellipsis with expand functionality
* to content.
*
* Example:
*
* <pre>
* <code>
* <span data-icinga-component="app/ellipsisText">
* A very long example text
* </span>
* </code>
* </pre>
*/
define(['jquery'],
function($, logger, componentLoader, URI) {
"use strict";
/**
* Test if a css3 ellipsis is avtive
*
* @param {Element} element
* @returns {boolean}
*/
var activeEllipsis = function(element) {
return (element.offsetWidth < element.scrollWidth);
};
/**
* Add classes to element to create a css3 ellipsis
*
* Parent elements width is used to calculate containing width
* and set target element width to a fixed one.
*
* @param {Element} target
* @constructor
*/
var EllipsisText = function(target) {
var parentWidth = $(target).parent().width();
$(target).width(parentWidth)
.css('overflow', 'hidden')
.css('text-overflow', 'ellipsis')
.css('display', 'block')
.css('white-space', 'nowrap');
if (activeEllipsis(target)) {
$(target).wrap('<a></a>')
.css('cursor', 'pointer');
$(target).parent()
.attr('data-icinga-ellipsistext', 'true')
.attr('data-content', $(target).html())
.popover({
trigger : 'manual',
html : true,
placement : 'auto'
})
.click(function(e) {
e.stopImmediatePropagation();
$('a[data-icinga-ellipsistext=\'true\']').popover('hide');
$(e.currentTarget).popover('toggle');
});
}
};
return EllipsisText;
}
);

View File

@ -130,6 +130,11 @@ function(Container, $, logger, URI) {
if (true || Container.isExternalLink(a.attr('href'))) { if (true || Container.isExternalLink(a.attr('href'))) {
return true; return true;
} }
} else if (targetEl.nodeName.toLowerCase() === 'input') {
var type = $(targetEl).attr('type');
if (type === 'submit') {
return true;
}
} }
Container.getDetailContainer().replaceDomFromUrl($('a', this).attr('href')); Container.getDetailContainer().replaceDomFromUrl($('a', this).attr('href'));