Skip to content

Commit

Permalink
Merge pull request #17 from iLert/feature/add-alert-action-alert-filter
Browse files Browse the repository at this point in the history
Feature/add alert action alert filter
  • Loading branch information
yacut authored Nov 25, 2022
2 parents b3662b0 + 993b8cb commit 26e74c3
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 23 deletions.
128 changes: 106 additions & 22 deletions alertaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import (

// AlertAction definition https://api.ilert.com/api-docs/#tag/Alert-Actions
type AlertAction struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
AlertSourceIDs []int64 `json:"alertSourceIds"`
ConnectorID string `json:"connectorId"`
ConnectorType string `json:"connectorType"`
TriggerMode string `json:"triggerMode"`
TriggerTypes []string `json:"triggerTypes,omitempty"`
CreatedAt string `json:"createdAt,omitempty"` // date time string in ISO 8601
UpdatedAt string `json:"updatedAt,omitempty"` // date time string in ISO 8601
Params interface{} `json:"params"`
ID string `json:"id,omitempty"`
Name string `json:"name"`
AlertSourceIDs []int64 `json:"alertSourceIds"`
ConnectorID string `json:"connectorId"`
ConnectorType string `json:"connectorType"`
TriggerMode string `json:"triggerMode"`
TriggerTypes []string `json:"triggerTypes,omitempty"`
CreatedAt string `json:"createdAt,omitempty"` // date time string in ISO 8601
UpdatedAt string `json:"updatedAt,omitempty"` // date time string in ISO 8601
Params interface{} `json:"params"`
AlertFilter *AlertFilter `json:"alertFilter,omitempty"`
}

// AlertActionOutput definition https://api.ilert.com/api-docs/#tag/Alert-Actions
Expand All @@ -32,6 +33,7 @@ type AlertActionOutput struct {
CreatedAt string `json:"createdAt"` // date time string in ISO 8601
UpdatedAt string `json:"updatedAt"` // date time string in ISO 8601
Params *AlertActionOutputParams `json:"params"`
AlertFilter *AlertFilter `json:"alertFilter,omitempty"`
}

// AlertActionOutputParams definition
Expand Down Expand Up @@ -223,6 +225,19 @@ type AlertActionResult struct {
Actor User `json:"actor"`
}

// AlertFilter definition
type AlertFilter struct {
Operator string `json:"operator"`
Predicates []AlertFilterPredicate `json:"predicates"`
}

// AlertFilterPredicate definition
type AlertFilterPredicate struct {
Field string `json:"field"`
Criteria string `json:"criteria"`
Value string `json:"value"`
}

// AlertActionTriggerModes defines alertAction trigger modes
var AlertActionTriggerModes = struct {
Automatic string
Expand Down Expand Up @@ -268,6 +283,75 @@ var AlertActionTriggerTypesAll = []string{
AlertActionTriggerTypes.AlertResolved,
}

// AlertFilterOperator defines alertFilter operator
var AlertFilterOperator = struct {
And string
Or string
}{
And: "AND",
Or: "OR",
}

// AlertFilterOperatorAll defines all alertFilter operator
var AlertFilterOperatorAll = []string{
AlertFilterOperator.And,
AlertFilterOperator.Or,
}

// AlertFilterPredicateFields defines alertFilter predicate fields
var AlertFilterPredicateFields = struct {
AlertSummary string
AlertDetails string
EscalationPolicy string
AlertPriority string
}{
AlertSummary: "ALERT_SUMMARY",
AlertDetails: "ALERT_DETAILS",
EscalationPolicy: "ESCALATION_POLICY",
AlertPriority: "ALERT_PRIORITY",
}

// AlertFilterPredicateFieldsAll defines all alertFilter predicate fields
var AlertFilterPredicateFieldsAll = []string{
AlertFilterPredicateFields.AlertSummary,
AlertFilterPredicateFields.AlertDetails,
AlertFilterPredicateFields.EscalationPolicy,
AlertFilterPredicateFields.AlertPriority,
}

// AlertFilterPredicateCriteria defines alertFilter predicate criteria
var AlertFilterPredicateCriteria = struct {
ContainsAnyWords string
ContainsNotWords string
ContainsString string
ContainsNotString string
IsString string
IsNotString string
MatchesRegex string
MatchesNotRegex string
}{
ContainsAnyWords: "CONTAINS_ANY_WORDS",
ContainsNotWords: "CONTAINS_NOT_WORDS",
ContainsString: "CONTAINS_STRING",
ContainsNotString: "CONTAINS_NOT_STRING",
IsString: "IS_STRING",
IsNotString: "IS_NOT_STRING",
MatchesRegex: "MATCHES_REGEX",
MatchesNotRegex: "MATCHES_NOT_REGEX",
}

// AlertFilterPredicateCriteriaAll defines all alertFilter predicate criteria
var AlertFilterPredicateCriteriaAll = []string{
AlertFilterPredicateCriteria.ContainsAnyWords,
AlertFilterPredicateCriteria.ContainsNotWords,
AlertFilterPredicateCriteria.ContainsString,
AlertFilterPredicateCriteria.ContainsNotString,
AlertFilterPredicateCriteria.IsString,
AlertFilterPredicateCriteria.IsNotString,
AlertFilterPredicateCriteria.MatchesRegex,
AlertFilterPredicateCriteria.MatchesNotRegex,
}

// CreateAlertActionInput represents the input of a CreateAlertAction operation.
type CreateAlertActionInput struct {
_ struct{}
Expand All @@ -280,13 +364,13 @@ type CreateAlertActionOutput struct {
AlertAction *AlertActionOutput
}

// CreateAlertAction creates a new alertAction https://api.ilert.com/api-docs/#tag/Alert-Actions/paths/~1alert-actions/post
// CreateAlertAction creates a new alert action https://api.ilert.com/api-docs/#tag/Alert-Actions/paths/~1alert-actions/post
func (c *Client) CreateAlertAction(input *CreateAlertActionInput) (*CreateAlertActionOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.AlertAction == nil {
return nil, errors.New("AlertAction input is required")
return nil, errors.New("alert action input is required")
}
resp, err := c.httpClient.R().SetBody(input.AlertAction).Post(apiRoutes.alertActions)
if err != nil {
Expand Down Expand Up @@ -317,13 +401,13 @@ type GetAlertActionOutput struct {
AlertAction *AlertActionOutput
}

// GetAlertAction gets the alertAction with specified id. https://api.ilert.com/api-docs/#tag/Alert-Actions/paths/~1alert-actions~1{id}/get
// GetAlertAction gets the alert action with specified id. https://api.ilert.com/api-docs/#tag/Alert-Actions/paths/~1alert-actions~1{id}/get
func (c *Client) GetAlertAction(input *GetAlertActionInput) (*GetAlertActionOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.AlertActionID == nil {
return nil, errors.New("AlertAction id is required")
return nil, errors.New("alert action id is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/%s", apiRoutes.alertActions, *input.AlertActionID))
Expand Down Expand Up @@ -354,7 +438,7 @@ type GetAlertActionsOutput struct {
AlertActions []*AlertActionOutput
}

// GetAlertActions lists alertActions. https://api.ilert.com/api-docs/#tag/Alert-Actions/paths/~1alert-actions/get
// GetAlertActions lists alert actions. https://api.ilert.com/api-docs/#tag/Alert-Actions/paths/~1alert-actions/get
func (c *Client) GetAlertActions(input *GetAlertActionsInput) (*GetAlertActionsOutput, error) {
resp, err := c.httpClient.R().Get(apiRoutes.alertActions)
if err != nil {
Expand Down Expand Up @@ -385,7 +469,7 @@ type SearchAlertActionOutput struct {
AlertAction *AlertActionOutput
}

// SearchAlertAction gets the alertAction with specified name.
// SearchAlertAction gets the alert action with specified name.
func (c *Client) SearchAlertAction(input *SearchAlertActionInput) (*SearchAlertActionOutput, error) {
if input == nil {
return nil, errors.New("input is required")
Expand All @@ -411,29 +495,29 @@ func (c *Client) SearchAlertAction(input *SearchAlertActionInput) (*SearchAlertA
return &SearchAlertActionOutput{AlertAction: alertAction}, nil
}

// UpdateAlertActionInput represents the input of a UpdateAlertAction operation.
// UpdateAlertActionInput represents the input of an UpdateAlertAction operation.
type UpdateAlertActionInput struct {
_ struct{}
AlertActionID *string
AlertAction *AlertAction
}

// UpdateAlertActionOutput represents the output of a UpdateAlertAction operation.
// UpdateAlertActionOutput represents the output of an UpdateAlertAction operation.
type UpdateAlertActionOutput struct {
_ struct{}
AlertAction *AlertActionOutput
}

// UpdateAlertAction updates an existing alertAction. https://api.ilert.com/api-docs/#tag/Alert-Actions/paths/~1alert-actions~1{id}/put
// UpdateAlertAction updates an existing alert action. https://api.ilert.com/api-docs/#tag/Alert-Actions/paths/~1alert-actions~1{id}/put
func (c *Client) UpdateAlertAction(input *UpdateAlertActionInput) (*UpdateAlertActionOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.AlertAction == nil {
return nil, errors.New("AlertAction input is required")
return nil, errors.New("alert action input is required")
}
if input.AlertActionID == nil {
return nil, errors.New("AlertAction id is required")
return nil, errors.New("alert action id is required")
}

resp, err := c.httpClient.R().SetBody(input.AlertAction).Put(fmt.Sprintf("%s/%s", apiRoutes.alertActions, *input.AlertActionID))
Expand Down Expand Up @@ -470,7 +554,7 @@ func (c *Client) DeleteAlertAction(input *DeleteAlertActionInput) (*DeleteAlertA
return nil, errors.New("input is required")
}
if input.AlertActionID == nil {
return nil, errors.New("AlertAction id is required")
return nil, errors.New("alert action id is required")
}

resp, err := c.httpClient.R().Delete(fmt.Sprintf("%s/%s", apiRoutes.alertActions, *input.AlertActionID))
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ilert

// Version package version
const Version = "v2.3.1"
const Version = "v2.3.2"

0 comments on commit 26e74c3

Please sign in to comment.