From 5f13db73ce536ff5b041b76146aee722c6e49116 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 12 Sep 2014 16:46:07 +0200 Subject: [PATCH] monitoring/commands: Use the toggle instance features command form in the process controller refs #6593 --- .../controllers/ProcessController.php | 135 +++++++---- .../process/disable-notifications.phtml | 15 ++ .../views/scripts/process/info.phtml | 224 ++++-------------- 3 files changed, 156 insertions(+), 218 deletions(-) create mode 100644 modules/monitoring/application/views/scripts/process/disable-notifications.phtml diff --git a/modules/monitoring/application/controllers/ProcessController.php b/modules/monitoring/application/controllers/ProcessController.php index 49f5715b1..98cba000f 100644 --- a/modules/monitoring/application/controllers/ProcessController.php +++ b/modules/monitoring/application/controllers/ProcessController.php @@ -2,66 +2,113 @@ // {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}} -use Icinga\Module\Monitoring\Controller as MonitoringController; +use Icinga\Module\Monitoring\Controller; +use Icinga\Module\Monitoring\Form\Command\Instance\DisableNotificationsExpireCommandForm; +use Icinga\Module\Monitoring\Form\Command\Instance\ToggleInstanceFeaturesCommandForm; /** - * Display process information and global commands + * Display process and performance information of the monitoring host and program-wide commands */ -class Monitoring_ProcessController extends MonitoringController +class Monitoring_ProcessController extends Controller { /** - * Retrieve backend and hooks for this controller + * Add tabs * - * @see ActionController::init + * @see \Icinga\Web\Controller\ActionController::init() */ public function init() { - $this->getTabs()->add('info', array( - 'title' => 'Process Info', - 'url' =>'monitoring/process/info' - ))->add('performance', array( - 'title' => 'Performance Info', - 'url' =>'monitoring/process/performance' - )); + $this + ->getTabs() + ->add( + 'info', + array( + 'title' => $this->translate('Process Info'), + 'url' =>'monitoring/process/info' + ) + ) + ->add( + 'performance', + array( + 'title' => $this->translate('Performance Info'), + 'url' => 'monitoring/process/performance' + ) + ); } + /** + * Display process information and program-wide commands + */ public function infoAction() { + $this->view->title = $this->translate('Process Info'); $this->getTabs()->activate('info'); $this->setAutorefreshInterval(10); - - // TODO: This one is broken right now, doublecheck default columns - $this->view->programstatus = $this->backend->select() - ->from('programstatus', array( - 'id', - 'status_update_time', - 'program_start_time', - 'program_end_time', - 'is_currently_running', - 'process_id', - 'daemon_mode', - 'last_command_check', - 'last_log_rotation', - 'notifications_enabled', - 'disable_notif_expire_time', - 'active_service_checks_enabled', - 'passive_service_checks_enabled', - 'active_host_checks_enabled', - 'passive_host_checks_enabled', - 'event_handlers_enabled', - 'flap_detection_enabled', - 'failure_prediction_enabled', - 'process_performance_data', - 'obsess_over_hosts', - 'obsess_over_services', - 'modified_host_attributes', - 'modified_service_attributes', - 'global_host_event_handler', - 'global_service_event_handler' - )) - ->getQuery()->fetchRow(); - $this->view->backendName = $this->backend->getName(); + $programStatus = $this->backend + ->select() + ->from( + 'programstatus', + array( + 'is_currently_running', + 'process_id', + 'program_start_time', + 'status_update_time', + 'last_command_check', + 'last_log_rotation', + 'global_service_event_handler', + 'global_host_event_handler', + 'notifications_enabled', + 'disable_notif_expire_time', + 'active_service_checks_enabled', + 'passive_service_checks_enabled', + 'active_host_checks_enabled', + 'passive_host_checks_enabled', + 'event_handlers_enabled', + 'obsess_over_services', + 'obsess_over_hosts', + 'flap_detection_enabled', + 'process_performance_data' + ) + ) + ->getQuery() + ->fetchRow(); + $this->view->programStatus = $programStatus; + $toggleFeaturesForm = new ToggleInstanceFeaturesCommandForm(); + $toggleFeaturesForm + ->setStatus($programStatus) + ->load($programStatus) + ->handleRequest(); + $this->view->toggleFeaturesForm = $toggleFeaturesForm; + } + + /** + * Disable notifications w/ an optional expire time + */ + public function disableNotificationsAction() + { + $this->view->title = $this->translate('Disable Notifications'); + $programStatus = $this->backend + ->select() + ->from( + 'programstatus', + array( + 'notifications_enabled', + 'disable_notif_expire_time' + ) + ) + ->getQuery() + ->fetchRow(); + $this->view->programStatus = $programStatus; + if ((bool) $programStatus->notifications_enabled === false) { + return; + } else { + $form = new DisableNotificationsExpireCommandForm(); + $form + ->setRedirectUrl('monitoring/process/info') + ->handleRequest(); + $this->view->form = $form; + } } public function performanceAction() diff --git a/modules/monitoring/application/views/scripts/process/disable-notifications.phtml b/modules/monitoring/application/views/scripts/process/disable-notifications.phtml new file mode 100644 index 000000000..6b45a1f22 --- /dev/null +++ b/modules/monitoring/application/views/scripts/process/disable-notifications.phtml @@ -0,0 +1,15 @@ +
+

+ notifications_enabled === false): ?> +
+ translate('Host and service notifications are already disabled.') ?> + programStatus->disable_notif_expire_time): ?> + translate('Notifications will be re-enabled in %s.'), + $this->timeUntil($this->programStatus->disable_notif_expire_time)); ?> + +
+ + + +
diff --git a/modules/monitoring/application/views/scripts/process/info.phtml b/modules/monitoring/application/views/scripts/process/info.phtml index 8fb9bd0e3..c659544c2 100644 --- a/modules/monitoring/application/views/scripts/process/info.phtml +++ b/modules/monitoring/application/views/scripts/process/info.phtml @@ -1,179 +1,55 @@
-tabs ?> + tabs ?>
-programstatus; -$cf = $this->getHelper('CommandForm'); - -?>
-

Backend backendName; ?> -is_currently_running === '1' - ? sprintf( - $this->translate('has been running with PID %d '), - $ps->process_id - ) . $this->prefixedTimeSince($ps->program_start_time) - : $this->translate('is not running'); ?>. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
translate('Last status update'); ?>timeSince($ps->status_update_time) ?> ago
translate('Last check command'); ?>timeSince($ps->last_command_check) ?> ago
translate('Global host event handler'); ?>global_host_event_handler ? $ps->global_host_event_handler : $this->translate('Not set'); ?>
translate('Global service event handler'); ?>global_service_event_handler ? $ps->global_service_event_handler : $this->translate('Not set'); ?>
translate('Notifications enabled'); ?>toggleSubmitForm( - '', - $ps->notifications_enabled, - 'enablenotifications', - 'disablenotifications', - false, - array('global' => '1') - ) ?> -notifications_enabled === '1'): ?> - - translate('Temporarily disable'); ?> - -disable_notif_expire_time): ?> -translate('Will be re-enabled in %s'), '' . $this->timeUntil($ps->disable_notif_expire_time) . ''); ?> - - -
translate('Execute active service checks'); ?>toggleSubmitForm( - '', - $ps->active_service_checks_enabled, - 'enableactivechecks', - 'disableactivechecks', - false, - array('global' => 'service') - ) ?>
translate('Accept passive service checks'); ?>toggleSubmitForm( - '', - $ps->passive_service_checks_enabled, - 'startacceptingpassivechecks', - 'stopacceptingpassivechecks', - false, - array('global' => 'service') - ) ?>
translate('Execute active host checks'); ?>toggleSubmitForm( - '', - $ps->active_host_checks_enabled, - 'enableactivechecks', - 'disableactivechecks', - false, - array('global' => 'host') - ) ?>
translate('Accept passive host checks'); ?>toggleSubmitForm( - '', - $ps->passive_host_checks_enabled, - 'startacceptingpassivechecks', - 'stopacceptingpassivechecks', - false, - array('global' => 'host') - ) ?>
translate('Eventhandlers enabled'); ?>toggleSubmitForm( - '', - $ps->event_handlers_enabled, - 'enableeventhandler', - 'disableeventhandler', - false, - array('global' => '1') - ) ?>
translate('Obsessing over host checks'); ?>toggleSubmitForm( - '', - $ps->obsess_over_hosts, - 'startobsessing', - 'stopobsessing', - false, - array('global' => 'host') - ) ?>
translate('Obsessing over service checks'); ?>toggleSubmitForm( - '', - $ps->obsess_over_services, - 'startobsessing', - 'stopobsessing', - false, - array('global' => 'service') - ) ?>
translate('Flap detection enabled'); ?>toggleSubmitForm( - '', - $ps->flap_detection_enabled, - 'enableflapdetection', - 'disableflapdetection', - false, - array('global' => '1') - ) ?>
translate('Process performance data'); ?>toggleSubmitForm( - '', - $ps->process_performance_data, - 'enableperformancedata', - 'disableperformancedata', - false, - array('global' => '1') - ) ?>
translate('Monitoring Process'); ?>labelSubmitForm( - $this->translate('Restart'), - $this->translate('Restart the monitoring process'), - '', - 'restartprocess' - ) ?> - -
- + programStatus->is_currently_running === true): ?> +

+ translate('%s has been up and running with PID %d since %s'), + $this->backendName, + $this->programStatus->process_id, + $this->timeSince($this->programStatus->program_start_time)) ?> +
+ +
+ translate('%s is not running'), $this->backendName) ?> +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
translate('Program Start Time') ?>dateFormat()->formatDateTime($this->programStatus->program_start_time) ?>
translate('Last Status Update'); ?>timeSince($this->programStatus->status_update_time) ?> ago
translate('Last External Command Check'); ?>timeSince($this->programStatus->last_command_check) ?> ago
translate('Last Log File Rotation'); ?>programStatus->last_log_rotation + ? $this->timeSince($this->programStatus->last_log_rotation) + : $this->translate('N/A') ?>
translate('Global Service Event Handler'); ?>programStatus->global_service_event_handler + ? $this->programStatus->global_service_event_handler + : $this->translate('N/A'); ?>
translate('Global Host Event Handler'); ?>programStatus->global_host_event_handler + ? $this->programStatus->global_host_event_handler + : $this->translate('N/A'); ?>
+
+ toggleFeaturesForm ?>