Skip to content
This repository was archived by the owner on Apr 7, 2024. It is now read-only.

Iti 0/feature/sigmasms #8

Merged
merged 20 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,12 @@ type SigmaConfig struct {
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
// URL to send POST request to.
URL *URL `yaml:"url" json:"url"`
APIKey Secret `yaml:"api_key,omitempty" json:"api_key,omitempty"`
Recipients []string `yaml:"recipients"`
NotificationType string `yaml:"notification_type"`
SenderName string `yaml:"sender_name"`
Text string `yaml:"text"`
TTS string `yaml:"tts"`
APIKey Secret `yaml:"api_key" json:"api_key"`
Recipient []string `yaml:"recipient" json:"recipient"`
NotificationType string `yaml:"notification_type" json:"notification_type"`
SenderName string `yaml:"sender_name" json:"sender_name"`
Text string `yaml:"text" json:"text"`
TTS string `yaml:"tts" json:"tts"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand Down
10 changes: 6 additions & 4 deletions notify/sigma/sigma.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func New(conf *config.SigmaConfig, t *template.Template, l log.Logger, httpOpts
type Request struct {
Recipient []string `json:"recipient"`
Type string `json:"type"`
Payload RequestPayload `json:"payload,omitempty"`
Payload RequestPayload `json:"payload"`
}

type RequestPayload struct {
Expand All @@ -79,7 +79,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
)

msg := Request{
Recipient: n.conf.Recipients,
Recipient: n.conf.Recipient,
Type: n.conf.NotificationType,
Payload: RequestPayload{
Sender: n.conf.SenderName,
Expand All @@ -97,15 +97,16 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
return false, errors.Wrap(err, "request error")
}
req.Header.Set("Authorization", string(n.conf.APIKey))
req.Header.Set("Content-NotificationType", "application/json")
req.Header.Set("Content-Type", "application/json")
req.WithContext(ctx)

resp, err := n.client.Do(req)
if err != nil {
return false, err
}
defer resp.Body.Close()

respBody, err := ioutil.ReadAll(req.Body)
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return false, err
}
Expand All @@ -120,4 +121,5 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
}

return false, nil

}