/** * */ 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 testGetColumns() { $this->assertEquals(array('host_id', 'host_template_model_htm_id', 'command_command_id', 'command_command_id_arg1', 'timeperiod_tp_id', 'timeperiod_tp_id2', 'command_command_id2', 'command_command_id_arg2', 'host_name', 'host_alias', 'host_address', 'display_name', 'host_max_check_attempts', 'host_check_interval', 'host_retry_check_interval', 'host_active_checks_enabled', 'host_passive_checks_enabled', 'host_checks_enabled', 'initial_state', 'host_obsess_over_host', 'host_check_freshness', 'host_freshness_threshold', 'host_event_handler_enabled', 'host_low_flap_threshold', 'host_high_flap_threshold', 'host_flap_detection_enabled', 'flap_detection_options', 'host_process_perf_data', 'host_retain_status_information', 'host_retain_nonstatus_information', 'host_notification_interval', 'host_notification_options', 'host_notifications_enabled', 'contact_additive_inheritance', 'cg_additive_inheritance', 'host_first_notification_delay', 'host_snmp_community', 'host_snmp_version', 'host_location', 'host_comment', 'host_register', 'host_activate', 'organization_id', 'environment_id', 'poller_id'), Hosttemplate::getColumns()); }
/** * Get the value from template * * @param int $hostId The host template Id * @param bool $isBase If the host template id is the base for get values * @return array */ public static function getInheritanceValues($hostId, $isBase = false, $columns = array()) { $values = array(); $templates = HostRepository::getTemplateChain($hostId, array(), -1); if ($isBase) { array_unshift($templates, array('id' => $hostId)); } foreach ($templates as $template) { if (count($columns) > 0) { $inheritanceValues = static::getInheritanceValues($template['id'], false, $columns); $tmplValues = Hosttemplate::getParameters($template['id'], $columns); } else { $inheritanceValues = static::getInheritanceValues($template['id']); $tmplValues = Hosttemplate::getParameters($template['id'], self::$inheritanceColumns); } $tmplValues = array_filter($tmplValues, function ($value) { return !is_null($value); }); $tmplValues = array_merge($inheritanceValues, $tmplValues); $values = array_merge($tmplValues, $values); } return $values; }