Compare commits
40 commits
29054e8242
...
31f7c51196
Author | SHA1 | Date | |
---|---|---|---|
31f7c51196 | |||
db71d22e8b | |||
ff37dd731f | |||
b1abe13ce1 | |||
03a2722feb | |||
8fa4a0aa16 | |||
de361cf23c | |||
67905c92be | |||
60641fbfee | |||
40c5e3b238 | |||
d051723d7b | |||
4d402778b0 | |||
eb7ac86759 | |||
e4e819ee90 | |||
2615da9ef8 | |||
2153dc8434 | |||
6ea61bf820 | |||
bdee792d75 | |||
d0c398f6f7 | |||
c423749f26 | |||
3b8a50d3e8 | |||
3f133e152a | |||
c4df60a89a | |||
c1a258f63c | |||
65cddbcc0d | |||
fb2387c212 | |||
170970e92d | |||
ea2cbfede5 | |||
fcd2cda803 | |||
4873da2851 | |||
01d16d4cba | |||
c83e2f1df7 | |||
90d61aed73 | |||
db5067c055 | |||
20dff10db8 | |||
5d348e7888 | |||
d917e13c4f | |||
5338bb0071 | |||
882d9fbefa | |||
c3233f1bc8 |
2 changed files with 29 additions and 7 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,15 +50,31 @@ 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 defaultBodyTemplate = template.Must(template.New("body").Funcs(common.FuncMap).Funcs(alertFm).Parse(defaultBodyTemplStr))
|
||||
var (
|
||||
defaultTemplate *template.Template
|
||||
)
|
||||
|
||||
var defaultSubjectTemplStr = `Stillbox Alert ({{ highest . }}`
|
||||
var defaultSubjectTemplate = template.Must(template.New("subject").Funcs(common.FuncMap).Funcs(alertFm).Parse(defaultSubjectTemplStr))
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// Send renders and sends the Alerts.
|
||||
func (b *backend) Send(ctx context.Context, alerts []alert.Alert) (err error) {
|
||||
|
@ -125,7 +141,10 @@ func (n *notifier) addService(cfg config.NotifyService) (err error) {
|
|||
|
||||
switch cfg.SubjectTemplate {
|
||||
case nil:
|
||||
be.subject = defaultSubjectTemplate
|
||||
be.subject = defaultTemplate.Lookup("subject")
|
||||
if be.subject == nil {
|
||||
panic("subject template nil")
|
||||
}
|
||||
default:
|
||||
be.subject, err = template.New("subject").Funcs(common.FuncMap).Funcs(alertFm).Parse(*cfg.SubjectTemplate)
|
||||
if err != nil {
|
||||
|
@ -135,7 +154,10 @@ func (n *notifier) addService(cfg config.NotifyService) (err error) {
|
|||
|
||||
switch cfg.BodyTemplate {
|
||||
case nil:
|
||||
be.body = defaultBodyTemplate
|
||||
be.body = defaultTemplate.Lookup("body")
|
||||
if be.body == nil {
|
||||
panic("body template nil")
|
||||
}
|
||||
default:
|
||||
be.body, err = template.New("body").Funcs(common.FuncMap).Funcs(alertFm).Parse(*cfg.BodyTemplate)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue