未验证 提交 b00b7817 编写于 作者: Q qinyening 提交者: GitHub

Support screen and alert template (#517)

上级 6b1e432f
...@@ -117,7 +117,7 @@ func pconf() { ...@@ -117,7 +117,7 @@ func pconf() {
func start() { func start() {
runner.Init() runner.Init()
fmt.Println("transfer start, use configuration file:", *conf) fmt.Println("judge start, use configuration file:", *conf)
fmt.Println("runner.Cwd:", runner.Cwd) fmt.Println("runner.Cwd:", runner.Cwd)
fmt.Println("runner.Hostname:", runner.Hostname) fmt.Println("runner.Hostname:", runner.Hostname)
} }
......
...@@ -29,6 +29,12 @@ type ConfYaml struct { ...@@ -29,6 +29,12 @@ type ConfYaml struct {
Link linkSection `yaml:"link"` Link linkSection `yaml:"link"`
IndexMod string `yaml:"indexMod"` IndexMod string `yaml:"indexMod"`
I18n i18n.I18nSection `yaml:"i18n"` I18n i18n.I18nSection `yaml:"i18n"`
Tpl tplSection `yaml:"tpl"`
}
type tplSection struct {
AlertPath string `yaml:"alertPath"`
ScreenPath string `yaml:"screenPath"`
} }
type mergeSection struct { type mergeSection struct {
...@@ -175,6 +181,11 @@ func Parse(ymlfile string) error { ...@@ -175,6 +181,11 @@ func Parse(ymlfile string) error {
"converge": true, // 历史告警的数据库表,对于已收敛的告警,默认删掉,不保留,省得告警太多 "converge": true, // 历史告警的数据库表,对于已收敛的告警,默认删掉,不保留,省得告警太多
}) })
viper.SetDefault("tpl", map[string]string{
"alertPath": "./etc/alert",
"screenPath": "./etc/screen",
})
err = viper.Unmarshal(&yaml) err = viper.Unmarshal(&yaml)
if err != nil { if err != nil {
return fmt.Errorf("Unmarshal %v", err) return fmt.Errorf("Unmarshal %v", err)
......
...@@ -144,6 +144,12 @@ func Config(r *gin.Engine) { ...@@ -144,6 +144,12 @@ func Config(r *gin.Engine) {
aggr.GET("/:id", aggrCalcGet) aggr.GET("/:id", aggrCalcGet)
} }
tpl := r.Group("/api/mon/tpl")
{
tpl.GET("", tplNameGets)
tpl.GET("/content", tplGet)
}
aggrs := r.Group("/api/mon/aggrs").Use() aggrs := r.Group("/api/mon/aggrs").Use()
{ {
aggrs.GET("", aggrCalcsWithEndpointGet) aggrs.GET("", aggrCalcsWithEndpointGet)
......
package http
import (
"github.com/didi/nightingale/src/modules/monapi/config"
"github.com/gin-gonic/gin"
"github.com/toolkits/pkg/file"
)
func tplNameGets(c *gin.Context) {
tplType := mustQueryStr(c, "tplType")
var files []string
var err error
switch tplType {
case "alert":
files, err = file.FilesUnder(config.Get().Tpl.AlertPath)
dangerous(err)
case "screen":
files, err = file.FilesUnder(config.Get().Tpl.ScreenPath)
dangerous(err)
default:
bomb("tpl type not found")
}
renderData(c, files, err)
}
func tplGet(c *gin.Context) {
tplName := mustQueryStr(c, "tplName")
tplType := mustQueryStr(c, "tplType")
var filePath string
switch tplType {
case "alert":
filePath = config.Get().Tpl.AlertPath + "/" + tplName
case "screen":
filePath = config.Get().Tpl.ScreenPath + "/" + tplName
default:
bomb("tpl type not found")
}
if !file.IsExist(filePath) {
bomb("tpl not found")
}
content, err := file.ToString(filePath)
renderData(c, content, err)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册