Alerting: Add MQTT notifications receiver (#91487)

* Alerting: Add MQTT notifications receiver
* Update alerting to 9daa6239cc41dc42bff0e916c8d0d27766caa8b9 (main)
---------

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
This commit is contained in:
Alexander Akhmetov
2024-08-22 16:47:48 +02:00
committed by GitHub
co-authored by Jack Baldry brendamuir
parent 9c73916f09
commit 832bb01f36
12 changed files with 324 additions and 5 deletions
@@ -51,7 +51,7 @@ func ContactPointToContactPointExport(cp definitions.ContactPoint) (notify.APIRe
len(cp.Pagerduty) + len(cp.OnCall) + len(cp.Pushover) + len(cp.Sensugo) +
len(cp.Sns) + len(cp.Slack) + len(cp.Teams) + len(cp.Telegram) +
len(cp.Threema) + len(cp.Victorops) + len(cp.Webhook) + len(cp.Wecom) +
len(cp.Webex)
len(cp.Webex) + len(cp.Mqtt)
integration := make([]*notify.GrafanaIntegrationConfig, 0, contactPointsLength)
@@ -105,6 +105,13 @@ func ContactPointToContactPointExport(cp definitions.ContactPoint) (notify.APIRe
}
integration = append(integration, el)
}
for _, i := range cp.Mqtt {
el, err := marshallIntegration(j, "mqtt", i, i.DisableResolveMessage)
if err != nil {
errs = append(errs, err)
}
integration = append(integration, el)
}
for _, i := range cp.Opsgenie {
el, err := marshallIntegration(j, "opsgenie", i, i.DisableResolveMessage)
if err != nil {
@@ -274,6 +281,11 @@ func parseIntegration(json jsoniter.API, result *definitions.ContactPoint, recei
if err = json.Unmarshal(data, &integration); err == nil {
result.Line = append(result.Line, integration)
}
case "mqtt":
integration := definitions.MqttIntegration{DisableResolveMessage: disable}
if err = json.Unmarshal(data, &integration); err == nil {
result.Mqtt = append(result.Mqtt, integration)
}
case "opsgenie":
integration := definitions.OpsgenieIntegration{DisableResolveMessage: disable}
if err = json.Unmarshal(data, &integration); err == nil {
@@ -85,6 +85,19 @@ type LineIntegration struct {
Description *string `json:"description,omitempty" yaml:"description,omitempty" hcl:"description"`
}
type MqttIntegration struct {
DisableResolveMessage *bool `json:"-" yaml:"-" hcl:"disable_resolve_message"`
BrokerURL *string `json:"brokerUrl,omitempty" yaml:"brokerUrl,omitempty" hcl:"broker_url"`
ClientID *string `json:"clientId,omitempty" yaml:"clientId,omitempty" hcl:"client_id"`
Topic *string `json:"topic,omitempty" yaml:"topic,omitempty" hcl:"topic"`
Message *string `json:"message,omitempty" yaml:"message,omitempty" hcl:"message"`
MessageFormat *string `json:"messageFormat,omitempty" yaml:"messageFormat,omitempty" hcl:"message_format"`
Username *string `json:"username,omitempty" yaml:"username,omitempty" hcl:"username"`
Password *Secret `json:"password,omitempty" yaml:"password,omitempty" hcl:"password"`
InsecureSkipVerify *bool `json:"insecureSkipVerify,omitempty" yaml:"insecureSkipVerify,omitempty" hcl:"insecure_skip_verify"`
}
type OnCallIntegration struct {
DisableResolveMessage *bool `json:"-" yaml:"-" hcl:"disable_resolve_message"`
@@ -299,6 +312,7 @@ type ContactPoint struct {
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"`
Mqtt []MqttIntegration `json:"mqtt" yaml:"mqtt" hcl:"mqtt,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"`