set default value to env variable INFINI_CONSOLE_ENDPOINT
This commit is contained in:
parent
2f0864f685
commit
3ad0abdd5f
|
@ -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
|
||||
|
|
|
@ -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, ",")
|
||||
|
|
|
@ -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)
|
||||
//todo override env variables with the variables defined in console ui
|
||||
return envVariables, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//todo override env variables with the variables defined in console ui
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue