diff --git a/behat.yml b/behat.yml index 2f27257fc46..b56eaccbd46 100644 --- a/behat.yml +++ b/behat.yml @@ -248,3 +248,8 @@ default: paths: [ %paths.base%/features/TimePeriodConfiguration.feature ] contexts: - TimePeriodConfigurationContext + + massive_change_hosts: + paths: [ %paths.base%/features/MassiveChangeHosts.feature ] + contexts: + - MassiveChangeHostsContext diff --git a/features/MassiveChangeHosts.feature b/features/MassiveChangeHosts.feature new file mode 100644 index 00000000000..145b385d4ae --- /dev/null +++ b/features/MassiveChangeHosts.feature @@ -0,0 +1,12 @@ +Feature: Massive Change on Hosts + As a Centreon administrator + I want to modify some properties of similar hosts + To configure quickly numerous hosts at the same time + + Background: + Given I am logged in a Centreon server + And several hosts have been created with mandatory properties + + Scenario: Configure by massive change several hosts with same properties + When I have applied Massive Change operation to several hosts + Then all selected hosts are updated with the same values diff --git a/features/bootstrap/MassiveChangeHostsContext.php b/features/bootstrap/MassiveChangeHostsContext.php new file mode 100644 index 00000000000..de2d96da3a8 --- /dev/null +++ b/features/bootstrap/MassiveChangeHostsContext.php @@ -0,0 +1,346 @@ + 'host1Name', + 'alias' => 'host1Alias', + 'address' => 'host1@localhost' + ); + + protected $host2 = array( + 'name' => 'host2Name', + 'alias' => 'host2Alias', + 'address' => 'host2@localhost' + ); + + protected $host3 = array( + 'name' => 'host3Name', + 'alias' => 'host3Alias', + 'address' => 'host3@localhost' + ); + + protected $hostGroup = array( + 'name' => 'hostGroupName', + 'alias' => 'hostGroupAlias' + ); + + protected $hostCategory1 = array( + 'name' => 'hostCategoryName1', + 'alias' => 'hostCategoryAlias1', + 'severity' => 1, + 'severity_level' => 2, + 'severity_icon' => ' centreon (png)' + ); + + protected $hostCategory2 = array( + 'name' => 'hostCategoryName2', + 'alias' => 'hostCategoryAlias2' + ); + + protected $updatedProperties = array( + 'snmp_community' => 'snmp', + 'snmp_version' => '2c', + 'monitored_from' => 'Central', + 'monitored_option' => 1, + 'location' => 'Europe/Paris', + 'update_mode_tplp' => 0, + 'templates' => array( + 'generic-host' + ), + 'service_linked_to_template' => 0, + 'command_arguments' => 'hostCommandArgument', + 'macros' => array( + 'HOSTMACRONAME' => '22' + ), + 'check_command' => 'check_http', + 'check_period' => 'workhours', + 'max_check_attempts' => 34, + 'normal_check_interval' => 5, + 'retry_check_interval' => 10, + 'active_checks_enabled' => 2, + 'passive_checks_enabled' => 0, + 'notifications_enabled' => 1, + 'contact_additive_inheritance' => 1, + 'contacts' => 'Guest', + 'contact_group_additive_inheritance' => 0, + 'contact_groups' => 'Supervisors', + 'update_mode_notifopts' => 1, + 'notify_on_down' => 1, + 'notify_on_unreachable' => 1, + 'notify_on_recovery' => 1, + 'notify_on_flapping' => 1, + 'notify_on_downtime_scheduled' => 1, + 'notify_on_none' => 0, + 'notification_interval' => 17, + 'update_mode_hcg' => 1, + 'update_mode_notif_interval' => 0, + 'update_mode_timeperiod' => 0, + 'notification_period' => 'none', + 'update_mode_first_notif_delay' => 1, + 'first_notification_delay' => 4, + 'recovery_notification_delay' => 3, + 'update_mode_hhg' => 0, + 'parent_host_groups' => 'hostGroupName', + 'update_mode_hhc' => 1, + 'parent_host_categories' => 'hostCategoryName2', + 'update_mode_hpar' => 1, + 'parent_hosts' => 'Centreon-Server', + 'update_mode_hch' => 0, + 'child_hosts' => 'host3Name', + 'obsess_over_host' => 2, + 'acknowledgement_timeout' => 2, + 'check_freshness' => 0, + 'freshness_threshold' => 34, + 'flap_detection_enabled' => 1, + 'low_flap_threshold' => 67, + 'high_flap_threshold' => 85, + 'retain_status_information' => 2, + 'retain_non_status_information' => 0, + 'stalking_option_on_up' => 1, + 'stalking_option_on_down' => 0, + 'stalking_option_on_unreachable' => 1, + 'event_handler_enabled' => 2, + 'event_handler' => 'check_https', + 'event_handler_arguments' => 'event_handler_arguments', + 'url' => 'hostMassiveChangeUrl', + 'notes' => 'hostMassiveChangeNotes', + 'action_url' => 'hostMassiveChangeActionUrl', + 'icon' => ' centreon (png)', + 'alt_icon' => 'hostMassiveChangeIcon', + 'status_map_image' => ' centreon (png)', + 'geo_coordinates' => 'Paris', + '2d_coords' => '15,84', + '3d_coords' => '15,84,76', + 'severity_level' => 'hostCategoryName1 (2)', + 'enabled' => 0, + 'comments' => 'hostMassiveChangeComments' + ); + + protected $updatedHost1 = array( + 'name' => 'host1Name', + 'alias' => 'host1Alias', + 'address' => 'host1@localhost', + 'snmp_community' => 'snmp', + 'snmp_version' => '2c', + 'monitored_from' => 'Central', + 'location' => 'Europe/Paris', + 'templates' => array( + 'generic-host' + ), + 'service_linked_to_template' => 0, + 'check_command' => 'check_http', + 'command_arguments' => 'hostCommandArgument', + 'macros' => array( + 'HOSTMACRONAME' => '22' + ), + 'check_period' => 'workhours', + 'max_check_attempts' => 34, + 'normal_check_interval' => 5, + 'retry_check_interval' => 10, + 'active_checks_enabled' => 2, + 'passive_checks_enabled' => 0, + 'notifications_enabled' => 1, + 'contact_additive_inheritance' => 1, + 'contacts' => 'Guest', + 'contact_group_additive_inheritance' => 0, + 'contact_groups' => 'Supervisors', + 'notify_on_down' => 1, + 'notify_on_unreachable' => 1, + 'notify_on_recovery' => 1, + 'notify_on_flapping' => 1, + 'notify_on_downtime_scheduled' => 1, + 'notify_on_none' => 1, + 'notification_interval' => 17, + 'notification_period' => 'none', + 'first_notification_delay' => 4, + 'recovery_notification_delay' => 3, + 'parent_host_groups' => 'hostGroupName', + 'parent_host_categories' => 'hostCategoryName2', + 'parent_hosts' => 'Centreon-Server', + 'child_hosts' => 'host3Name', + 'obsess_over_host' => 2, + 'acknowledgement_timeout' => 2, + 'check_freshness' => 0, + 'freshness_threshold' => 34, + 'flap_detection_enabled' => 1, + 'low_flap_threshold' => 67, + 'high_flap_threshold' => 85, + 'retain_status_information' => 2, + 'retain_non_status_information' => 0, + 'stalking_option_on_up' => 1, + 'stalking_option_on_down' => 0, + 'stalking_option_on_unreachable' => 1, + 'event_handler_enabled' => 2, + 'event_handler' => 'check_https', + 'event_handler_arguments' => 'event_handler_arguments', + 'url' => 'hostMassiveChangeUrl', + 'notes' => 'hostMassiveChangeNotes', + 'action_url' => 'hostMassiveChangeActionUrl', + 'icon' => ' centreon (png)', + 'alt_icon' => 'hostMassiveChangeIcon', + 'status_map_image' => ' centreon (png)', + 'geo_coordinates' => 'Paris', + '2d_coords' => '15,84', + '3d_coords' => '15,84,76', + 'severity_level' => 'hostCategoryName1 (2)', + 'enabled' => 0, + 'comments' => 'hostMassiveChangeComments' + ); + + protected $updatedHost2 = array( + 'name' => 'host2Name', + 'alias' => 'host2Alias', + 'address' => 'host2@localhost', + 'snmp_community' => 'snmp', + 'snmp_version' => '2c', + 'monitored_from' => 'Central', + 'location' => 'Europe/Paris', + 'templates' => array( + 'generic-host' + ), + 'service_linked_to_template' => 0, + 'check_command' => 'check_http', + 'command_arguments' => 'hostCommandArgument', + 'macros' => array( + 'HOSTMACRONAME' => '22' + ), + 'check_period' => 'workhours', + 'max_check_attempts' => 34, + 'normal_check_interval' => 5, + 'retry_check_interval' => 10, + 'active_checks_enabled' => 2, + 'passive_checks_enabled' => 0, + 'notifications_enabled' => 1, + 'contact_additive_inheritance' => 1, + 'contacts' => 'Guest', + 'contact_group_additive_inheritance' => 0, + 'contact_groups' => 'Supervisors', + 'notify_on_down' => 1, + 'notify_on_unreachable' => 1, + 'notify_on_recovery' => 1, + 'notify_on_flapping' => 1, + 'notify_on_downtime_scheduled' => 1, + 'notify_on_none' => 1, + 'notification_interval' => 17, + 'notification_period' => 'none', + 'first_notification_delay' => 4, + 'recovery_notification_delay' => 3, + 'parent_host_groups' => 'hostGroupName', + 'parent_host_categories' => 'hostCategoryName2', + 'parent_hosts' => 'Centreon-Server', + 'child_hosts' => 'host3Name', + 'obsess_over_host' => 2, + 'acknowledgement_timeout' => 2, + 'check_freshness' => 0, + 'freshness_threshold' => 34, + 'flap_detection_enabled' => 1, + 'low_flap_threshold' => 67, + 'high_flap_threshold' => 85, + 'retain_status_information' => 2, + 'retain_non_status_information' => 0, + 'stalking_option_on_up' => 1, + 'stalking_option_on_down' => 0, + 'stalking_option_on_unreachable' => 1, + 'event_handler_enabled' => 2, + 'event_handler' => 'check_https', + 'event_handler_arguments' => 'event_handler_arguments', + 'url' => 'hostMassiveChangeUrl', + 'notes' => 'hostMassiveChangeNotes', + 'action_url' => 'hostMassiveChangeActionUrl', + 'icon' => ' centreon (png)', + 'alt_icon' => 'hostMassiveChangeIcon', + 'status_map_image' => ' centreon (png)', + 'geo_coordinates' => 'Paris', + '2d_coords' => '15,84', + '3d_coords' => '15,84,76', + 'severity_level' => 'hostCategoryName1 (2)', + 'enabled' => 0, + 'comments' => 'hostMassiveChangeComments' + ); + + /** + * @Given several hosts have been created with mandatory properties + */ + public function severalHostsHaveBeenCreatedWithMandatoryProperties() + { + $this->currentPage = new HostConfigurationPage($this); + $this->currentPage->setProperties($this->host1); + $this->currentPage->save(); + $this->currentPage = new HostConfigurationPage($this); + $this->currentPage->setProperties($this->host2); + $this->currentPage->save(); + $this->currentPage = new HostConfigurationPage($this); + $this->currentPage->setProperties($this->host3); + $this->currentPage->save(); + $this->currentPage = new HostGroupConfigurationPage($this); + $this->currentPage->setProperties($this->hostGroup); + $this->currentPage->save(); + $this->currentPage = new HostCategoryConfigurationPage($this); + $this->currentPage->setProperties($this->hostCategory1); + $this->currentPage->save(); + $this->currentPage = new HostCategoryConfigurationPage($this); + $this->currentPage->setProperties($this->hostCategory2); + $this->currentPage->save(); + } + + /** + * @When I have applied Massive Change operation to several hosts + */ + public function iHaveAppliedMassiveChangeOperationToSeveralHosts() + { + $this->currentPage = new HostConfigurationListingPage($this); + $object = $this->currentPage->getEntry($this->host1['name']); + $this->assertFind('css', 'input[type="checkbox"][name="select[' . $object['id'] . ']"]')->check(); + $object = $this->currentPage->getEntry($this->host2['name']); + $this->assertFind('css', 'input[type="checkbox"][name="select[' . $object['id'] . ']"]')->check(); + $this->selectInList('select[name="o1"]', 'Massive Change'); + $this->currentPage = new MassiveChangeHostConfigurationPage($this, false); + $this->currentPage->setProperties($this->updatedProperties); + $this->currentPage->save(); + } + + /** + * @Then all selected hosts are updated with the same values + */ + public function allSelectedHostsAreUpdatedWithTheSameValues() + { + $this->tableau = array(); + try { + $this->spin( + function ($context) { + $this->currentPage = new HostConfigurationListingPage($this); + $this->currentPage = $this->currentPage->inspect($this->updatedHost1['name']); + $object = $this->currentPage->getProperties(); + foreach ($this->updatedHost1 as $key => $value) { + if ($value != $object[$key]) { + $this->tableau[] = $key . '1'; + } + } + $this->currentPage = new HostConfigurationListingPage($this); + $this->currentPage = $this->currentPage->inspect($this->updatedHost2['name']); + $object = $this->currentPage->getProperties(); + foreach ($this->updatedHost2 as $key => $value) { + if ($value != $object[$key]) { + $this->tableau[] = $key . '2'; + } + } + return count($this->tableau) == 0; + }, + "Some properties are not being updated : ", + 5 + ); + } catch (\Exception $e) { + $this->tableau = array_unique($this->tableau); + throw new \Exception("Some properties are not being updated : " . implode(',', $this->tableau)); + } + } +} diff --git a/www/include/configuration/configObject/host/DB-Func.php b/www/include/configuration/configObject/host/DB-Func.php index b5cfa201546..1de236053a9 100644 --- a/www/include/configuration/configObject/host/DB-Func.php +++ b/www/include/configuration/configObject/host/DB-Func.php @@ -584,6 +584,11 @@ function updateHostInDB($host_id = null, $from_MC = false, $cfg = null) } +# Function for updating first notification delay options + updateHostNotifOptionRecoveryNotificationDelay($host_id); + + + # Function for updating notification timeperiod options # 1 - MC with deletion of existing options (Replacement) # 2 - MC with addition of new options (incremental) @@ -1949,6 +1954,34 @@ function updateHostNotifOptionFirstNotificationDelay_MC($host_id = null) } } + +function updateHostNotifOptionRecoveryNotificationDelay($host_id = null, $ret = array()) +{ + if (!$host_id) { + return; + } + global $form; + global $pearDB; + + if (isset($ret["host_recovery_notification_delay"])) { + $ret = $ret["host_recovery_notification_delay"]; + } else { + $ret = $form->getSubmitValue("host_recovery_notification_delay"); + } + + if ($ret == '') { + return; + } + $rq = "UPDATE host SET "; + $rq .= "host_recovery_notification_delay = "; + isset($ret) && $ret != null ? $rq .= "'" . $ret . "' " : $rq .= "NULL "; + $rq .= "WHERE host_id = '" . $host_id . "'"; + $pearDB->query($rq); +} + + + + function updateHostHostGroup($host_id, $ret = array()) { global $form, $pearDB;