From 523d10fe00813a04f04902fea542c1fa92eed36d Mon Sep 17 00:00:00 2001 From: Jonathan Engel <57597246+Jonathan-Eng@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:27:52 +0300 Subject: [PATCH] DEV-46341: add logzio opsgenie support (#40) * add logzio opsgenie contact point --- go.mod | 2 +- go.sum | 4 +- .../ngalert/api/compat_contact_points.go | 17 ++++++ .../api/tooling/definitions/contact_points.go | 59 ++++++++++++------- .../definitions/provisioning_contactpoints.go | 2 +- .../channels_config/available_channels.go | 31 ++++++++++ .../receivers/form/ChannelSubForm.tsx | 3 +- .../plugins/datasource/alertmanager/consts.ts | 1 + 8 files changed, 92 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index c254420d0e0ad..9db1b0bd9682e 100644 --- a/go.mod +++ b/go.mod @@ -519,6 +519,6 @@ replace xorm.io/xorm => ./pkg/util/xorm // This is required in order to get notification delivery errors from the receivers API. replace github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20240208102907-e82436ce63e6 -replace github.com/grafana/alerting => github.com/logzio/data-viz-alerting v0.0.0-20240709132848-5bf841d2c3d3 +replace github.com/grafana/alerting => github.com/logzio/data-viz-alerting v0.0.0-20240926134858-3220ec2366dc exclude github.com/mattn/go-sqlite3 v2.0.3+incompatible diff --git a/go.sum b/go.sum index b067c7fd16c31..56498e45ead0f 100644 --- a/go.sum +++ b/go.sum @@ -2892,8 +2892,8 @@ github.com/linkedin/goavro/v2 v2.10.0 h1:eTBIRoInBM88gITGXYtUSqqxLTFXfOsJBiX8ZMW github.com/linkedin/goavro/v2 v2.10.0/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA= github.com/linode/linodego v1.25.0 h1:zYMz0lTasD503jBu3tSRhzEmXHQN1zptCw5o71ibyyU= github.com/linode/linodego v1.25.0/go.mod h1:BMZI0pMM/YGjBis7pIXDPbcgYfCZLH0/UvzqtsGtG1c= -github.com/logzio/data-viz-alerting v0.0.0-20240709132848-5bf841d2c3d3 h1:fny0mkam3829TczE+J/QHYjsgaZZHYhJf0Z9YadD+kk= -github.com/logzio/data-viz-alerting v0.0.0-20240709132848-5bf841d2c3d3/go.mod h1:brTFeACal/cSZAR8XO/4LPKs7rzNfS86okl6QjSP1eY= +github.com/logzio/data-viz-alerting v0.0.0-20240926134858-3220ec2366dc h1:PwLcwpAa5kpbAOX8i6eeEJsLemW84IDopjjY3F6Enrc= +github.com/logzio/data-viz-alerting v0.0.0-20240926134858-3220ec2366dc/go.mod h1:brTFeACal/cSZAR8XO/4LPKs7rzNfS86okl6QjSP1eY= github.com/luna-duclos/instrumentedsql v0.0.0-20181127104832-b7d587d28109/go.mod h1:PWUIzhtavmOR965zfawVsHXbEuU1G29BPZ/CB3C7jXk= github.com/luna-duclos/instrumentedsql v1.1.2/go.mod h1:4LGbEqDnopzNAiyxPPDXhLspyunZxgPTMJBKtC6U0BQ= github.com/luna-duclos/instrumentedsql v1.1.3/go.mod h1:9J1njvFds+zN7y85EDhN9XNQLANWwZt2ULeIC8yMNYs= diff --git a/pkg/services/ngalert/api/compat_contact_points.go b/pkg/services/ngalert/api/compat_contact_points.go index b6afc5f83df10..f00207c797feb 100644 --- a/pkg/services/ngalert/api/compat_contact_points.go +++ b/pkg/services/ngalert/api/compat_contact_points.go @@ -105,6 +105,16 @@ func ContactPointToContactPointExport(cp definitions.ContactPoint) (notify.APIRe errs = append(errs, err) } } + + // LOGZ.IO GRAFANA CHANGE :: DEV-46341 - Add support for logzio opsgenie integration + for _, i := range cp.LogzioOpsgenie { + el, err := marshallIntegration(j, "logzio_opsgenie", i, i.DisableResolveMessage) + integration = append(integration, el) + if err != nil { + errs = append(errs, err) + } + } + // LOGZ.IO GRAFANA CHANGE :: end for _, i := range cp.Pagerduty { el, err := marshallIntegration(j, "pagerduty", i, i.DisableResolveMessage) integration = append(integration, el) @@ -264,6 +274,13 @@ func parseIntegration(json jsoniter.API, result *definitions.ContactPoint, recei if err = json.Unmarshal(data, &integration); err == nil { result.Opsgenie = append(result.Opsgenie, integration) } + // LOGZ.IO GRAFANA CHANGE :: DEV-46341 - Add support for logzio opsgenie integration + case "logzio_opsgenie": + integration := definitions.LogzioOpsgenieIntegration{DisableResolveMessage: disable} + if err = json.Unmarshal(data, &integration); err == nil { + result.LogzioOpsgenie = append(result.LogzioOpsgenie, integration) + } + // LOGZ.IO GRAFANA CHANGE :: end case "pagerduty": integration := definitions.PagerdutyIntegration{DisableResolveMessage: disable} if err = json.Unmarshal(data, &integration); err == nil { diff --git a/pkg/services/ngalert/api/tooling/definitions/contact_points.go b/pkg/services/ngalert/api/tooling/definitions/contact_points.go index b5569aa2845fd..7244599966c58 100644 --- a/pkg/services/ngalert/api/tooling/definitions/contact_points.go +++ b/pkg/services/ngalert/api/tooling/definitions/contact_points.go @@ -121,6 +121,22 @@ type OpsgenieIntegration struct { Responders []OpsgenieIntegrationResponder `json:"responders,omitempty" yaml:"responders,omitempty" hcl:"responders,block"` } +// LOGZ.IO GRAFANA CHANGE :: DEV-46341: Add Logzio Opsgenie Integration +type LogzioOpsgenieIntegration struct { + DisableResolveMessage *bool `json:"-" yaml:"-" hcl:"disable_resolve_message"` + + APIKey Secret `json:"apiKey" yaml:"apiKey" hcl:"api_key"` + + APIUrl *string `json:"apiUrl,omitempty" yaml:"apiUrl,omitempty" hcl:"url"` + Message *string `json:"message,omitempty" yaml:"message,omitempty" hcl:"message"` + Description *string `json:"description,omitempty" yaml:"description,omitempty" hcl:"description"` + AutoClose *bool `json:"autoClose,omitempty" yaml:"autoClose,omitempty" hcl:"auto_close"` + OverridePriority *bool `json:"overridePriority,omitempty" yaml:"overridePriority,omitempty" hcl:"override_priority"` + SendTagsAs *string `json:"sendTagsAs,omitempty" yaml:"sendTagsAs,omitempty" hcl:"send_tags_as"` +} + +// LOGZ.IO GRAFANA CHANGE :: end + type PagerdutyIntegration struct { DisableResolveMessage *bool `json:"-" yaml:"-" hcl:"disable_resolve_message"` @@ -269,25 +285,26 @@ type WecomIntegration struct { } type ContactPoint struct { - Name string `json:"name" yaml:"name" hcl:"name"` - Alertmanager []AlertmanagerIntegration `json:"alertmanager" yaml:"alertmanager" hcl:"alertmanager,block"` - Dingding []DingdingIntegration `json:"dingding" yaml:"dingding" hcl:"dingding,block"` - Discord []DiscordIntegration `json:"discord" yaml:"discord" hcl:"discord,block"` - Email []EmailIntegration `json:"email" yaml:"email" hcl:"email,block"` - Googlechat []GooglechatIntegration `json:"googlechat" yaml:"googlechat" hcl:"googlechat,block"` - Kafka []KafkaIntegration `json:"kafka" yaml:"kafka" hcl:"kafka,block"` - Line []LineIntegration `json:"line" yaml:"line" hcl:"line,block"` - Opsgenie []OpsgenieIntegration `json:"opsgenie" yaml:"opsgenie" hcl:"opsgenie,block"` - Pagerduty []PagerdutyIntegration `json:"pagerduty" yaml:"pagerduty" hcl:"pagerduty,block"` - OnCall []OnCallIntegration `json:"oncall" yaml:"oncall" hcl:"oncall,block"` - Pushover []PushoverIntegration `json:"pushover" yaml:"pushover" hcl:"pushover,block"` - Sensugo []SensugoIntegration `json:"sensugo" yaml:"sensugo" hcl:"sensugo,block"` - Slack []SlackIntegration `json:"slack" yaml:"slack" hcl:"slack,block"` - Teams []TeamsIntegration `json:"teams" yaml:"teams" hcl:"teams,block"` - Telegram []TelegramIntegration `json:"telegram" yaml:"telegram" hcl:"telegram,block"` - Threema []ThreemaIntegration `json:"threema" yaml:"threema" hcl:"threema,block"` - Victorops []VictoropsIntegration `json:"victorops" yaml:"victorops" hcl:"victorops,block"` - Webhook []WebhookIntegration `json:"webhook" yaml:"webhook" hcl:"webhook,block"` - Wecom []WecomIntegration `json:"wecom" yaml:"wecom" hcl:"wecom,block"` - Webex []WebexIntegration `json:"webex" yaml:"webex" hcl:"webex,block"` + Name string `json:"name" yaml:"name" hcl:"name"` + Alertmanager []AlertmanagerIntegration `json:"alertmanager" yaml:"alertmanager" hcl:"alertmanager,block"` + Dingding []DingdingIntegration `json:"dingding" yaml:"dingding" hcl:"dingding,block"` + Discord []DiscordIntegration `json:"discord" yaml:"discord" hcl:"discord,block"` + Email []EmailIntegration `json:"email" yaml:"email" hcl:"email,block"` + Googlechat []GooglechatIntegration `json:"googlechat" yaml:"googlechat" hcl:"googlechat,block"` + Kafka []KafkaIntegration `json:"kafka" yaml:"kafka" hcl:"kafka,block"` + Line []LineIntegration `json:"line" yaml:"line" hcl:"line,block"` + Opsgenie []OpsgenieIntegration `json:"opsgenie" yaml:"opsgenie" hcl:"opsgenie,block"` + LogzioOpsgenie []LogzioOpsgenieIntegration `json:"logzio_opsgenie" yaml:"logzio_opsgenie" hcl:"logzio_opsgenie,block"` // LOGZ.IO GRAFANA CHANGE :: DEV-46341: Add Logzio Opsgenie Integration + Pagerduty []PagerdutyIntegration `json:"pagerduty" yaml:"pagerduty" hcl:"pagerduty,block"` + OnCall []OnCallIntegration `json:"oncall" yaml:"oncall" hcl:"oncall,block"` + Pushover []PushoverIntegration `json:"pushover" yaml:"pushover" hcl:"pushover,block"` + Sensugo []SensugoIntegration `json:"sensugo" yaml:"sensugo" hcl:"sensugo,block"` + Slack []SlackIntegration `json:"slack" yaml:"slack" hcl:"slack,block"` + Teams []TeamsIntegration `json:"teams" yaml:"teams" hcl:"teams,block"` + Telegram []TelegramIntegration `json:"telegram" yaml:"telegram" hcl:"telegram,block"` + Threema []ThreemaIntegration `json:"threema" yaml:"threema" hcl:"threema,block"` + Victorops []VictoropsIntegration `json:"victorops" yaml:"victorops" hcl:"victorops,block"` + Webhook []WebhookIntegration `json:"webhook" yaml:"webhook" hcl:"webhook,block"` + Wecom []WecomIntegration `json:"wecom" yaml:"wecom" hcl:"wecom,block"` + Webex []WebexIntegration `json:"webex" yaml:"webex" hcl:"webex,block"` } diff --git a/pkg/services/ngalert/api/tooling/definitions/provisioning_contactpoints.go b/pkg/services/ngalert/api/tooling/definitions/provisioning_contactpoints.go index e7ca49a8043cc..b2f83c7344cb4 100644 --- a/pkg/services/ngalert/api/tooling/definitions/provisioning_contactpoints.go +++ b/pkg/services/ngalert/api/tooling/definitions/provisioning_contactpoints.go @@ -99,7 +99,7 @@ type EmbeddedContactPoint struct { Name string `json:"name" binding:"required"` // required: true // example: webhook - // enum: alertmanager, dingding, discord, email, googlechat, kafka, line, opsgenie, pagerduty, pushover, sensugo, slack, teams, telegram, threema, victorops, webhook, wecom + // enum: alertmanager, dingding, discord, email, googlechat, kafka, line, opsgenie, logzio_opsgenie, pagerduty, pushover, sensugo, slack, teams, telegram, threema, victorops, webhook, wecom // LOGZ.IO GRAFANA CHANGE :: DEV-46341 - Add support for logzio opsgenie integration Type string `json:"type" binding:"required"` // required: true Settings *simplejson.Json `json:"settings" binding:"required"` diff --git a/pkg/services/ngalert/notifier/channels_config/available_channels.go b/pkg/services/ngalert/notifier/channels_config/available_channels.go index b05138a79c4f9..880b1aed16675 100644 --- a/pkg/services/ngalert/notifier/channels_config/available_channels.go +++ b/pkg/services/ngalert/notifier/channels_config/available_channels.go @@ -1339,6 +1339,37 @@ func GetAvailableNotifiers() []*NotifierPlugin { }, }, }, + // LOGZ.IO GRAFANA CHANGE :: DEV-46341 - Add support for logzio opsgenie integration + { + Type: "logzio_opsgenie", + Name: "LogzioOpsGenie", + Description: "Sends notifications to OpsGenie with Logz.io integration", + Heading: "LogzioOpsGenie settings", + Options: []NotifierOption{ + { + Label: "API Key", + Element: ElementTypeInput, + InputType: InputTypeText, + Placeholder: "LogzioOpsGenie API Key", + PropertyName: "apiKey", + Required: true, + Secure: true, + }, + { + Label: "Description", + Description: "A description of the incident.", + Element: ElementTypeTextArea, + PropertyName: "description", + }, + { + Label: "Auto close incidents", + Element: ElementTypeCheckbox, + Description: "Automatically close alerts in LogzioOpsGenie once the alert goes back to ok.", + PropertyName: "autoClose", + }, + }, + }, + // LOGZ.IO GRAFANA CHANGE :: end { Type: "webex", Name: "Cisco Webex Teams", diff --git a/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx b/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx index c974cd2ec5024..9504333196ae7 100644 --- a/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx +++ b/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx @@ -15,7 +15,6 @@ import { CollapsibleSection } from './CollapsibleSection'; import { Notifier } from './notifiers'; // LOGZ.IO GRAFANA CHANGE :: DEV-35483 - Filter out logzio opsgenie type from creation -const INTERNAL_CHANNEL_TYPE_PREFIX = 'logzio_'; // LOGZ.IO GRAFANA CHANGE :: end interface Props { @@ -147,7 +146,7 @@ export function ChannelSubForm({ inputId={contactPointTypeInputId} {...field} width={37} - options={typeOptions.filter((o) => !o.value.startsWith(INTERNAL_CHANNEL_TYPE_PREFIX))} // LOGZ.IO GRAFANA CHANGE :: DEV-35483 - Filter out logzio opsgenie type from creation + options={typeOptions} onChange={(value) => onChange(value?.value)} /> )} diff --git a/public/app/plugins/datasource/alertmanager/consts.ts b/public/app/plugins/datasource/alertmanager/consts.ts index 7e63f989f84fc..ee35dea9d4fda 100644 --- a/public/app/plugins/datasource/alertmanager/consts.ts +++ b/public/app/plugins/datasource/alertmanager/consts.ts @@ -3,6 +3,7 @@ export const receiverTypeNames: Record = { pushover: 'Pushover', slack: 'Slack', opsgenie: 'OpsGenie', + logzio_opsgenie: 'LogzioOpsGenie', // LOGZ.IO GRAFANA CHANGE :: DEV-46341 - Add Logz.io OpsGenie integration webhook: 'Webhook', victorops: 'VictorOps', wechat: 'WeChat',