Skip to content

Commit

Permalink
Fix pagerduty test that required server info
Browse files Browse the repository at this point in the history
  • Loading branch information
desa committed Aug 8, 2017
1 parent 3b873a2 commit c2dac67
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions integrations/streamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"html"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -7842,7 +7843,9 @@ func TestStream_AlertPagerDuty(t *testing.T) {
ts := pagerdutytest.NewServer()
defer ts.Close()

defaultDetails := "{"Name":"cpu","TaskName":"TestStream_Alert","Group":"host=serverA","Tags":{"host":"serverA"},"ServerInfo":{"Hostname":"","ClusterID":"","ServerID":""},"ID":"kapacitor/cpu/serverA","Fields":{"count":10},"Level":"CRITICAL","Time":"1971-01-01T00:00:10Z","Message":"CRITICAL alert for kapacitor/cpu/serverA"}\n"
defaultDetailsTmpl := `{"Name":"cpu","TaskName":"TestStream_Alert","Group":"host=serverA","Tags":{"host":"serverA"},"ServerInfo":{"Hostname":"%v","ClusterID":"%v","ServerID":"%v"},"ID":"kapacitor/cpu/serverA","Fields":{"count":10},"Level":"CRITICAL","Time":"1971-01-01T00:00:10Z","Message":"CRITICAL alert for kapacitor/cpu/serverA"}
`
var defaultDetails string

var script = `
stream
Expand All @@ -7867,6 +7870,12 @@ stream

var kapacitorURL string
tmInit := func(tm *kapacitor.TaskMaster) {
si := tm.ServerInfo
defaultDetails = fmt.Sprintf(defaultDetailsTmpl,
si.Hostname(),
si.ClusterID(),
si.ServerID(),
)
c := pagerduty.NewConfig()
c.Enabled = true
c.URL = ts.URL
Expand All @@ -7888,7 +7897,7 @@ stream
Description: "CRITICAL alert for kapacitor/cpu/serverA",
Client: "kapacitor",
ClientURL: kapacitorURL,
Details: defaultDetails,
Details: html.EscapeString(defaultDetails),
},
},
pagerdutytest.Request{
Expand All @@ -7899,7 +7908,7 @@ stream
Description: "CRITICAL alert for kapacitor/cpu/serverA",
Client: "kapacitor",
ClientURL: kapacitorURL,
Details: defaultDetails,
Details: html.EscapeString(defaultDetails),
},
},
}
Expand Down

0 comments on commit c2dac67

Please sign in to comment.