bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/conf/system_elastic_all.go (about)

     1  package conf
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"bosun.org/cmd/bosun/expr"
     7  	"bosun.org/slog"
     8  )
     9  
    10  // ParseESConfig return expr.ElasticHost
    11  func parseESConfig(sc *SystemConf) expr.ElasticHosts {
    12  	store := make(map[string]expr.ElasticConfig)
    13  	for hostPrefix, value := range sc.ElasticConf {
    14  		// build es config per cluster
    15  		var cfg expr.ElasticConfig
    16  		switch expr.ESVersion(value.Version) {
    17  		case expr.ESV2:
    18  			cfg = parseESConfig2(value)
    19  		case expr.ESV5:
    20  			cfg = parseESConfig5(value)
    21  		case expr.ESV6:
    22  			cfg = parseESConfig6(value)
    23  		case expr.ESV7:
    24  			cfg = parseESConfig7(value)
    25  		case "":
    26  			slog.Fatal(fmt.Errorf(`conf: [ElasticConf.%s]: Version is required a field (supported values for Version are: "v2", "v5", "v6" and "v7")`, hostPrefix))
    27  		default:
    28  			slog.Fatal(fmt.Errorf(`conf: [ElasticConf.%s]: invalid elastic version: %s (supported versions are: "v2", "v5", "v6" and "v7")`, hostPrefix, value.Version))
    29  		}
    30  
    31  		cfg.Version = expr.ESVersion(value.Version)
    32  		store[hostPrefix] = cfg
    33  	}
    34  
    35  	return expr.ElasticHosts{Hosts: store}
    36  }
    37  
    38  // ParseESConfig return expr.ElasticHost
    39  func parseESAnnoteConfig(sc *SystemConf) expr.ElasticConfig {
    40  	var cfg expr.ElasticConfig
    41  	if len(sc.AnnotateConf.Hosts) == 0 {
    42  		return cfg
    43  	}
    44  	switch expr.ESVersion(sc.AnnotateConf.Version) {
    45  	case expr.ESV2:
    46  		cfg = parseESConfig2(ElasticConf(sc.AnnotateConf))
    47  	case expr.ESV5:
    48  		cfg = parseESConfig5(ElasticConf(sc.AnnotateConf))
    49  	case expr.ESV6:
    50  		cfg = parseESConfig6(ElasticConf(sc.AnnotateConf))
    51  	case expr.ESV7:
    52  		cfg = parseESConfig7(ElasticConf(sc.AnnotateConf))
    53  	case "":
    54  		slog.Fatal(fmt.Errorf(`conf: [AnnotateConf]: Version is required a field (supported values for Version are: "v2", "v5", "v6" and "v7")`))
    55  	default:
    56  		slog.Fatal(fmt.Errorf(`conf: [AnnotateConf]: invalid elastic version: %s (supported versions are: "v2", "v5", "v6" and "v7")`, sc.AnnotateConf.Version))
    57  	}
    58  
    59  	cfg.Version = expr.ESVersion(sc.AnnotateConf.Version)
    60  	return cfg
    61  }