Skip to content

Commit

Permalink
Merge pull request #43 from iLert/feature/new-api-resources
Browse files Browse the repository at this point in the history
Feature/new api resources pt.1
  • Loading branch information
STLVRTX authored Aug 22, 2024
2 parents ec1c9d4 + 27a402b commit 9882f29
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 32 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## 22.08.2024, Version 3.9.0

- add new api resources/fields pt.1 [#42](https://github.com/iLert/ilert-go/pull/42)
- alert action
- deprecate `delaySec` in favor of more specific `escalationEndedDelaySec` and `notResolvedDelaySec`
- new trigger type `AlertNotResolved`
- new alert action type `SlackWebhook`
- alert source
- new alert grouping type `intelligentGrouping`
- add field `scoreThreshold`
- add event filter
- add includes for POST and PUT API calls
- status page
- add email login via `emailWhitelist`
- add `announcement` fields
- add `metrics`

## 09.05.2024, Version 3.8.1

- add region to user [#41](https://github.com/iLert/ilert-go/pull/41)
Expand Down
68 changes: 40 additions & 28 deletions alert_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,42 @@ 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,omitempty"` // @deprecated
AlertSources *[]AlertSource `json:"alertSources,omitempty"`
ConnectorID string `json:"connectorId,omitempty"`
ConnectorType string `json:"connectorType"`
TriggerMode string `json:"triggerMode"`
DelaySec int `json:"delaySec,omitempty"` // between 0 and 7200, only allowed with triggerType 'alert-escalation-ended'
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"`
Teams *[]TeamShort `json:"teams,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name"`
AlertSourceIDs []int64 `json:"alertSourceIds,omitempty"` // @deprecated
AlertSources *[]AlertSource `json:"alertSources,omitempty"`
ConnectorID string `json:"connectorId,omitempty"`
ConnectorType string `json:"connectorType"`
TriggerMode string `json:"triggerMode"`
DelaySec int `json:"delaySec,omitempty"` // @deprecated
EscalationEndedDelaySec int `json:"escalationEndedDelaySec,omitempty"` // between 0 and 7200, used with triggerType 'AlertEscalationEnded'
NotResolvedDelaySec int `json:"notResolvedDelaySec,omitempty"` // between 0 and 7200, used with triggerType 'AlertNotResolved'
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"`
Teams *[]TeamShort `json:"teams,omitempty"`
}

// AlertActionOutput definition https://api.ilert.com/api-docs/#tag/Alert-Actions
type AlertActionOutput struct {
ID string `json:"id"`
Name string `json:"name"`
AlertSourceIDs []int64 `json:"alertSourceIds,omitempty"` // @deprecated
AlertSources *[]AlertSource `json:"alertSources,omitempty"`
ConnectorID string `json:"connectorId"`
ConnectorType string `json:"connectorType"`
TriggerMode string `json:"triggerMode"`
DelaySec int `json:"delaySec,omitempty"` // between 0 and 7200, only allowed with triggerType 'alert-escalation-ended'
TriggerTypes []string `json:"triggerTypes,omitempty"`
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"`
Teams *[]TeamShort `json:"teams,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
AlertSourceIDs []int64 `json:"alertSourceIds,omitempty"` // @deprecated
AlertSources *[]AlertSource `json:"alertSources,omitempty"`
ConnectorID string `json:"connectorId"`
ConnectorType string `json:"connectorType"`
TriggerMode string `json:"triggerMode"`
DelaySec int `json:"delaySec,omitempty"` // @deprecated
EscalationEndedDelaySec int `json:"escalationEndedDelaySec,omitempty"` // between 0 and 7200, used with triggerType 'AlertEscalationEnded'
NotResolvedDelaySec int `json:"notResolvedDelaySec,omitempty"` // between 0 and 7200, used with triggerType 'AlertNotResolved'
TriggerTypes []string `json:"triggerTypes,omitempty"`
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"`
Teams *[]TeamShort `json:"teams,omitempty"`
}

// AlertActionOutputParams definition
Expand Down Expand Up @@ -122,6 +126,11 @@ type AlertActionParamsMicrosoftTeamsWebhook struct {
URL string `json:"url,omitempty"`
}

// AlertActionParamsSlackWebhook definition
type AlertActionParamsSlackWebhook struct {
URL string `json:"url,omitempty"`
}

// AlertActionParamsServiceNow definition
type AlertActionParamsServiceNow struct {
CallerID string `json:"callerId,omitempty"` // user email
Expand Down Expand Up @@ -257,6 +266,7 @@ var AlertActionTriggerTypes = struct {
AlertResponderRemoved string
AlertChannelAttached string
AlertChannelDetached string
AlertNotResolved string
}{
AlertCreated: "alert-created",
AlertAssigned: "alert-assigned",
Expand All @@ -271,6 +281,7 @@ var AlertActionTriggerTypes = struct {
AlertResponderRemoved: "alert-responder-removed",
AlertChannelAttached: "alert-channel-attached",
AlertChannelDetached: "alert-channel-detached",
AlertNotResolved: "v-alert-not-resolved",
}

// AlertActionTriggerTypesAll defines all alertAction trigger types
Expand All @@ -288,6 +299,7 @@ var AlertActionTriggerTypesAll = []string{
AlertActionTriggerTypes.AlertResponderRemoved,
AlertActionTriggerTypes.AlertChannelAttached,
AlertActionTriggerTypes.AlertChannelDetached,
AlertActionTriggerTypes.AlertNotResolved,
}

// AlertFilterOperator defines alertFilter operator
Expand Down
31 changes: 28 additions & 3 deletions alert_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type AlertSource struct {
LinkTemplates []LinkTemplate `json:"linkTemplates,omitempty"`
PriorityTemplate *PriorityTemplate `json:"priorityTemplate,omitempty"`
AlertGroupingWindow string `json:"alertGroupingWindow,omitempty"` // e.g. PT4H
ScoreThreshold float64 `json:"scoreThreshold,omitempty"`
EventFilter string `json:"eventFilter,omitempty"`
}

// EmailPredicate definition
Expand Down Expand Up @@ -165,6 +167,7 @@ var AlertSourceAlertCreations = struct {
OneOpenAlertAllowed string
OpenResolveOnExtraction string
OneAlertGroupedPerWindow string
IntelligentGrouping string
}{
// @deprecated
OneIncidentPerEmail: "ONE_INCIDENT_PER_EMAIL",
Expand All @@ -178,6 +181,7 @@ var AlertSourceAlertCreations = struct {
OneOpenAlertAllowed: "ONE_OPEN_ALERT_ALLOWED",
OpenResolveOnExtraction: "OPEN_RESOLVE_ON_EXTRACTION",
OneAlertGroupedPerWindow: "ONE_ALERT_GROUPED_PER_WINDOW",
IntelligentGrouping: "INTELLIGENT_GROUPING",
}

// AlertSourceAlertCreationsAll defines alert source alert creations list
Expand All @@ -194,6 +198,7 @@ var AlertSourceAlertCreationsAll = []string{
AlertSourceAlertCreations.OneOpenAlertAllowed,
AlertSourceAlertCreations.OpenResolveOnExtraction,
AlertSourceAlertCreations.OneAlertGroupedPerWindow,
AlertSourceAlertCreations.IntelligentGrouping,
}

// AlertSourceAlertGroupingWindows defines alert source alert grouping windows
Expand Down Expand Up @@ -464,6 +469,10 @@ var AlertSourceIntegrationTypesAll = []string{
type CreateAlertSourceInput struct {
_ struct{}
AlertSource *AlertSource

// describes optional properties that should be included in the response
// possible values: "summaryTemplate", "detailsTemplate", "routingTemplate", "textTemplate", "linkTemplates", "priorityTemplate", "eventFilter"
Include []*string
}

// CreateAlertSourceOutput represents the output of a CreateAlertSource operation.
Expand Down Expand Up @@ -501,7 +510,13 @@ func (c *Client) CreateAlertSource(input *CreateAlertSourceInput) (*CreateAlertS
v.RemoveLegacyFields()
}

resp, err := c.httpClient.R().SetBody(input.AlertSource).Post(apiRoutes.alertSources)
q := url.Values{}

for _, include := range input.Include {
q.Add("include", *include)
}

resp, err := c.httpClient.R().SetBody(input.AlertSource).Post(fmt.Sprintf("%s?%s", apiRoutes.alertSources, q.Encode()))
if err != nil {
return nil, err
}
Expand All @@ -524,7 +539,7 @@ type GetAlertSourceInput struct {
AlertSourceID *int64

// describes optional properties that should be included in the response
// possible values: "summaryTemplate", "detailsTemplate", "routingTemplate", "textTemplate", "linkTemplates", "priorityTemplate"
// possible values: "summaryTemplate", "detailsTemplate", "routingTemplate", "textTemplate", "linkTemplates", "priorityTemplate", "eventFilter"
Include []*string
}

Expand Down Expand Up @@ -654,6 +669,10 @@ type UpdateAlertSourceInput struct {
_ struct{}
AlertSourceID *int64
AlertSource *AlertSource

// describes optional properties that should be included in the response
// possible values: "summaryTemplate", "detailsTemplate", "routingTemplate", "textTemplate", "linkTemplates", "priorityTemplate", "eventFilter"
Include []*string
}

// UpdateAlertSourceOutput represents the output of a UpdateAlertSource operation.
Expand Down Expand Up @@ -694,7 +713,13 @@ func (c *Client) UpdateAlertSource(input *UpdateAlertSourceInput) (*UpdateAlertS
v.RemoveLegacyFields()
}

resp, err := c.httpClient.R().SetBody(input.AlertSource).Put(fmt.Sprintf("%s/%d", apiRoutes.alertSources, *input.AlertSourceID))
q := url.Values{}

for _, include := range input.Include {
q.Add("include", *include)
}

resp, err := c.httpClient.R().SetBody(input.AlertSource).Put(fmt.Sprintf("%s/%d?%s", apiRoutes.alertSources, *input.AlertSourceID, q.Encode()))
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ var ConnectorTypes = struct {
MicrosoftTeamsWebhook string
ServiceNow string
Slack string
SlackWebhook string
Telegram string
Topdesk string
Webhook string
Expand All @@ -175,6 +176,7 @@ var ConnectorTypes = struct {
MicrosoftTeamsWebhook: "microsoft_teams_webhook",
ServiceNow: "servicenow",
Slack: "slack",
SlackWebhook: "slack_webhook",
Telegram: "telegram",
Topdesk: "topdesk",
Webhook: "webhook",
Expand All @@ -198,6 +200,7 @@ var ConnectorTypesAll = []string{
ConnectorTypes.MicrosoftTeamsWebhook,
ConnectorTypes.ServiceNow,
ConnectorTypes.Slack,
ConnectorTypes.SlackWebhook,
ConnectorTypes.Telegram,
ConnectorTypes.Topdesk,
ConnectorTypes.Webhook,
Expand Down
5 changes: 5 additions & 0 deletions status_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type StatusPage struct {
Structure *StatusPageStructure `json:"structure,omitempty"`
ThemeMode string `json:"themeMode,omitempty"` // please use field `Appearance` instead
Appearance string `json:"appearance,omitempty"`
EmailWhitelist []string `json:"emailWhitelist,omitempty"`
Announcement string `json:"announcement,omitempty"`
AnnouncementOnPage bool `json:"announcementOnPage,omitempty"`
AnnouncementInWidget bool `json:"announcementInWidget,omitempty"`
Metrics []Metric `json:"metrics,omitempty"`
}

// StatusPageStructure defines status page structure
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 = "v3.8.3"
const Version = "v3.9.0"

0 comments on commit 9882f29

Please sign in to comment.