Exemplo n.º 1
0
func doHTTPCheck(target net.IP, secure bool) {
	hc := healthcheck.NewHTTPChecker(target, *port)
	hc.Mark = *mark
	hc.Secure = secure
	hc.Request = unquote(*request)
	hc.Response = unquote(*response)
	hc.ResponseCode = *responseCode
	hc.Method = *method
	hc.Proxy = *proxy
	hc.TLSVerify = *tlsVerify
	check(hc)
}
Exemplo n.º 2
0
func (h *healthcheckManager) newConfig(id healthcheck.Id, key checkKey, hc *config.Healthcheck) (*healthcheck.Config, error) {
	host := key.backendIP.IP()
	port := int(hc.Port)
	mark := 0

	// For DSR we use the VIP address as the target and specify a mark for
	// the backend.
	ip := host
	if key.healthcheckMode == seesaw.HCModeDSR {
		ip = key.vserverIP.IP()
		mark = int(h.markBackend(key.backendIP))
	}

	var checker healthcheck.Checker
	var target *healthcheck.Target
	switch hc.Type {
	case seesaw.HCTypeDNS:
		dns := healthcheck.NewDNSChecker(ip, port)
		target = &dns.Target
		queryType, err := healthcheck.DNSType(hc.Method)
		if err != nil {
			return nil, err
		}
		dns.Answer = hc.Receive
		dns.Question.Name = hc.Send
		dns.Question.Qtype = queryType

		checker = dns
	case seesaw.HCTypeHTTP:
		http := healthcheck.NewHTTPChecker(ip, port)
		target = &http.Target
		if hc.Send != "" {
			http.Request = hc.Send
		}
		if hc.Receive != "" {
			http.Response = hc.Receive
		}
		if hc.Code != 0 {
			http.ResponseCode = hc.Code
		}
		http.Proxy = hc.Proxy
		if hc.Method != "" {
			http.Method = hc.Method
		}
		checker = http
	case seesaw.HCTypeHTTPS:
		https := healthcheck.NewHTTPChecker(ip, port)
		target = &https.Target
		if hc.Send != "" {
			https.Request = hc.Send
		}
		if hc.Receive != "" {
			https.Response = hc.Receive
		}
		if hc.Code != 0 {
			https.ResponseCode = hc.Code
		}
		https.Secure = true
		https.TLSVerify = hc.TLSVerify
		https.Proxy = hc.Proxy
		if hc.Method != "" {
			https.Method = hc.Method
		}
		checker = https
	case seesaw.HCTypeICMP:
		// DSR cannot be used with ICMP (at least for now).
		if key.healthcheckMode != seesaw.HCModePlain {
			return nil, errors.New("ICMP healthchecks cannot be used with DSR mode")
		}
		ping := healthcheck.NewPingChecker(ip)
		target = &ping.Target
		checker = ping
	case seesaw.HCTypeRADIUS:
		radius := healthcheck.NewRADIUSChecker(ip, port)
		target = &radius.Target
		// TODO(jsing): Ugly hack since we do not currently have
		// separate protobuf messages for each healthcheck type...
		send := strings.Split(hc.Send, ":")
		if len(send) != 3 {
			return nil, errors.New("RADIUS healthcheck has invalid send value")
		}
		radius.Username = send[0]
		radius.Password = send[1]
		radius.Secret = send[2]
		if hc.Receive != "" {
			radius.Response = hc.Receive
		}
		checker = radius
	case seesaw.HCTypeTCP:
		tcp := healthcheck.NewTCPChecker(ip, port)
		target = &tcp.Target
		tcp.Send = hc.Send
		tcp.Receive = hc.Receive
		checker = tcp
	case seesaw.HCTypeTCPTLS:
		tcp := healthcheck.NewTCPChecker(ip, port)
		target = &tcp.Target
		tcp.Send = hc.Send
		tcp.Receive = hc.Receive
		tcp.Secure = true
		tcp.TLSVerify = hc.TLSVerify
		checker = tcp
	case seesaw.HCTypeUDP:
		udp := healthcheck.NewUDPChecker(ip, port)
		target = &udp.Target
		udp.Send = hc.Send
		udp.Receive = hc.Receive
		checker = udp
	default:
		return nil, fmt.Errorf("Unknown healthcheck type: %v", hc.Type)
	}

	target.Host = host
	target.Mark = mark
	target.Mode = hc.Mode

	hcc := healthcheck.NewConfig(id, checker)
	hcc.Interval = hc.Interval
	hcc.Timeout = hc.Timeout
	hcc.Retries = hc.Retries

	return hcc, nil
}