Alerting improvements
This commit is contained in:
parent
e7d59ed78c
commit
368f231b89
7 changed files with 21 additions and 4 deletions
|
@ -36,7 +36,7 @@ notify:
|
|||
# subjectTemplate: "Stillbox Alert ({{ highest . }})"
|
||||
# bodyTemplate: |
|
||||
# {{ range . -}}
|
||||
# {{ .TGName }} is active with a score of {{ f .Score.Score 4 }}! ({{ f .Score.RecentCount 0 }}/{{ .Score.Count }} recent calls)
|
||||
# {{ .TGName }}{{ if (and .Talkgroup .Talkgroup.AlphaTag) }} ({{ .Talkgroup.StringTag false -}}){{ end }} is active with a score of {{ f .Score.Score 4 }}! ({{ f .Score.RecentCount 0 }}/{{ .Score.Count }} recent calls)
|
||||
#
|
||||
# {{ end -}}
|
||||
config:
|
||||
|
|
|
@ -16,6 +16,7 @@ type Alert struct {
|
|||
ID int
|
||||
Timestamp time.Time
|
||||
TGName string
|
||||
Talkgroup *talkgroups.Talkgroup
|
||||
Score trending.Score[talkgroups.ID]
|
||||
OrigScore float64
|
||||
Weight float32
|
||||
|
@ -56,6 +57,7 @@ func Make(ctx context.Context, store talkgroups.Store, score trending.Score[talk
|
|||
case nil:
|
||||
d.Weight = tgRecord.Talkgroup.Weight
|
||||
d.TGName = tgRecord.String()
|
||||
d.Talkgroup = tgRecord
|
||||
default:
|
||||
system, has := store.SystemName(ctx, int(score.ID.System))
|
||||
if has {
|
||||
|
|
|
@ -3,6 +3,7 @@ package alerting
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"sort"
|
||||
"sync"
|
||||
|
@ -200,6 +201,14 @@ func (as *alerter) eval(ctx context.Context, now time.Time, testMode bool) ([]al
|
|||
func (as *alerter) testNotifyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
ridx := rand.Intn(len(as.scores))
|
||||
a, err := alert.Make(ctx, talkgroups.StoreFrom(ctx), as.scores[ridx], 1.0)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("test notify make alert fail")
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
alerts, err := as.eval(ctx, time.Now(), true)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("test notification eval")
|
||||
|
@ -207,6 +216,8 @@ func (as *alerter) testNotifyHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
alerts = append(alerts, a)
|
||||
|
||||
err = as.notifier.Send(ctx, alerts)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("test notification send")
|
||||
|
|
|
@ -21,8 +21,12 @@ func (g Talkgroup) GetSystem() System { return S
|
|||
func (g Talkgroup) GetLearned() bool { return false }
|
||||
|
||||
func (g Talkgroup) String() string {
|
||||
return g.StringTag(true)
|
||||
}
|
||||
|
||||
func (g Talkgroup) StringTag(withTag bool) string {
|
||||
switch {
|
||||
case g.AlphaTag != nil:
|
||||
case withTag && g.AlphaTag != nil:
|
||||
return *g.AlphaTag
|
||||
case g.Name != nil && g.TGGroup != nil:
|
||||
return *g.TGGroup + " " + *g.Name
|
||||
|
|
|
@ -52,7 +52,7 @@ var alertFm = template.FuncMap{
|
|||
|
||||
const (
|
||||
defaultBodyTemplStr = `{{ range . -}}
|
||||
{{ .TGName }} is active with a score of {{ f .Score.Score 4 }}! ({{ f .Score.RecentCount 0 }}/{{ .Score.Count }} recent calls)
|
||||
{{ .TGName }}{{ if (and .Talkgroup .Talkgroup.AlphaTag) }} ({{ .Talkgroup.StringTag false -}}){{ end }} is active with a score of {{ f .Score.Score 4 }}! ({{ f .Score.RecentCount 0 }}/{{ .Score.Count }} recent calls)
|
||||
|
||||
{{ end -}}`
|
||||
defaultSubjectTemplStr = `Stillbox Alert ({{ highest . }})`
|
||||
|
|
|
@ -119,6 +119,7 @@ func (rr *radioReferenceImporter) importTalkgroups(ctx context.Context, sys int,
|
|||
Metadata: metadata,
|
||||
Tags: tags,
|
||||
Weight: 1.0,
|
||||
Alert: true,
|
||||
},
|
||||
System: database.System{
|
||||
ID: sys,
|
||||
|
|
|
@ -320,7 +320,6 @@ func (t *cache) UpsertTGs(ctx context.Context, system int, input []database.Upse
|
|||
|
||||
input[i].SystemID = int32(system)
|
||||
input[i].Learned = common.PtrTo(false)
|
||||
|
||||
}
|
||||
|
||||
var oerr error
|
||||
|
|
Loading…
Reference in a new issue