checkmgr/checkmgr.go
func (cm *CheckManager) GetSubmissionURL() (*Trap, error) {
	if cm.trapURL == "" {
		return nil, errors.Errorf("get submission url - submission url unavailable")
	}

	trap := &Trap{}

	u, err := url.Parse(string(cm.trapURL))
	if err != nil {
		return nil, errors.Wrap(err, "get submission url")
	}
	trap.URL = u

	if u.Scheme == "http+unix" {
		service := "circonus-agent"
		sockPath := ""
		metricID := ""

		subNames := cm.sockRx.SubexpNames()
		matches := cm.sockRx.FindAllStringSubmatch(string(cm.trapURL), -1)
		for _, match := range matches {
			for idx, val := range match {
				switch subNames[idx] {
				case "sockfile":
					sockPath = val
				case "id":
					metricID = val
				}
			}
		}

		if sockPath == "" || metricID == "" {
			return nil, errors.Errorf("get submission url - invalid socket url (%s)", cm.trapURL)
		}

		u, err = url.Parse(fmt.Sprintf("http+unix://%s/write/%s", service, metricID))
		if err != nil {
			return nil, errors.Wrap(err, "get submission url")
		}
		trap.URL = u

		trap.SockTransport = &httpunix.Transport{
			DialTimeout:           100 * time.Millisecond,
			RequestTimeout:        1 * time.Second,
			ResponseHeaderTimeout: 1 * time.Second,
		}
		trap.SockTransport.RegisterLocation(service, sockPath)
		trap.IsSocket = true
	}

	if u.Scheme == "https" {
		// preference user-supplied TLS configuration
		if cm.brokerTLS != nil {
			trap.TLS = cm.brokerTLS
			return trap, nil
		}

		// api.circonus.com uses a public CA signed certificate
		// trap.noit.circonus.net uses Circonus CA private certificate
		// enterprise brokers use private CA certificate
		if trap.URL.Hostname() == "api.circonus.com" {
			return trap, nil
		}

		if cm.certPool == nil {
			if err := cm.loadCACert(); err != nil {
				return nil, errors.Wrap(err, "get submission url")
			}
		}
		t := &tls.Config{
			RootCAs: cm.certPool,
		}
		if cm.trapCN != "" {
			t.ServerName = string(cm.trapCN)
		}
		trap.TLS = t
	}

	return trap, nil
}
func (cm *CheckManager) GetSubmissionURL() (*Trap, error) {
	if cm.trapURL == "" {
		return nil, errors.Errorf("get submission url - submission url unavailable")
	}

	trap := &Trap{}

	u, err := url.Parse(string(cm.trapURL))
	if err != nil {
		return nil, errors.Wrap(err, "get submission url")
	}
	trap.URL = u

	if u.Scheme == "http+unix" {
		service := "circonus-agent"
		sockPath := ""
		metricID := ""

		subNames := cm.sockRx.SubexpNames()
		matches := cm.sockRx.FindAllStringSubmatch(string(cm.trapURL), -1)
		for _, match := range matches {
			for idx, val := range match {
				switch subNames[idx] {
				case "sockfile":
					sockPath = val
				case "id":
					metricID = val
				}
			}
		}

		if sockPath == "" || metricID == "" {
			return nil, errors.Errorf("get submission url - invalid socket url (%s)", cm.trapURL)
		}

		u, err = url.Parse(fmt.Sprintf("http+unix://%s/write/%s", service, metricID))
		if err != nil {
			return nil, errors.Wrap(err, "get submission url")
		}
		trap.URL = u

		trap.SockTransport = &httpunix.Transport{
			DialTimeout:           100 * time.Millisecond,
			RequestTimeout:        1 * time.Second,
			ResponseHeaderTimeout: 1 * time.Second,
		}
		trap.SockTransport.RegisterLocation(service, sockPath)
		trap.IsSocket = true
	}

	if u.Scheme == "https" {
		// preference user-supplied TLS configuration
		if cm.brokerTLS != nil {
			trap.TLS = cm.brokerTLS
			return trap, nil
		}

		// api.circonus.com uses a public CA signed certificate
		// trap.noit.circonus.net uses Circonus CA private certificate
		// enterprise brokers use private CA certificate
		if trap.URL.Hostname() == "api.circonus.com" {
			return trap, nil
		}

		if cm.certPool == nil {
			if err := cm.loadCACert(); err != nil {
				return nil, errors.Wrap(err, "get submission url")
			}
		}
		t := &tls.Config{
			RootCAs: cm.certPool,
		}
		if cm.trapCN != "" {
			t.ServerName = string(cm.trapCN)
		}
		trap.TLS = t
	}

	return trap, nil
}
func ( cm * CheckManager ) GetSubmissionURL ( ) ( * Trap , error ) { if cm . trapURL == " " { return nil , errors . Errorf ( " " ) } trap := & Trap { } u , err := url . Parse ( string ( cm . trapURL ) ) if err != nil { return nil , errors . Wrap ( err , " " ) } trap . URL = u if u . Scheme == " " { service := " " sockPath := " " metricID := " " subNames := cm . sockRx . SubexpNames ( ) matches := cm . sockRx . FindAllStringSubmatch ( string ( cm . trapURL ) , - 1 ) for _ , match := range matches { for idx , val := range match { switch subNames [ idx ] { case " " : sockPath = val case " " : metricID = val } } } if sockPath == " " || metricID == " " { return nil , errors . Errorf ( " " , cm . trapURL ) } u , err = url . Parse ( fmt . Sprintf ( " " , service , metricID ) ) if err != nil { return nil , errors . Wrap ( err , " " ) } trap . URL = u trap . SockTransport = & httpunix . Transport { DialTimeout : 100 * time . Millisecond , RequestTimeout : 1 * time . Second , ResponseHeaderTimeout : 1 * time . Second , } trap . SockTransport . RegisterLocation ( service , sockPath ) trap . IsSocket = true } if u . Scheme == " " { // preference user-supplied TLS configuration if cm . brokerTLS != nil { trap . TLS = cm . brokerTLS return trap , nil } // api.circonus.com uses a public CA signed certificate // trap.noit.circonus.net uses Circonus CA private certificate // enterprise brokers use private CA certificate if trap . URL . Hostname ( ) == " " { return trap , nil } if cm . certPool == nil { if err := cm . loadCACert ( ) ; err != nil { return nil , errors . Wrap ( err , " " ) } } t := & tls . Config { RootCAs : cm . certPool , } if cm . trapCN != " " { t . ServerName = string ( cm . trapCN ) } trap . TLS = t } return trap , nil }
// GetSubmissionURL returns submission url for circonus
GetSubmissionURL returns submission url for circonus