allow configuring keyword
This commit is contained in:
parent
043fe33e81
commit
1368582154
2 changed files with 10 additions and 7 deletions
|
|
@ -20,10 +20,10 @@ import (
|
|||
func initWebhook() {
|
||||
conf := configuration.ReadConfig()
|
||||
R.GET("/api/webhook/:secret", func(ctx *gin.Context) {
|
||||
triggerAlamosWebhook(ctx, false)
|
||||
triggerAlamosWebhook(ctx, false, conf)
|
||||
})
|
||||
R.GET("/api/webhook/:secret/test", func(ctx *gin.Context) {
|
||||
triggerAlamosWebhook(ctx, true)
|
||||
triggerAlamosWebhook(ctx, true, conf)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
@ -35,14 +35,15 @@ func initWebhook() {
|
|||
// @Success 200
|
||||
// @Param secret path string true "Smoke Detector secret"
|
||||
// @Router /api/webhook/{secret}/test [get]
|
||||
func triggerAlamosWebhook(ctx *gin.contect, test bool) {
|
||||
keyword := "smoke"
|
||||
if test {
|
||||
keyword = "smoketest"
|
||||
}
|
||||
func triggerAlamosWebhook(ctx *gin.contect, test bool, conf Config) {
|
||||
id := ctx.Param("secret")
|
||||
for _, sensor := range conf.SmokeDetectors {
|
||||
if sensor.ID == id {
|
||||
keyword := conf.Targets[sensor.Target].Keyword
|
||||
if test {
|
||||
keyword = conf.Targets[sensor.Target].KeywordTest
|
||||
}
|
||||
|
||||
log.Log.Debug("Set REST baseurl to ", conf.Targets[sensor.Target].URL)
|
||||
client := resty.New().SetBaseURL(conf.Targets[sensor.Target].URL)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ type Config struct {
|
|||
type Target struct {
|
||||
URL string `yaml:"url"`
|
||||
Secret string `yaml:"secret"`
|
||||
Keyword string `yaml:"keyword"`
|
||||
KeywordTest string `yaml:"keyword-test"`
|
||||
}
|
||||
|
||||
type SmokeDetector struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue