[TASK] improve log message in webhooks

This commit is contained in:
Martin/Geno 2018-09-06 13:42:29 +02:00
parent 2155f245b7
commit 2d8949dc69
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 16 additions and 7 deletions

View File

@ -43,10 +43,13 @@ func handler(_ http.Header, body interface{}) *log.Entry {
} }
entry := log.NewEntry(nil) entry := log.NewEntry(nil)
entry = entry.WithField("hostname", request.Payload.VCSURL) entry = entry.WithFields(map[string]interface{}{
"hostname": request.Payload.VCSURL,
"url": request.Payload.BuildURL,
})
entry.Time = time.Now() entry.Time = time.Now()
entry.Level = HookstatusMap[request.Payload.Status] entry.Level = HookstatusMap[request.Payload.Status]
entry.Message = fmt.Sprintf("#%0.f (%0.fs): %s - %s", request.Payload.BuildNum, request.Payload.BuildTime/1000, request.Payload.Subject, request.Payload.BuildURL) entry.Message = fmt.Sprintf("#%0.f (%0.fs): %s", request.Payload.BuildNum, request.Payload.BuildTime/1000, request.Payload.Subject)
return entry return entry
} }

View File

@ -51,14 +51,20 @@ func handler(_ http.Header, body interface{}) *log.Entry {
} }
entry := log.NewEntry(nil) entry := log.NewEntry(nil)
entry = entry.WithField("hostname", request.RuleURL) entry = entry.WithFields(map[string]interface{}{
"hostname": request.RuleURL,
"ruleid": request.RuleID,
"url": request.RuleURL,
})
if request.ImageURL != "" {
entry = entry.WithField("imageurl", request.ImageURL)
}
entry.Time = time.Now() entry.Time = time.Now()
entry.Level = HookstateMap[request.State] entry.Level = HookstateMap[request.State]
if request.Message == "" { for _, e := range request.EvalMatches {
entry.Message = fmt.Sprintf("%s - %s: %s", request.Title, request.State, request.RuleURL) entry = entry.WithField(e.Metric, e.Value)
} else {
entry.Message = fmt.Sprintf("%s - %s: %s %s", request.Title, request.State, request.Message, request.RuleURL)
} }
entry.Message = fmt.Sprintf("%s: %s", request.Title, request.Message)
return entry return entry
} }