Skip to content

Commit

Permalink
Omit null JSON fields in Alerta request body (#10)
Browse files Browse the repository at this point in the history
Resolves #9
  • Loading branch information
dwaiting authored and satterly committed Jun 28, 2019
1 parent 894bca4 commit 98f1a4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ type Alert struct {
Event string `json:"event"`
Environment string `json:"environment"`
Severity string `json:"severity"`
Correlate []string `json:"correlate"`
Correlate []string `json:"correlate,omitempty"`
Status string `json:"status"`
Service []string `json:"service"`
Group string `json:"group"`
Value string `json:"value"`
Text string `json:"text"`
Tags []string `json:"tags"`
Attributes map[string]string `json:"attributes"`
Tags []string `json:"tags,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
Origin string `json:"origin"`
Type string `json:"type"`
CreateTime string `json:"createTime"`
CreateTime string `json:"createTime,omitempty"`
Timeout int `json:"timeout"`
RawData string `json:"rawData"`
}
Expand Down Expand Up @@ -203,4 +203,4 @@ func sendAlert(event *types.Event) error {
return err
}
return nil
}
}
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestSendAlert(t *testing.T) {

var apiStub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body)
expectedBody := `{"resource":"entity1","event":"check1","environment":"default","severity":"normal","correlate":null,"status":"","service":["Sensu"],"group":"default","value":"","text":"","tags":null,"attributes":null,"origin":"sensu-go/`
expectedBody := `{"resource":"entity1","event":"check1","environment":"default","severity":"normal","status":"","service":["Sensu"],"group":"default","value":"","text":"","origin":"sensu-go/`
assert.Contains(string(body), expectedBody)
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(`{"status": "ok"}`))
Expand Down

0 comments on commit 98f1a4b

Please sign in to comment.