diff --git a/plugin/setup/setup.go b/plugin/setup/setup.go index a86e0f80..7cd0f6e0 100644 --- a/plugin/setup/setup.go +++ b/plugin/setup/setup.go @@ -5,6 +5,7 @@ import ( "crypto/md5" "encoding/hex" "fmt" + "infini.sh/framework/core/kv" "io" "net/http" uri2 "net/url" @@ -323,9 +324,17 @@ func (module *Module) initialize(w http.ResponseWriter, r *http.Request, ps http module.WriteError(w, "setup not permitted", 500) return } + scheme := "http" + if r.TLS != nil { + scheme = "https" + } + consoleEndpoint := fmt.Sprintf("%s://%s", scheme, r.Host) + err := kv.AddValue("system", []byte("INFINI_CONSOLE_ENDPOINT"), []byte(consoleEndpoint)) + if err != nil { + log.Error(err) + } success := false - var err error var errType string var fixTips string var code int diff --git a/service/alerting/elasticsearch/engine.go b/service/alerting/elasticsearch/engine.go index 3c2b996b..27493d9e 100644 --- a/service/alerting/elasticsearch/engine.go +++ b/service/alerting/elasticsearch/engine.go @@ -902,7 +902,9 @@ func newParameterCtx(rule *alerting.Rule, checkResults *alerting.ConditionResult } for i, resultItem := range checkResults.ResultItems { - + if i >= 10 { + break + } if i == 0 { firstGroupValue = strings.Join(resultItem.GroupValues, ",") firstThreshold = strings.Join(resultItem.ConditionItem.Values, ",") diff --git a/service/alerting/env.go b/service/alerting/env.go index 0cf3ff2b..b1f3c340 100644 --- a/service/alerting/env.go +++ b/service/alerting/env.go @@ -5,13 +5,54 @@ package alerting import ( + "fmt" "infini.sh/framework/core/config" + config2 "infini.sh/console/config" + "infini.sh/framework/core/env" "infini.sh/framework/core/global" + "infini.sh/framework/core/kv" + log "src/github.com/cihub/seelog" ) func GetEnvVariables() (map[string]interface{}, error){ configFile := global.Env().GetConfigFile() envVariables, err := config.LoadEnvVariables(configFile) + if err != nil { + return nil, err + } //todo override env variables with the variables defined in console ui - return envVariables, err + if envVariables != nil && envVariables["INFINI_CONSOLE_ENDPOINT"] == nil { + buf, err := kv.GetValue("system", []byte("INFINI_CONSOLE_ENDPOINT")) + if err != nil { + log.Error(err) + } + var endpoint string + if len(buf) > 0 { + endpoint = string(buf) + } + if endpoint == "" { + endpoint, err = GetInnerConsoleEndpoint() + if err != nil { + return nil, err + } + } + envVariables["INFINI_CONSOLE_ENDPOINT"] = endpoint + } + return envVariables, nil +} + +func GetInnerConsoleEndpoint() (string, error){ + appConfig := &config2.AppConfig{ + UI: config2.UIConfig{}, + } + + ok, err := env.ParseConfig("web", appConfig) + if err != nil { + return "", err + } + if !ok { + return "", fmt.Errorf("web config not exists") + } + endpoint := fmt.Sprintf("%s://%s", appConfig.GetSchema(), appConfig.Network.GetPublishAddr()) + return endpoint, nil }