checkmgr/check.go
func (cm *CheckManager) fetchCheckBySubmissionURL(submissionURL api.URLType) (*api.Check, error) {
	if string(submissionURL) == "" {
		return nil, errors.New("[ERROR] Invalid submission URL (blank)")
	}

	u, err := url.Parse(string(submissionURL))
	if err != nil {
		return nil, err
	}

	// valid trap url: scheme://host[:port]/module/httptrap/UUID/secret

	// does it smell like a valid trap url path
	if !strings.Contains(u.Path, "/module/httptrap/") {
		return nil, fmt.Errorf("[ERROR] Invalid submission URL '%s', unrecognized path", submissionURL)
	}

	// extract uuid
	pathParts := strings.Split(strings.Replace(u.Path, "/module/httptrap/", "", 1), "/")
	if len(pathParts) != 2 {
		return nil, fmt.Errorf("[ERROR] Invalid submission URL '%s', UUID not where expected", submissionURL)
	}
	uuid := pathParts[0]

	filter := api.SearchFilterType{"f__check_uuid": []string{uuid}}

	checks, err := cm.apih.SearchChecks(nil, &filter)
	if err != nil {
		return nil, err
	}

	if len(*checks) == 0 {
		return nil, fmt.Errorf("[ERROR] No checks found with UUID %s", uuid)
	}

	numActive := 0
	checkID := -1

	for idx, check := range *checks {
		if check.Active {
			numActive++
			checkID = idx
		}
	}

	if numActive > 1 {
		return nil, fmt.Errorf("[ERROR] Multiple checks with same UUID %s", uuid)
	}

	check := (*checks)[checkID]

	return &check, nil

}
func (cm *CheckManager) fetchCheckBySubmissionURL(submissionURL api.URLType) (*api.Check, error) {
	if string(submissionURL) == "" {
		return nil, errors.New("[ERROR] Invalid submission URL (blank)")
	}

	u, err := url.Parse(string(submissionURL))
	if err != nil {
		return nil, err
	}

	// valid trap url: scheme://host[:port]/module/httptrap/UUID/secret

	// does it smell like a valid trap url path
	if !strings.Contains(u.Path, "/module/httptrap/") {
		return nil, fmt.Errorf("[ERROR] Invalid submission URL '%s', unrecognized path", submissionURL)
	}

	// extract uuid
	pathParts := strings.Split(strings.Replace(u.Path, "/module/httptrap/", "", 1), "/")
	if len(pathParts) != 2 {
		return nil, fmt.Errorf("[ERROR] Invalid submission URL '%s', UUID not where expected", submissionURL)
	}
	uuid := pathParts[0]

	filter := api.SearchFilterType{"f__check_uuid": []string{uuid}}

	checks, err := cm.apih.SearchChecks(nil, &filter)
	if err != nil {
		return nil, err
	}

	if len(*checks) == 0 {
		return nil, fmt.Errorf("[ERROR] No checks found with UUID %s", uuid)
	}

	numActive := 0
	checkID := -1

	for idx, check := range *checks {
		if check.Active {
			numActive++
			checkID = idx
		}
	}

	if numActive > 1 {
		return nil, fmt.Errorf("[ERROR] Multiple checks with same UUID %s", uuid)
	}

	check := (*checks)[checkID]

	return &check, nil

}
func ( cm * CheckManager ) fetchCheckBySubmissionURL ( submissionURL api . URLType ) ( * api . Check , error ) { if string ( submissionURL ) == " " { return nil , errors . New ( " " ) } u , err := url . Parse ( string ( submissionURL ) ) if err != nil { return nil , err } // valid trap url: scheme://host[:port]/module/httptrap/UUID/secret // does it smell like a valid trap url path if ! strings . Contains ( u . Path , " " ) { return nil , fmt . Errorf ( " " , submissionURL ) } // extract uuid pathParts := strings . Split ( strings . Replace ( u . Path , " " , " " , 1 ) , " " ) if len ( pathParts ) != 2 { return nil , fmt . Errorf ( " " , submissionURL ) } uuid := pathParts [ 0 ] filter := api . SearchFilterType { " " : [ ] string { uuid } } checks , err := cm . apih . SearchChecks ( nil , & filter ) if err != nil { return nil , err } if len ( * checks ) == 0 { return nil , fmt . Errorf ( " " , uuid ) } numActive := 0 checkID := - 1 for idx , check := range * checks { if check . Active { numActive ++ checkID = idx } } if numActive > 1 { return nil , fmt . Errorf ( " " , uuid ) } check := ( * checks ) [ checkID ] return & check , nil }
// FetchCheckBySubmissionURL fetch a check configuration by submission_url
FetchCheckBySubmissionURL fetch a check configuration by submission_url