fix resolving env variables with sending test alert channel message
This commit is contained in:
parent
f4bf4fcb18
commit
90dc208fb7
|
@ -6,7 +6,10 @@ package alerting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
alerting2 "infini.sh/console/service/alerting"
|
||||||
"infini.sh/console/service/alerting/common"
|
"infini.sh/console/service/alerting/common"
|
||||||
|
"infini.sh/framework/core/elastic"
|
||||||
|
"infini.sh/framework/core/global"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -222,6 +225,13 @@ func (h *AlertAPI) testChannel(w http.ResponseWriter, req *http.Request, ps http
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
envVariables, err := alerting2.GetEnvVariables()
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
firstGrpValue := global.MustLookupString(elastic.GlobalSystemElasticsearchID)
|
||||||
ctx := map[string]interface{}{
|
ctx := map[string]interface{}{
|
||||||
"title": "INFINI platform test alert message",
|
"title": "INFINI platform test alert message",
|
||||||
"message": "This is just a test email, do not reply!",
|
"message": "This is just a test email, do not reply!",
|
||||||
|
@ -231,19 +241,19 @@ func (h *AlertAPI) testChannel(w http.ResponseWriter, req *http.Request, ps http
|
||||||
"resource_name": "test resource",
|
"resource_name": "test resource",
|
||||||
"event_id": util.GetUUID(),
|
"event_id": util.GetUUID(),
|
||||||
"timestamp": time.Now().UnixMilli(),
|
"timestamp": time.Now().UnixMilli(),
|
||||||
"first_group_value": "first group value",
|
"first_group_value": firstGrpValue,
|
||||||
"first_threshold": "90",
|
"first_threshold": "90",
|
||||||
"priority": "critical",
|
"priority": "critical",
|
||||||
"results": []util.MapStr{
|
"results": []util.MapStr{
|
||||||
{"threshold": "90",
|
{"threshold": "90",
|
||||||
"priority": "critical",
|
"priority": "critical",
|
||||||
"group_values": []string{"first group value", "second group value"},
|
"group_values": []string{firstGrpValue, "group_value2" },
|
||||||
"issue_timestamp": time.Now().UnixMilli()-500,
|
"issue_timestamp": time.Now().UnixMilli()-500,
|
||||||
"result_value": 90,
|
"result_value": 90,
|
||||||
"relation_values": util.MapStr{"a": 100, "b": 90},
|
"relation_values": util.MapStr{"a": 100, "b": 90},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"env": envVariables,
|
||||||
}
|
}
|
||||||
_, err, _ = common.PerformChannel(&obj, ctx)
|
_, err, _ = common.PerformChannel(&obj, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -43,6 +43,10 @@ func lookupMetadata(object string, property string, defaultValue string, id stri
|
||||||
)
|
)
|
||||||
switch object {
|
switch object {
|
||||||
case "cluster":
|
case "cluster":
|
||||||
|
meta := elastic.GetMetadata(id)
|
||||||
|
if meta == nil {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
cfg := elastic.GetConfig(id)
|
cfg := elastic.GetConfig(id)
|
||||||
buf = util.MustToJSONBytes(cfg)
|
buf = util.MustToJSONBytes(cfg)
|
||||||
err := util.FromJSONBytes(buf, &cfgM)
|
err := util.FromJSONBytes(buf, &cfgM)
|
||||||
|
|
Loading…
Reference in New Issue