Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[alerting] Add target ip to available alert fields. #548

Merged
merged 1 commit into from
Oct 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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