Alerting: Add TLS, QoS and retain options to the MQTT receiver (#92331)
This commit is contained in:
@@ -401,6 +401,12 @@ func (c contactPointsExtension) UpdateStructDescriptor(structDescriptor *jsonite
|
||||
desc.Decoder = codec
|
||||
desc.Encoder = codec
|
||||
}
|
||||
if structDescriptor.Type == reflect2.TypeOf(definitions.MqttIntegration{}) {
|
||||
codec := &numberAsStringCodec{ignoreError: true}
|
||||
desc := structDescriptor.GetField("QoS")
|
||||
desc.Decoder = codec
|
||||
desc.Encoder = codec
|
||||
}
|
||||
}
|
||||
|
||||
type emailAddressCodec struct{}
|
||||
|
||||
@@ -184,4 +184,30 @@ func TestContactPointFromContactPointExports(t *testing.T) {
|
||||
require.Nil(t, result.OnCall[1].MaxAlerts)
|
||||
require.Nil(t, result.OnCall[2].MaxAlerts)
|
||||
})
|
||||
|
||||
t.Run("mqtt with optional numbers as string", func(t *testing.T) {
|
||||
export := definitions.ContactPointExport{
|
||||
Name: "test",
|
||||
Receivers: []definitions.ReceiverExport{
|
||||
{
|
||||
Type: "mqtt",
|
||||
Settings: definitions.RawMessage(`{ "qos" : "112" }`),
|
||||
},
|
||||
{
|
||||
Type: "mqtt",
|
||||
Settings: definitions.RawMessage(`{ "qos" : "test" }`),
|
||||
},
|
||||
{
|
||||
Type: "mqtt",
|
||||
Settings: definitions.RawMessage(`{ "qos" : null }`),
|
||||
},
|
||||
},
|
||||
}
|
||||
result, err := ContactPointFromContactPointExport(export)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, result.Mqtt, 3)
|
||||
require.Equal(t, int64(112), *result.Mqtt[0].QoS)
|
||||
require.Nil(t, result.Mqtt[1].QoS)
|
||||
require.Nil(t, result.Mqtt[2].QoS)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -85,17 +85,26 @@ type LineIntegration struct {
|
||||
Description *string `json:"description,omitempty" yaml:"description,omitempty" hcl:"description"`
|
||||
}
|
||||
|
||||
type TLSConfig struct {
|
||||
InsecureSkipVerify *bool `json:"insecureSkipVerify,omitempty" yaml:"insecureSkipVerify,omitempty" hcl:"insecure_skip_verify"`
|
||||
TLSCACertificate *Secret `json:"caCertificate,omitempty" yaml:"caCertificate,omitempty" hcl:"ca_certificate"`
|
||||
TLSClientCertificate *Secret `json:"clientCertificate,omitempty" yaml:"clientCertificate,omitempty" hcl:"client_certificate"`
|
||||
TLSClientKey *Secret `json:"clientKey,omitempty" yaml:"clientKey,omitempty" hcl:"client_key"`
|
||||
}
|
||||
|
||||
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"`
|
||||
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"`
|
||||
QoS *int64 `json:"qos,omitempty" yaml:"qos,omitempty" hcl:"qos"`
|
||||
Retain *bool `json:"retain,omitempty" yaml:"retain,omitempty" hcl:"retain"`
|
||||
TLSConfig *TLSConfig `json:"tlsConfig,omitempty" yaml:"tlsConfig,omitempty" hcl:"tls_config,block"`
|
||||
}
|
||||
|
||||
type OnCallIntegration struct {
|
||||
|
||||
@@ -1325,12 +1325,75 @@ func GetAvailableNotifiers() []*NotifierPlugin {
|
||||
Secure: true,
|
||||
},
|
||||
{
|
||||
Label: "Disable certificate verification",
|
||||
Element: ElementTypeCheckbox,
|
||||
Description: "Do not verify the broker's certificate chain and host name.",
|
||||
PropertyName: "insecureSkipVerify",
|
||||
Label: "QoS",
|
||||
Element: ElementTypeSelect,
|
||||
SelectOptions: []SelectOption{
|
||||
{
|
||||
Value: "0",
|
||||
Label: "At most once (0)",
|
||||
},
|
||||
{
|
||||
Value: "1",
|
||||
Label: "At least once (1)",
|
||||
},
|
||||
{
|
||||
Value: "2",
|
||||
Label: "Exactly once (2)",
|
||||
},
|
||||
},
|
||||
Description: "The quality of service to use when sending the message.",
|
||||
PropertyName: "qos",
|
||||
Required: false,
|
||||
},
|
||||
{
|
||||
Label: "Retain",
|
||||
Description: "If set to true, the message will be retained by the broker.",
|
||||
Element: ElementTypeCheckbox,
|
||||
PropertyName: "retain",
|
||||
Required: false,
|
||||
},
|
||||
{
|
||||
Label: "TLS",
|
||||
PropertyName: "tlsConfig",
|
||||
Description: "TLS configuration options",
|
||||
Element: ElementTypeSubform,
|
||||
SubformOptions: []NotifierOption{
|
||||
{
|
||||
Label: "Disable certificate verification",
|
||||
Element: ElementTypeCheckbox,
|
||||
Description: "Do not verify the broker's certificate chain and host name.",
|
||||
PropertyName: "insecureSkipVerify",
|
||||
Required: false,
|
||||
},
|
||||
{
|
||||
Label: "CA Certificate",
|
||||
Element: ElementTypeTextArea,
|
||||
Description: "Certificate in PEM format to use when verifying the broker's certificate chain.",
|
||||
InputType: InputTypeText,
|
||||
PropertyName: "caCertificate",
|
||||
Required: false,
|
||||
Secure: true,
|
||||
},
|
||||
{
|
||||
Label: "Client Certificate",
|
||||
Element: ElementTypeTextArea,
|
||||
Description: "Client certificate in PEM format to use when connecting to the broker.",
|
||||
InputType: InputTypeText,
|
||||
PropertyName: "clientCertificate",
|
||||
Required: false,
|
||||
Secure: true,
|
||||
},
|
||||
{
|
||||
Label: "Client Key",
|
||||
Element: ElementTypeTextArea,
|
||||
Description: "Client key in PEM format to use when connecting to the broker.",
|
||||
InputType: InputTypeText,
|
||||
PropertyName: "clientKey",
|
||||
Required: false,
|
||||
Secure: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user