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 . }})"
|
# subjectTemplate: "Stillbox Alert ({{ highest . }})"
|
||||||
# bodyTemplate: |
|
# bodyTemplate: |
|
||||||
# {{ range . -}}
|
# {{ 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 -}}
|
# {{ end -}}
|
||||||
config:
|
config:
|
||||||
|
|
|
@ -16,6 +16,7 @@ type Alert struct {
|
||||||
ID int
|
ID int
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
TGName string
|
TGName string
|
||||||
|
Talkgroup *talkgroups.Talkgroup
|
||||||
Score trending.Score[talkgroups.ID]
|
Score trending.Score[talkgroups.ID]
|
||||||
OrigScore float64
|
OrigScore float64
|
||||||
Weight float32
|
Weight float32
|
||||||
|
@ -56,6 +57,7 @@ func Make(ctx context.Context, store talkgroups.Store, score trending.Score[talk
|
||||||
case nil:
|
case nil:
|
||||||
d.Weight = tgRecord.Talkgroup.Weight
|
d.Weight = tgRecord.Talkgroup.Weight
|
||||||
d.TGName = tgRecord.String()
|
d.TGName = tgRecord.String()
|
||||||
|
d.Talkgroup = tgRecord
|
||||||
default:
|
default:
|
||||||
system, has := store.SystemName(ctx, int(score.ID.System))
|
system, has := store.SystemName(ctx, int(score.ID.System))
|
||||||
if has {
|
if has {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package alerting
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"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) {
|
func (as *alerter) testNotifyHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
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)
|
alerts, err := as.eval(ctx, time.Now(), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("test notification eval")
|
log.Error().Err(err).Msg("test notification eval")
|
||||||
|
@ -207,6 +216,8 @@ func (as *alerter) testNotifyHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alerts = append(alerts, a)
|
||||||
|
|
||||||
err = as.notifier.Send(ctx, alerts)
|
err = as.notifier.Send(ctx, alerts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("test notification send")
|
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) GetLearned() bool { return false }
|
||||||
|
|
||||||
func (g Talkgroup) String() string {
|
func (g Talkgroup) String() string {
|
||||||
|
return g.StringTag(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g Talkgroup) StringTag(withTag bool) string {
|
||||||
switch {
|
switch {
|
||||||
case g.AlphaTag != nil:
|
case withTag && g.AlphaTag != nil:
|
||||||
return *g.AlphaTag
|
return *g.AlphaTag
|
||||||
case g.Name != nil && g.TGGroup != nil:
|
case g.Name != nil && g.TGGroup != nil:
|
||||||
return *g.TGGroup + " " + *g.Name
|
return *g.TGGroup + " " + *g.Name
|
||||||
|
|
|
@ -52,7 +52,7 @@ var alertFm = template.FuncMap{
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultBodyTemplStr = `{{ range . -}}
|
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 -}}`
|
{{ end -}}`
|
||||||
defaultSubjectTemplStr = `Stillbox Alert ({{ highest . }})`
|
defaultSubjectTemplStr = `Stillbox Alert ({{ highest . }})`
|
||||||
|
|
|
@ -119,6 +119,7 @@ func (rr *radioReferenceImporter) importTalkgroups(ctx context.Context, sys int,
|
||||||
Metadata: metadata,
|
Metadata: metadata,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
Weight: 1.0,
|
Weight: 1.0,
|
||||||
|
Alert: true,
|
||||||
},
|
},
|
||||||
System: database.System{
|
System: database.System{
|
||||||
ID: sys,
|
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].SystemID = int32(system)
|
||||||
input[i].Learned = common.PtrTo(false)
|
input[i].Learned = common.PtrTo(false)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var oerr error
|
var oerr error
|
||||||
|
|
Loading…
Reference in a new issue