checkmgr/check.go
func (cm *CheckManager) createNewCheck() (*api.CheckBundle, *api.Broker, error) {
	checkSecret := string(cm.checkSecret)
	if checkSecret == "" {
		secret, err := cm.makeSecret()
		if err != nil {
			secret = "myS3cr3t"
		}
		checkSecret = secret
	}

	broker, err := cm.getBroker()
	if err != nil {
		return nil, nil, err
	}

	chkcfg := &api.CheckBundle{
		Brokers:     []string{broker.CID},
		Config:      make(map[config.Key]string),
		DisplayName: string(cm.checkDisplayName),
		Metrics:     []api.CheckBundleMetric{},
		MetricLimit: config.DefaultCheckBundleMetricLimit,
		Notes:       cm.getNotes(),
		Period:      60,
		Status:      statusActive,
		Tags:        append(cm.checkSearchTag, cm.checkTags...),
		Target:      string(cm.checkTarget),
		Timeout:     10,
		Type:        string(cm.checkType),
	}

	if len(cm.customConfigFields) > 0 {
		for fld, val := range cm.customConfigFields {
			chkcfg.Config[config.Key(fld)] = val
		}
	}

	//
	// use the default config settings if these are NOT set by user configuration
	//
	if val, ok := chkcfg.Config[config.AsyncMetrics]; !ok || val == "" {
		chkcfg.Config[config.AsyncMetrics] = "true"
	}

	if val, ok := chkcfg.Config[config.Secret]; !ok || val == "" {
		chkcfg.Config[config.Secret] = checkSecret
	}

	checkBundle, err := cm.apih.CreateCheckBundle(chkcfg)
	if err != nil {
		return nil, nil, err
	}

	return checkBundle, broker, nil
}
func (cm *CheckManager) createNewCheck() (*api.CheckBundle, *api.Broker, error) {
	checkSecret := string(cm.checkSecret)
	if checkSecret == "" {
		secret, err := cm.makeSecret()
		if err != nil {
			secret = "myS3cr3t"
		}
		checkSecret = secret
	}

	broker, err := cm.getBroker()
	if err != nil {
		return nil, nil, err
	}

	chkcfg := &api.CheckBundle{
		Brokers:     []string{broker.CID},
		Config:      make(map[config.Key]string),
		DisplayName: string(cm.checkDisplayName),
		Metrics:     []api.CheckBundleMetric{},
		MetricLimit: config.DefaultCheckBundleMetricLimit,
		Notes:       cm.getNotes(),
		Period:      60,
		Status:      statusActive,
		Tags:        append(cm.checkSearchTag, cm.checkTags...),
		Target:      string(cm.checkTarget),
		Timeout:     10,
		Type:        string(cm.checkType),
	}

	if len(cm.customConfigFields) > 0 {
		for fld, val := range cm.customConfigFields {
			chkcfg.Config[config.Key(fld)] = val
		}
	}

	//
	// use the default config settings if these are NOT set by user configuration
	//
	if val, ok := chkcfg.Config[config.AsyncMetrics]; !ok || val == "" {
		chkcfg.Config[config.AsyncMetrics] = "true"
	}

	if val, ok := chkcfg.Config[config.Secret]; !ok || val == "" {
		chkcfg.Config[config.Secret] = checkSecret
	}

	checkBundle, err := cm.apih.CreateCheckBundle(chkcfg)
	if err != nil {
		return nil, nil, err
	}

	return checkBundle, broker, nil
}
func ( cm * CheckManager ) createNewCheck ( ) ( * api . CheckBundle , * api . Broker , error ) { checkSecret := string ( cm . checkSecret ) if checkSecret == " " { secret , err := cm . makeSecret ( ) if err != nil { secret = " " } checkSecret = secret } broker , err := cm . getBroker ( ) if err != nil { return nil , nil , err } chkcfg := & api . CheckBundle { Brokers : [ ] string { broker . CID } , Config : make ( map [ config . Key ] string ) , DisplayName : string ( cm . checkDisplayName ) , Metrics : [ ] api . CheckBundleMetric { } , MetricLimit : config . DefaultCheckBundleMetricLimit , Notes : cm . getNotes ( ) , Period : 60 , Status : statusActive , Tags : append ( cm . checkSearchTag , cm . checkTags ... ) , Target : string ( cm . checkTarget ) , Timeout : 10 , Type : string ( cm . checkType ) , } if len ( cm . customConfigFields ) > 0 { for fld , val := range cm . customConfigFields { chkcfg . Config [ config . Key ( fld ) ] = val } } // // use the default config settings if these are NOT set by user configuration // if val , ok := chkcfg . Config [ config . AsyncMetrics ] ; ! ok || val == " " { chkcfg . Config [ config . AsyncMetrics ] = " " } if val , ok := chkcfg . Config [ config . Secret ] ; ! ok || val == " " { chkcfg . Config [ config . Secret ] = checkSecret } checkBundle , err := cm . apih . CreateCheckBundle ( chkcfg ) if err != nil { return nil , nil , err } return checkBundle , broker , nil }
// Create a new check to receive metrics
Create a new check to receive metrics