Skip to content

Commit

Permalink
[alerting] Add target ip to available alert fields. (#548)
Browse files Browse the repository at this point in the history
Also remove duplicate template constant in alerting.go.
  • Loading branch information
manugarg committed Oct 5, 2023
1 parent 7d836a9 commit a8b0282
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
14 changes: 0 additions & 14 deletions probes/alerting/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ import (
"google.golang.org/protobuf/proto"
)

const (
DefaultDashboardURLTemplate = "http://localhost:9313/status?probe=@probe@"
DefaultSummaryTemplate = "Cloudprober alert @alert@ for @target@"
DefaultDetailsTemplate = `Cloudprober alert "@alert@" for "@target@":
Failures: @failures@ out of @total@ probes
Failing since: @since@
Probe: @probe@
Dashboard: @dashboard_url@
Playbook: @playbook_url@
Condition ID: @condition_id@
`
)

type targetState struct {
lastSuccess int64
lastTotal int64
Expand Down
4 changes: 4 additions & 0 deletions probes/alerting/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (n *Notifier) alertFields(alertInfo *AlertInfo) (map[string]string, error)
fields["target.label."+k] = v
}

if alertInfo.Target.IP != nil {
fields["target_ip"] = alertInfo.Target.IP.String()
}

alertJSON, err := json.Marshal(fields)
if err != nil {
return nil, fmt.Errorf("error marshalling alert fields into json: %v", err)
Expand Down
5 changes: 4 additions & 1 deletion probes/alerting/notifier/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package notifier

import (
"context"
"net"
"net/smtp"
"testing"
"time"
Expand All @@ -28,6 +29,7 @@ import (
func TestAlertFields(t *testing.T) {
testTarget := endpoint.Endpoint{
Name: "test-target",
IP: net.ParseIP("10.11.12.13"),
Labels: map[string]string{
"apptype": "backend",
"language": "go",
Expand Down Expand Up @@ -55,12 +57,13 @@ func TestAlertFields(t *testing.T) {
"probe": "test-probe",
"condition_id": "122333444",
"target": "test-target",
"target_ip": "10.11.12.13",
"failures": "8",
"total": "12",
"since": "0001-01-01T00:00:01Z",
"target.label.apptype": "backend",
"target.label.language": "go",
"json": `{"alert":"test-alert","condition_id":"122333444","failures":"8","probe":"test-probe","since":"0001-01-01T00:00:01Z","target":"test-target","target.label.apptype":"backend","target.label.language":"go","total":"12"}`,
"json": `{"alert":"test-alert","condition_id":"122333444","failures":"8","probe":"test-probe","since":"0001-01-01T00:00:01Z","target":"test-target","target.label.apptype":"backend","target.label.language":"go","target_ip":"10.11.12.13","total":"12"}`,
"summary": "Cloudprober alert test-alert for test-target",
"details": "Cloudprober alert \"test-alert\" for \"test-target\":\n\nFailures: 8 out of 12 probes\nFailing since: 0001-01-01T00:00:01Z\nProbe: test-probe\nDashboard: @dashboard_url@\nPlaybook: \nCondition ID: 122333444\n",
"playbook_url": "",
Expand Down

0 comments on commit a8b0282

Please sign in to comment.