Exemplo n.º 1
0
func TcpConstructor(h Healthcheck) (HealthChecker, error) {

	var result *multierror.Error
	hc := TcpHealthCheck{
		Destination: h.Destination,
	}

	if val, ok := h.Config["port"]; ok {
		hc.Port = utils.GetAsString(val)
	} else {
		result = multierror.Append(result, errors.New("'port' not defined in tcp healthcheck config to "+h.Destination))
	}

	if v, ok := h.Config["expect"]; ok {
		hc.Expect = v.(string)
	}

	if v, ok := h.Config["send"]; ok {
		hc.Send = v.(string)
	}

	if val, exists := h.Config["ssl"]; exists {
		ssl, er := utils.GetAsBool(val, false)
		if er != nil {
			result = multierror.Append(result, errors.New("'ssl' has to be true or false"))
		} else {
			hc.TLS = ssl
		}

		if val, exists := h.Config["certPath"]; exists {
			x509, err := ioutil.ReadFile(val.(string))
			if err != nil {
				result = multierror.Append(result, errors.New("'cert' refers to a file that can not be parsed"))
			} else {
				hc.x509 = x509
			}
		}

		if val, exists := h.Config["cert"]; exists {
			x509 := []byte(val.(string))
			hc.x509 = x509
		}

		if val, exists := h.Config["skipVerify"]; exists {
			skipVerify, err := utils.GetAsBool(val, false)
			if err != nil {
				result = multierror.Append(result, errors.New("'skipVerify' has to be true or false, input"))
			} else {
				hc.SkipVerify = skipVerify
			}
		}

		if val, exists := h.Config["serverName"]; exists {
			hc.ServerName = val.(string)
		}
	}
	return hc, result.ErrorOrNil()
}
Exemplo n.º 2
0
func CommandConstructor(h Healthcheck) (HealthChecker, error) {
	var result *multierror.Error
	hc := CommandHealthCheck{
		Destination: h.Destination,
	}
	if val, ok := h.Config["command"]; ok {
		hc.Command = utils.GetAsString(val)
	} else {
		result = multierror.Append(result, errors.New("'command' not defined in command healthcheck config to "+h.Destination))
	}
	if val, ok := h.Config["arguments"]; ok {
		args, err := utils.GetAsSlice(val)
		if err != nil {
			result = multierror.Append(result, err)
		} else {
			for i, val := range args {
				args[i] = strings.Replace(val, "%DESTINATION%", h.Destination, -1)
			}
			hc.Arguments = args
		}
	}
	return hc, result.ErrorOrNil()
}