Skip to content

Commit

Permalink
DEV-46341: add logzio opsgenie support (#40)
Browse files Browse the repository at this point in the history
* add logzio opsgenie contact point
  • Loading branch information
Jonathan-Eng authored Sep 26, 2024
1 parent da350c4 commit 523d10f
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 27 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
17 changes: 17 additions & 0 deletions pkg/services/ngalert/api/compat_contact_points.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
59 changes: 38 additions & 21 deletions pkg/services/ngalert/api/tooling/definitions/contact_points.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<R extends FieldValues> {
Expand Down Expand Up @@ -147,7 +146,7 @@ export function ChannelSubForm<R extends ChannelValues>({
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)}
/>
)}
Expand Down
1 change: 1 addition & 0 deletions public/app/plugins/datasource/alertmanager/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const receiverTypeNames: Record<string, string> = {
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',
Expand Down

0 comments on commit 523d10f

Please sign in to comment.