Add form to configure objects

refs #4924
This commit is contained in:
Marius Hein 2013-10-20 13:15:11 +02:00
parent 652df9fd66
commit 5a1a738ce7
11 changed files with 268 additions and 51 deletions

View File

@ -468,8 +468,8 @@ class Monitoring_CommandController extends ActionController
}
$form->setCommand(
'STOP_ACCEPTING_PASSIVE_HOST_CHECKS',
'STOP_ACCEPTING_PASSIVE_SVC_CHECKS'
'DISABLE_PASSIVE_HOST_CHECKS',
'DISABLE_PASSIVE_SVC_CHECKS'
);
$form->setGlobalCommands(
@ -501,8 +501,8 @@ class Monitoring_CommandController extends ActionController
}
$form->setCommand(
'START_ACCEPTING_PASSIVE_HOST_CHECKS',
'START_ACCEPTING_PASSIVE_SVC_CHECKS'
'ENABLE_PASSIVE_HOST_CHECKS',
'ENABLE_PASSIVE_SVC_CHECKS'
);
$form->setGlobalCommands(

View File

@ -24,6 +24,7 @@ class Zend_View_Helper_CommandForm extends Zend_View_Helper_Abstract
$form = new Form();
$form->setIgnoreChangeDiscarding(true);
$form->setAttrib('data-icinga-component', 'app/ajaxPostSubmitForm');
$form->setAttrib('class', 'inline-form');
$form->setRequest(Zend_Controller_Front::getInstance()->getRequest());
$form->setAction($this->view->href('monitoring/command/' . $commandName));
@ -94,7 +95,19 @@ class Zend_View_Helper_CommandForm extends Zend_View_Helper_Abstract
return $form;
}
public function toggleSubmitForm($label, $checkValue, $enabledCommand, $disabledCommand, array $arguments = array())
/**
* Create a toggle form for switch between commands
*
* @param string $label
* @param string $checkValue
* @param string $enabledCommand
* @param string $disabledCommand
* @param bool $changed
* @param array $arguments
*
* @return string
*/
public function toggleSubmitForm($label, $checkValue, $enabledCommand, $disabledCommand, $changed = false, array $arguments = array())
{
if ($checkValue === '1') {
$commandName = $disabledCommand;
@ -103,7 +116,6 @@ class Zend_View_Helper_CommandForm extends Zend_View_Helper_Abstract
}
$form = $this->simpleForm($commandName, $arguments);
$form->setAttrib('class', 'pull-right');
$uniqueName = uniqid('check');
@ -125,7 +137,29 @@ class Zend_View_Helper_CommandForm extends Zend_View_Helper_Abstract
$form->addElement($submit_identifier);
$form->getElement('btn_submit')->setDecorators(array('ViewHelper'));
return '<label class="label-horizontal" for="' . $uniqueName . '">' . $label . '</label>' . $form;
$out = '<label class="label-horizontal label-configuration" for="' . $uniqueName . '">'
. $label
. '</label>'
. '<div class="pull-right">';
if ($changed === true) {
$out .= '<span class="config-changed">'
. '<i class="icinga-icon-edit"></i> (modified)'
. '</span>';
}
$formCode = (string) $form;
$jsLessSubmit = '<noscript>'
. '<input type="submit" value="Change" class="button btn btn-cta" />'
. '</noscript></form>';
$formCode = str_replace('</form>', $jsLessSubmit, $formCode);
$out .= $formCode
. '</div>';
return $out;
}
/**

View File

@ -227,6 +227,7 @@
$ps->notifications_enabled,
'enablenotifications',
'disablenotifications',
false,
array(
'global' => '1'
)
@ -242,6 +243,7 @@
$ps->active_service_checks_enabled,
'enableactivechecks',
'disableactivechecks',
false,
array(
'global' => 'service'
)
@ -257,6 +259,7 @@
$ps->passive_service_checks_enabled,
'startacceptingpassivechecks',
'stopacceptingpassivechecks',
false,
array(
'global' => 'service'
)
@ -272,6 +275,7 @@
$ps->active_host_checks_enabled,
'enableactivechecks',
'disableactivechecks',
false,
array(
'global' => 'host'
)
@ -287,6 +291,7 @@
$ps->passive_host_checks_enabled,
'startacceptingpassivechecks',
'stopacceptingpassivechecks',
false,
array(
'global' => 'host'
)
@ -302,6 +307,7 @@
$ps->event_handlers_enabled,
'enableeventhandler',
'disableeventhandler',
false,
array(
'global' => '1'
)
@ -317,6 +323,7 @@
$ps->obsess_over_hosts,
'startobsessing',
'stopobsessing',
false,
array(
'global' => 'host'
)
@ -332,6 +339,7 @@
$ps->obsess_over_services,
'startobsessing',
'stopobsessing',
false,
array(
'global' => 'service'
)
@ -347,6 +355,7 @@
$ps->flap_detection_enabled,
'enableflapdetection',
'disableflapdetection',
false,
array(
'global' => '1'
)
@ -362,6 +371,7 @@
$ps->process_performance_data,
'enableperformancedata',
'disableperformancedata',
false,
array(
'global' => '1'
)

View File

@ -3,6 +3,32 @@
/** @var Zend_View_Helper_CommandForm $cf */
$cf = $this->getHelper('CommandForm');
$data = array(
'host' => $o->host_name,
'service' => $o->service_description
);
$modified_attributes = false;
if ($o->service_description && $o->service_modified_service_attributes) {
$modified_attributes = true;
} elseif ($o->host_modified_host_attributes) {
$modified_attributes = true;
}
$test_db_modified = (
($o->passive_checks_enabled_changed === '0')
&& ($o->active_checks_enabled_changed === '0')
&& ($o->obsessing_changed === '0')
&& ($o->notifications_enabled_changed === '0')
&& ($o->event_handler_enabled_changed === '0')
&& ($o->flap_detection_enabled_changed === '0')
) ? false : true;
if ($modified_attributes && !$test_db_modified) {
$modified_attributes = false;
}
?>
<div>
<div class="panel-heading">
@ -14,42 +40,109 @@
<hr class="separator" />
<div class="panel-body">
<table class="table table-condensed table-detail">
<table class="table table-bordered">
<tbody>
<tr>
<td>Passive Checks</td>
<td><div class="icon-table-hint icon-edit pull-left"></div></td>
<td>
<input type="checkbox" id="#" name="#" class="pull-right" <?= ($o->passive_checks_enabled === '1') ? 'checked="true"' : '' ?> />
<?=
$cf->toggleSubmitForm(
'Passive Checks enabled',
$o->passive_checks_enabled,
'startacceptingpassivechecks',
'stopacceptingpassivechecks',
(($o->passive_checks_enabled_changed === '1') ? true : false),
$data
);
?>
</td>
</tr>
<tr>
<td>Active Checks</td>
<td></td>
<td><input type="checkbox" id="#" name="#" class="pull-right" <?= ($o->active_checks_enabled === '1') ? 'checked="true"' : '' ?> /></td>
<td>
<?=
$cf->toggleSubmitForm(
'Active Checks enabled',
$o->active_checks_enabled,
'enableactivechecks',
'disableactivechecks',
(($o->active_checks_enabled_changed === '1') ? true : false),
$data
);
?>
</td>
</tr>
<tr>
<td>
<?=
$cf->toggleSubmitForm(
'Obsessing enabled',
$o->obsessing,
'startobsessing',
'stopobsessing',
(($o->obsessing_changed === '1') ? true : false),
$data
);
?>
</td>
</tr>
<tr>
<td>Obsessing</td>
<td></td>
<td><input type="checkbox" id="#" name="#" class="pull-right" <?= ($o->obsessing === '1') ? 'checked="true"' : '' ?> /></td>
<td>
<?=
$cf->toggleSubmitForm(
'Notifications enabled',
$o->notifications_enabled,
'enablenotifications',
'disablenotifications',
(($o->notifications_enabled_changed === '1') ? true : false),
$data
);
?>
</td>
</tr>
<tr>
<td>Notifications</td>
<td></td>
<td><input type="checkbox" id="#" name="#" class="pull-right" <?= ($o->notifications_enabled === '1') ? 'checked="true"' : '' ?> /></td>
<td>
<?=
$cf->toggleSubmitForm(
'Eventhandler enabled',
$o->event_handler_enabled,
'enableeventhandler',
'disableeventhandler',
(($o->event_handler_enabled_changed === '1') ? true : false),
$data
);
?>
</td>
</tr>
<tr>
<td>Event Handler</td>
<td></div></td>
<td><input type="checkbox" id="#" name="#" class="pull-right" <?= ($o->event_handler_enabled === '1') ? 'checked="true"' : '' ?> /></td>
</tr>
<tr>
<td>Flap Detection</td>
<td></td>
<td><input type="checkbox" id="#" name="#" class="pull-right" <?= ($o->flap_detection_enabled === '1') ? 'checked="true"' : '' ?> /></td>
<td>
<?=
$cf->toggleSubmitForm(
'Flap Detection enabled',
$o->flap_detection_enabled,
'enableflapdetection',
'disableflapdetection',
(($o->flap_detection_enabled_changed === '1') ? true : false),
$data
);
?>
</td>
</tr>
</tbody>
</table>
<?php if ($modified_attributes === true): ?>
<?=
$cf->labelSubmitForm(
'Reset modified attributes',
'Reset configuration to initial values after a system restart',
'btn-cta',
'resetattributes',
$data
);
?>
<?php endif; ?>
</div>
</div>

View File

@ -38,7 +38,12 @@ class StatusQuery extends IdoQuery
'host_check_execution_time' => 'hs.execution_time',
'host_check_latency' => 'hs.latency',
'host_problem' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
'host_notifications_enabled' => 'hs.notifications_enabled',
'host_notifications_enabled_changed' => 'CASE WHEN hs.notifications_enabled=h.notifications_enabled
THEN 0 ELSE 1 END',
'host_last_time_up' => 'UNIX_TIMESTAMP(hs.last_time_up)',
'host_last_time_down' => 'UNIX_TIMESTAMP(hs.last_time_down)',
'host_last_time_unreachable' => 'UNIX_TIMESTAMP(hs.last_time_unreachable)',
@ -54,15 +59,36 @@ class StatusQuery extends IdoQuery
'host_acknowledgement_type' => 'hs.acknowledgement_type',
'host_current_notification_number' => 'hs.current_notification_number',
'host_passive_checks_enabled' => 'hs.passive_checks_enabled',
'host_passive_checks_enabled_changed' => 'CASE WHEN hs.passive_checks_enabled=h.passive_checks_enabled
THEN 0 ELSE 1 END',
'host_active_checks_enabled' => 'hs.active_checks_enabled',
'host_active_checks_enabled_changed' => 'CASE WHEN hs.active_checks_enabled=h.active_checks_enabled
THEN 0 ELSE 1 END',
'host_event_handler_enabled' => 'hs.event_handler_enabled',
'host_event_handler_enabled_changed' => 'CASE WHEN hs.event_handler_enabled=h.event_handler_enabled
THEN 0 ELSE 1 END',
'host_flap_detection_enabled' => 'hs.flap_detection_enabled',
'host_flap_detection_enabled_changed' => 'CASE WHEN hs.flap_detection_enabled=h.flap_detection_enabled
THEN 0 ELSE 1 END',
'host_is_flapping' => 'hs.is_flapping',
'host_percent_state_change' => 'hs.percent_state_change',
'host_scheduled_downtime_depth' => 'hs.scheduled_downtime_depth',
'host_failure_prediction_enabled' => 'hs.failure_prediction_enabled',
'host_process_performance_data' => 'hs.process_performance_data',
'host_obsessing' => 'hs.obsess_over_host',
'host_obsessing_changed' => 'CASE WHEN hs.obsess_over_host=h.obsess_over_host
THEN 0 ELSE 1 END',
'host_modified_host_attributes' => 'hs.modified_host_attributes',
'host_event_handler' => 'hs.event_handler',
'host_check_command' => 'hs.check_command',
@ -145,14 +171,37 @@ class StatusQuery extends IdoQuery
'service_last_notification' => 'ss.last_notification',
'service_next_notification' => 'ss.next_notification',
'service_no_more_notifications' => 'ss.no_more_notifications',
'service_notifications_enabled' => 'ss.notifications_enabled',
'service_notifications_enabled_changed' => 'CASE WHEN ss.notifications_enabled=s.notifications_enabled
THEN 0 ELSE 1 END',
'service_problem_has_been_acknowledged' => 'ss.problem_has_been_acknowledged',
'service_acknowledgement_type' => 'ss.acknowledgement_type',
'service_current_notification_number' => 'ss.current_notification_number',
'service_passive_checks_enabled' => 'ss.passive_checks_enabled',
'service_passive_checks_enabled_changed' => 'CASE WHEN ss.passive_checks_enabled=s.passive_checks_enabled
THEN 0 ELSE 1 END',
'service_active_checks_enabled' => 'ss.active_checks_enabled',
'service_active_checks_enabled_changed' => 'CASE WHEN ss.active_checks_enabled=s.active_checks_enabled
THEN 0 ELSE 1 END',
'service_event_handler_enabled' => 'ss.event_handler_enabled',
'service_event_handler_enabled_changed' => 'CASE WHEN ss.event_handler_enabled=s.event_handler_enabled
THEN 0 ELSE 1 END',
'service_flap_detection_enabled' => 'ss.flap_detection_enabled',
'service_flap_detection_enabled_changed' => 'CASE WHEN ss.flap_detection_enabled=s.flap_detection_enabled
THEN 0 ELSE 1 END',
'service_is_flapping' => 'ss.is_flapping',
'service_percent_state_change' => 'ss.percent_state_change',
'service_check_latency' => 'ss.latency',
@ -160,10 +209,14 @@ class StatusQuery extends IdoQuery
'service_scheduled_downtime_depth' => 'ss.scheduled_downtime_depth',
'service_failure_prediction_enabled' => 'ss.failure_prediction_enabled',
'service_process_performance_data' => 'ss.process_performance_data',
'service_obsessing' => 'ss.obsess_over_service',
'service_obsessing_changed' => 'CASE WHEN ss.obsess_over_service=s.obsess_over_service
THEN 0 ELSE 1 END',
'service_modified_service_attributes' => 'ss.modified_service_attributes',
'service_event_handler' => 'ss.event_handler',
'service_check_command' => 'ss.check_command',
'service_normal_check_interval' => 'ss.normal_check_interval',
'service_retry_check_interval' => 'ss.retry_check_interval',
'service_check_timeperiod_object_id' => 'ss.check_timeperiod_object_id',

View File

@ -37,11 +37,17 @@ class HostStatus extends DataView
'host_check_command',
'host_perfdata',
'host_passive_checks_enabled',
'host_passive_checks_enabled_changed',
'host_obsessing',
'host_obsessing_changed',
'host_notifications_enabled',
'host_notifications_enabled_changed',
'host_event_handler_enabled',
'host_event_handler_enabled_changed',
'host_flap_detection_enabled',
'host_flap_detection_enabled_changed',
'host_active_checks_enabled',
'host_active_checks_enabled_changed',
'host_current_check_attempt',
'host_max_check_attempts',
'host_last_notification',
@ -51,7 +57,8 @@ class HostStatus extends DataView
'host_last_comment',
'host_action_url',
'host_notes_url',
'host_percent_state_change'
'host_percent_state_change',
'host_modified_host_attributes'
);
}

View File

@ -35,6 +35,7 @@ class ServiceStatus extends DataView
'service_severity',
'service_last_check',
'service_notifications_enabled',
'service_notifications_enabled_changed',
'service_action_url',
'service_notes_url',
'service_last_comment',
@ -67,11 +68,14 @@ class ServiceStatus extends DataView
'host_last_time_up',
'host_last_time_down',
'host_last_time_unreachable',
'host_modified_host_attributes',
'service',
'service_hard_state',
'service_perfdata',
'service_active_checks_enabled',
'service_active_checks_enabled_changed',
'service_passive_checks_enabled',
'service_passive_checks_enabled_changed',
'service_last_hard_state',
'service_last_hard_state_change',
'service_last_time_ok',
@ -79,7 +83,14 @@ class ServiceStatus extends DataView
'service_last_time_critical',
'service_last_time_unknown',
'service_current_check_attempt',
'service_max_check_attempts'
'service_max_check_attempts',
'service_obsessing',
'service_obsessing_changed',
'service_event_handler_enabled',
'service_event_handler_enabled_changed',
'service_flap_detection_enabled',
'service_flap_detection_enabled_changed',
'service_modified_service_attributes',
);
}

View File

@ -52,6 +52,11 @@
display: block;
}
.config-changed {
display: inline-block;
margin: 0 10px 0 0;
}
/* ==========================================================================
Forms
========================================================================== */

View File

@ -89,6 +89,10 @@ p {
font-weight: normal;
}
.label-configuration {
cursor: pointer;
}
.inline-image {
display: inline-block;
width: 16px;
@ -103,6 +107,10 @@ p {
font-weight: normal;
}
.inline-form {
display: inline;
}
.gap {
margin-bottom: 15px;
}
@ -136,6 +144,7 @@ a.button {
a.btn-small {
height: 25px;
display: inline-block;
}
/**

View File

@ -35,18 +35,7 @@
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
@ -73,8 +62,8 @@ define(['components/app/container', 'jquery'], function(Container, $) {
submit.attr('disabled', true);
}
}).done(function() {
var container = getOwnerContainer(form);
container.setUrl(container.getUrl());
var c = new Container(form);
c.refresh();
}).error(function() {
submit.removeAttr('disabled');
});

View File

@ -134,8 +134,6 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe
* @private
*/
var createDefaultLoadIndicator = function() {
this.showDetail();
if (this.containerDom.find('div.load-indicator').length === 0) {
var content = '<div class="load-indicator">' +
'<div class="mask"></div>' +
@ -173,11 +171,11 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe
};
this.replaceDomAsync = function(url) {
if (url === '') {
this.containerDom.empty();
urlMgr.syncWithUrl();
if (urlMgr.detailUrl === '') {
this.hideDetail();
return;
}
if (pendingDetailRequest) {
pendingDetailRequest.abort();
}
@ -331,7 +329,15 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe
} else {
urlMgr.setDetailUrl(url.href());
}
}
};
this.refresh = function() {
if (this.containerType === CONTAINER_TYPES.MAIN) {
Container.getMainContainer().replaceDomAsync(urlMgr.mainUrl);
} else {
Container.getDetailContainer().replaceDomAsync(urlMgr.detailUrl);
}
};
this.construct(target);
};