Compare commits
33 commits
31f7c51196
...
29054e8242
Author | SHA1 | Date | |
---|---|---|---|
29054e8242 | |||
50109bc283 | |||
4bd8f3351a | |||
951e0459b8 | |||
2ec7924e86 | |||
558a57e797 | |||
6e0aade9d2 | |||
c891a94c7b | |||
21eabbc17a | |||
ab3219c434 | |||
5ea44aebb9 | |||
f3364a93ec | |||
81135c29f0 | |||
6556c8049c | |||
08f1bd4ff0 | |||
58c1376146 | |||
465e86a6bb | |||
10e4eff17a | |||
b40144447f | |||
092b925a25 | |||
28ee194297 | |||
5bce1f4f9d | |||
77cdacc917 | |||
7242782d39 | |||
8afc687d4f | |||
1f8fe24dd2 | |||
8d32757334 | |||
eebc3fdae2 | |||
50663a561a | |||
6b5e5dbdf1 | |||
38300f247a | |||
e198adb60b | |||
9fc4823159 |
2 changed files with 7 additions and 29 deletions
|
@ -64,7 +64,7 @@ func Make(ctx context.Context, store talkgroups.Store, score trending.Score[talk
|
|||
}
|
||||
|
||||
if tgRecord.Talkgroup.Name != nil {
|
||||
d.TGName = fmt.Sprintf("%s %s [%d]", tgRecord.System.Name, *tgRecord.Talkgroup.Name, score.ID.Talkgroup)
|
||||
d.TGName = fmt.Sprintf("%s %s (%d)", tgRecord.System.Name, *tgRecord.Talkgroup.Name, score.ID.Talkgroup)
|
||||
} else {
|
||||
d.TGName = fmt.Sprintf("%s:%d", tgRecord.System.Name, int(score.ID.Talkgroup))
|
||||
}
|
||||
|
|
|
@ -50,31 +50,15 @@ var alertFm = template.FuncMap{
|
|||
"highest": highest,
|
||||
}
|
||||
|
||||
const (
|
||||
defaultBodyTemplStr = `{{ range . -}}
|
||||
const defaultBodyTemplStr = `{{ range . -}}
|
||||
{{ .TGName }} is active with a score of {{ f .Score.Score 4 }}! ({{ f .Score.RecentCount 0 }}/{{ .Score.Count }} recent calls)
|
||||
|
||||
{{ end -}}`
|
||||
defaultSubjectTemplStr = `Stillbox Alert ({{ highest . }})`
|
||||
)
|
||||
|
||||
var (
|
||||
defaultTemplate *template.Template
|
||||
)
|
||||
var defaultBodyTemplate = template.Must(template.New("body").Funcs(common.FuncMap).Funcs(alertFm).Parse(defaultBodyTemplStr))
|
||||
|
||||
func init() {
|
||||
defaultTemplate = template.New("notification")
|
||||
defaultTemplate.Funcs(common.FuncMap).Funcs(alertFm)
|
||||
_, err := defaultTemplate.New("body").Parse(defaultBodyTemplStr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = defaultTemplate.New("subject").Parse(defaultSubjectTemplStr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
var defaultSubjectTemplStr = `Stillbox Alert ({{ highest . }}`
|
||||
var defaultSubjectTemplate = template.Must(template.New("subject").Funcs(common.FuncMap).Funcs(alertFm).Parse(defaultSubjectTemplStr))
|
||||
|
||||
// Send renders and sends the Alerts.
|
||||
func (b *backend) Send(ctx context.Context, alerts []alert.Alert) (err error) {
|
||||
|
@ -141,10 +125,7 @@ func (n *notifier) addService(cfg config.NotifyService) (err error) {
|
|||
|
||||
switch cfg.SubjectTemplate {
|
||||
case nil:
|
||||
be.subject = defaultTemplate.Lookup("subject")
|
||||
if be.subject == nil {
|
||||
panic("subject template nil")
|
||||
}
|
||||
be.subject = defaultSubjectTemplate
|
||||
default:
|
||||
be.subject, err = template.New("subject").Funcs(common.FuncMap).Funcs(alertFm).Parse(*cfg.SubjectTemplate)
|
||||
if err != nil {
|
||||
|
@ -154,10 +135,7 @@ func (n *notifier) addService(cfg config.NotifyService) (err error) {
|
|||
|
||||
switch cfg.BodyTemplate {
|
||||
case nil:
|
||||
be.body = defaultTemplate.Lookup("body")
|
||||
if be.body == nil {
|
||||
panic("body template nil")
|
||||
}
|
||||
be.body = defaultBodyTemplate
|
||||
default:
|
||||
be.body, err = template.New("body").Funcs(common.FuncMap).Funcs(alertFm).Parse(*cfg.BodyTemplate)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue