Skip to content

Commit

Permalink
add alert filter field to alert action
Browse files Browse the repository at this point in the history
  • Loading branch information
STLVRTX committed Nov 24, 2022
1 parent b3662b0 commit 1f1e367
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 11 deletions.
104 changes: 94 additions & 10 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 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 1f1e367

Please sign in to comment.