Skip to content

Commit

Permalink
Merge pull request #192 from chehongshu/feature/20221227_add_InnerAle…
Browse files Browse the repository at this point in the history
…rtPub_func

add function : publish alert event
  • Loading branch information
shabicheng authored Dec 28, 2022
2 parents b3d0362 + 4495fc1 commit b47d8d5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions client_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,18 @@ func (c *Client) ListAlert(project, alertName, dashboard string, offset, size in
}
return listAlert.Results, listAlert.Total, listAlert.Count, err
}

func (c *Client) PublishAlertEvent(project string, alertResult []byte) error {
h := map[string]string{
"x-log-bodyrawsize": fmt.Sprintf("%v", len(alertResult)),
"Content-Type": "application/json",
}

uri := "/event/alerthub?type=raw"
r, err := c.request(project, "POST", uri, h, alertResult)
if err != nil {
return err
}
r.Body.Close()
return nil
}
3 changes: 3 additions & 0 deletions client_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,7 @@ type ClientInterface interface {
DeleteProjectPolicy(project string) error
// GetProjectPolicy return project's policy.
GetProjectPolicy(project string) (string, error)

// #################### AlertPub Msg #####################
PublishAlertEvent(project string, alertResult []byte) error
}
11 changes: 11 additions & 0 deletions token_auto_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1755,3 +1755,14 @@ func (c *TokenAutoUpdateClient) GetProjectPolicy(project string) (policy string,
}
return
}

func (c *TokenAutoUpdateClient) PublishAlertEvent(project string, alertResult []byte) error {
var err error = nil
for i := 0; i < c.maxTryTimes; i++ {
err = c.logClient.PublishAlertEvent(project, alertResult)
if err == nil {
break
}
}
return err
}

0 comments on commit b47d8d5

Please sign in to comment.