Skip to content

Commit

Permalink
fix: external ServiceNow testability (#2500)
Browse files Browse the repository at this point in the history
* fix: external ServiceNow testability
  • Loading branch information
alespour authored May 6, 2021
1 parent 4ca7790 commit f6f7229
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
28 changes: 20 additions & 8 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9240,10 +9240,16 @@ func TestServer_ListServiceTests(t *testing.T) {
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/service-tests/servicenow"},
Name: "servicenow",
Options: client.ServiceTestOptions{
"alert_id": "id",
"source": "Kapacitor",
"level": "CRITICAL",
"message": "test servicenow alert",
"alert_id": "1001",
"message": "test servicenow message",
"level": "CRITICAL",
"source": "Kapacitor",
"node": "",
"type": "",
"resource": "",
"metric_name": "",
"message_key": "",
"additional_info": map[string]interface{}{},
},
},
{
Expand Down Expand Up @@ -9421,10 +9427,16 @@ func TestServer_ListServiceTests_WithPattern(t *testing.T) {
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/service-tests/servicenow"},
Name: "servicenow",
Options: client.ServiceTestOptions{
"alert_id": "id",
"source": "Kapacitor",
"level": "CRITICAL",
"message": "test servicenow alert",
"alert_id": "1001",
"message": "test servicenow message",
"level": "CRITICAL",
"source": "Kapacitor",
"node": "",
"type": "",
"resource": "",
"metric_name": "",
"message_key": "",
"additional_info": map[string]interface{}{},
},
},
{
Expand Down
33 changes: 23 additions & 10 deletions services/servicenow/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,25 @@ func (s *Service) StateChangesOnly() bool {
}

type testOptions struct {
AlertID string `json:"alert_id"`
Source string `json:"source"`
Level alert.Level `json:"level"`
Message string `json:"message"`
AlertID string `json:"alert_id"`
Message string `json:"message"`
Level alert.Level `json:"level"`
Source string `json:"source"`
Node string `json:"node"`
Type string `json:"type"`
Resource string `json:"resource"`
MetricName string `json:"metric_name"`
MessageKey string `json:"message_key"`
AdditionalInfo map[string]interface{} `json:"additional_info"`
}

func (s *Service) TestOptions() interface{} {
return &testOptions{
AlertID: "id",
Source: "Kapacitor",
Level: alert.Critical,
Message: "test servicenow alert",
AlertID: "1001",
Message: "test servicenow message",
Level: alert.Critical,
Source: "Kapacitor",
AdditionalInfo: map[string]interface{}{},
}
}

Expand All @@ -95,7 +102,13 @@ func (s *Service) Test(options interface{}) error {
}
c := s.config()
hc := &HandlerConfig{
Source: o.Source,
Source: o.Source,
Node: o.Node,
Type: o.Type,
Resource: o.Resource,
MetricName: o.MetricName,
MessageKey: o.MessageKey,
AdditionalInfo: o.AdditionalInfo,
}
data := &alert.EventData{
Fields: map[string]interface{}{},
Expand All @@ -105,7 +118,7 @@ func (s *Service) Test(options interface{}) error {
return s.Alert(c.URL, o.AlertID, o.Message, o.Level, data, hc)
}

func (s *Service) Alert(url, alertID string, message string, level alert.Level, data *alert.EventData, hc *HandlerConfig) error {
func (s *Service) Alert(url, alertID, message string, level alert.Level, data *alert.EventData, hc *HandlerConfig) error {
postUrl, post, err := s.preparePost(url, alertID, message, level, data, hc)
if err != nil {
return err
Expand Down

0 comments on commit f6f7229

Please sign in to comment.