Skip to content

Commit

Permalink
Merge pull request #106 from aliyun/update_alert
Browse files Browse the repository at this point in the history
add alert field
  • Loading branch information
shabicheng authored Oct 26, 2020
2 parents b620e86 + c85fe5b commit b2ded96
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
22 changes: 11 additions & 11 deletions client_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ type AlertQuery struct {
}

type Notification struct {
Type string `json:"type"`
Content string `json:"content"`
EmailList []string `json:"emailList,omitempty"`
Method string `json:"method,omitempty"`
MobileList []string `json:"mobileList,omitempty"`
ServiceUri string `json:"serviceUri,omitempty"`
Type string `json:"type"`
Content string `json:"content"`
EmailList []string `json:"emailList,omitempty"`
Method string `json:"method,omitempty"`
MobileList []string `json:"mobileList,omitempty"`
ServiceUri string `json:"serviceUri,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}

type Schedule struct {
Expand Down Expand Up @@ -208,7 +209,6 @@ func (c *Client) ListSavedSearch(project string, savedSearchName string, offset,
return listSavedSearch.Savedsearches, listSavedSearch.Total, listSavedSearch.Count, err
}


func (c *Client) ListSavedSearchV2(project string, savedSearchName string, offset, size int) (savedSearches []string, savedsearchItems []ResponseSavedSearchItem, total int, count int, err error) {
h := map[string]string{
"x-log-bodyrawsize": "0",
Expand All @@ -221,14 +221,14 @@ func (c *Client) ListSavedSearchV2(project string, savedSearchName string, offse
uri := "/savedsearches"
r, err := c.request(project, "GET", uri, h, nil)
if err != nil {
return nil, nil,0, 0, err
return nil, nil, 0, 0, err
}
defer r.Body.Close()

type ListSavedSearch struct {
Total int `json:"total"`
Count int `json:"count"`
Savedsearches []string `json:"savedsearches"`
Total int `json:"total"`
Count int `json:"count"`
Savedsearches []string `json:"savedsearches"`
SavedsearchItems []ResponseSavedSearchItem `json:"savedsearchItems"`
}

Expand Down
15 changes: 15 additions & 0 deletions client_alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ func (s *AlertTestSuite) createAlert() error {
Content: "${alertName} triggered at ${firetime}",
MobileList: []string{"1234567891"},
},
{
Type: NotificationTypeWebhook,
Method: "OPTIONS",
Content: "${alertName} triggered at ${firetime}",
Headers: map[string]string{"content-type": "test", "name": "aliyun"},
ServiceUri: "https://www.aliyun.com/",
},
},
NotifyThreshold: 1,
},
Expand Down Expand Up @@ -166,6 +173,14 @@ func (s *AlertTestSuite) TestClient_GetAlert() {
getAlert, err := s.client.GetAlert(s.projectName, s.alertName)
s.Require().Nil(err)
s.Require().Equal(getAlert.Name, s.alertName)
s.Require().Equal(len(getAlert.Configuration.NotificationList), 3)
for _, v := range getAlert.Configuration.NotificationList {
if v.Type == NotificationTypeWebhook {
s.Require().Equal(v.Method, "OPTIONS")
s.Require().Equal(v.Headers, map[string]string{"content-type": "test", "name": "aliyun"})
}
}

err = s.client.DeleteAlert(s.projectName, s.alertName)
s.Require().Nil(err)
}
Expand Down

0 comments on commit b2ded96

Please sign in to comment.