/** * */ public function validate($value, $params = array(), $sContext = 'server') { if (isset($params['extraParams']['host_active_checks_enabled']) && $params['extraParams']['host_active_checks_enabled'] == "0") { $reponse = array('success' => true, 'error' => ''); return $reponse; } if (!isset($value) || $value === " " || $value == "") { // case : UI or API with host-templates params if (isset($params['extraParams']['host_hosttemplates']) && $params['extraParams']['host_hosttemplates'] != " ") { $tplIds = explode(',', $params['extraParams']['host_hosttemplates']); foreach ($tplIds as $tplId) { if (!empty($tplId)) { $template = Hosttemplate::get($tplId); $childTemplates = HostRepository::getTemplateChain($tplId, array(), -1, true); if (!empty($template['command_command_id'])) { $reponse = array('success' => true, 'error' => ''); return $reponse; } foreach ($childTemplates as $childTemplate) { if (!empty($childTemplate['command_command_id'])) { $reponse = array('success' => true, 'error' => ''); return $reponse; } } } } } else { if (isset($params['object_id'])) { // case : Only UI without host-templates params $childTemplates = HostRepository::getTemplateChain($params['object_id'], array(), -1, true); foreach ($childTemplates as $childTemplate) { if (!empty($childTemplate['command_command_id']) || $childTemplate['command_command_id'] == "0") { $reponse = array('success' => true, 'error' => ''); return $reponse; } } } } $reponse = array('success' => false, 'error' => 'No check command set on the host and its templates'); } else { $reponse = array('success' => true, 'error' => ''); } return $reponse; }
public function testGet() { $testResult = array('host_id' => '1', 'host_template_model_htm_id' => null, 'command_command_id' => '2', 'command_command_id_arg1' => '1!2', 'timeperiod_tp_id' => '1', 'timeperiod_tp_id2' => '1', 'command_command_id2' => '3', 'command_command_id_arg2' => '80!90', 'host_name' => 'Template host', 'host_alias' => 'Template host', 'host_address' => null, 'display_name' => 'Template host', 'host_max_check_attempts' => '5', 'host_check_interval' => '5', 'host_retry_check_interval' => '5', 'host_active_checks_enabled' => '2', 'host_passive_checks_enabled' => '2', 'host_checks_enabled' => '2', 'initial_state' => 'u', 'host_obsess_over_host' => '2', 'host_check_freshness' => '2', 'host_freshness_threshold' => '5', 'host_event_handler_enabled' => '2', 'host_low_flap_threshold' => '5', 'host_high_flap_threshold' => '5', 'host_flap_detection_enabled' => '2', 'flap_detection_options' => 'f', 'host_process_perf_data' => '2', 'host_retain_status_information' => '2', 'host_retain_nonstatus_information' => '2', 'host_notification_interval' => '300', 'host_notification_options' => '$HOSTNAME$', 'host_notifications_enabled' => '2', 'contact_additive_inheritance' => '1', 'cg_additive_inheritance' => '1', 'host_first_notification_delay' => '0', 'host_snmp_community' => 'public', 'host_snmp_version' => '2c', 'host_location' => '0', 'host_comment' => 'Host template', 'host_register' => '0', 'host_activate' => '1', 'organization_id' => '1', 'environment_id' => null, 'poller_id' => null); $result = Hosttemplate::get(1); $this->assertEquals($testResult, $result); $testResult = array('host_name' => 'Template host'); $result = Hosttemplate::get(1, 'host_name'); $this->assertEquals($testResult, $result); $testResult = array('host_name' => 'Template host', 'host_comment' => 'Host template'); $result = Hosttemplate::get(1, array('host_name', 'host_comment')); $this->assertEquals($testResult, $result); $this->setExpectedException('\\Centreon\\Internal\\Exception', $this->errMsg, 0); Hosttemplate::get(42); }