@@ -20,14 +20,13 @@ import (
2020 "fmt"
2121 "github.com/go-kit/log"
2222 "github.com/pkg/errors"
23+ "github.com/prometheus/alertmanager/config"
2324 "github.com/prometheus/alertmanager/notify"
25+ "github.com/prometheus/alertmanager/template"
2426 "github.com/prometheus/alertmanager/types"
2527 commoncfg "github.com/prometheus/common/config"
2628 "io/ioutil"
2729 "net/http"
28-
29- "github.com/prometheus/alertmanager/config"
30- "github.com/prometheus/alertmanager/template"
3130)
3231
3332// Notifier implements a Notifier for generic sigma.
@@ -52,8 +51,19 @@ func New(conf *config.SigmaConfig, t *template.Template, l log.Logger, httpOpts
5251 }, nil
5352}
5453
55- // Request Message defines the JSON object send to Sigma endpoints.
56- type Request struct {
54+ // RequestSms Message defines the JSON object send to Sigma endpoints.
55+ type RecipientVoice struct {
56+ Include []string `json:"include"`
57+ Exclude []string `json:"exclude"`
58+ }
59+
60+ type RequestVoice struct {
61+ Recipient RecipientVoice `json:"recipient"`
62+ Type string `json:"type"`
63+ Payload RequestPayload `json:"payload"`
64+ }
65+
66+ type RequestSms struct {
5767 Recipient []string `json:"recipient"`
5868 Type string `json:"type"`
5969 Payload RequestPayload `json:"payload"`
@@ -79,24 +89,44 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
7989 tmplText = notify .TmplText (n .tmpl , data , & err )
8090 )
8191
82- msg := Request {
83- Recipient : n .conf .Recipient ,
84- Type : n .conf .NotificationType ,
85- Payload : RequestPayload {
86- Sender : n .conf .SenderName ,
87- Text : tmplText (n .conf .Text ),
88- },
89- }
90- body , err := json .Marshal (msg )
91- if err != nil {
92- return false , err
92+ var body []byte
93+ switch n .conf .NotificationType {
94+ case "sms" :
95+ msg := RequestSms {
96+ Recipient : n .conf .Recipient ,
97+ Type : n .conf .NotificationType ,
98+ Payload : RequestPayload {
99+ Sender : n .conf .SenderName ,
100+ Text : tmplText (n .conf .Text ),
101+ },
102+ }
103+ body , err = json .Marshal (msg )
104+ if err != nil {
105+ return false , err
106+ }
107+ case "voice" :
108+ msg := RequestVoice {
109+ Recipient : RecipientVoice {
110+ Include : n .conf .Recipient ,
111+ },
112+ Type : n .conf .NotificationType ,
113+ Payload : RequestPayload {
114+ Sender : n .conf .SenderName ,
115+ Text : tmplText (n .conf .Text ),
116+ },
117+ }
118+ body , err = json .Marshal (msg )
119+ if err != nil {
120+ return false , err
121+ }
93122 }
94- bodyReader := bytes .NewReader (body )
95123
124+ bodyReader := bytes .NewReader (body )
96125 req , err := http .NewRequest ("POST" , n .conf .URL .String (), bodyReader )
97126 if err != nil {
98127 return false , errors .Wrap (err , "request error" )
99128 }
129+
100130 req .Header .Set ("Authorization" , string (n .conf .APIKey ))
101131 req .Header .Set ("Content-Type" , "application/json" )
102132 req .WithContext (ctx )
@@ -122,6 +152,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
122152 }
123153
124154 return false , nil
155+
125156}
126157
127158type Error struct {
0 commit comments