2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-04-12 16:55:22 -04:00
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
package notify
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/config"
|
|
|
|
"github.com/minio/minio/internal/event/target"
|
2019-10-23 01:59:13 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetNotifyKafka - helper for config migration from older config.
|
2021-05-25 17:17:33 -04:00
|
|
|
func SetNotifyKafka(s config.Config, name string, cfg target.KafkaArgs) error {
|
2019-11-13 20:38:05 -05:00
|
|
|
if !cfg.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
if err := cfg.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-05-25 17:17:33 -04:00
|
|
|
s[config.NotifyKafkaSubSys][name] = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOn,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaBrokers,
|
|
|
|
Value: func() string {
|
|
|
|
var brokers []string
|
|
|
|
for _, broker := range cfg.Brokers {
|
|
|
|
brokers = append(brokers, broker.String())
|
|
|
|
}
|
|
|
|
return strings.Join(brokers, config.ValueSeparator)
|
|
|
|
}(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaTopic,
|
|
|
|
Value: cfg.Topic,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaQueueDir,
|
|
|
|
Value: cfg.QueueDir,
|
|
|
|
},
|
2019-12-05 18:31:46 -05:00
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaClientTLSCert,
|
|
|
|
Value: cfg.TLS.ClientTLSCert,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaClientTLSKey,
|
|
|
|
Value: cfg.TLS.ClientTLSKey,
|
|
|
|
},
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaQueueLimit,
|
|
|
|
Value: strconv.Itoa(int(cfg.QueueLimit)),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaTLS,
|
|
|
|
Value: config.FormatBool(cfg.TLS.Enable),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaTLSSkipVerify,
|
|
|
|
Value: config.FormatBool(cfg.TLS.SkipVerify),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaTLSClientAuth,
|
|
|
|
Value: strconv.Itoa(int(cfg.TLS.ClientAuth)),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaSASL,
|
|
|
|
Value: config.FormatBool(cfg.SASL.Enable),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaSASLUsername,
|
|
|
|
Value: cfg.SASL.User,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.KafkaSASLPassword,
|
|
|
|
Value: cfg.SASL.Password,
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNotifyAMQP - helper for config migration from older config.
|
|
|
|
func SetNotifyAMQP(s config.Config, amqpName string, cfg target.AMQPArgs) error {
|
2019-11-13 20:38:05 -05:00
|
|
|
if !cfg.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
if err := cfg.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s[config.NotifyAMQPSubSys][amqpName] = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOn,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpURL,
|
|
|
|
Value: cfg.URL.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpExchange,
|
|
|
|
Value: cfg.Exchange,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpRoutingKey,
|
|
|
|
Value: cfg.RoutingKey,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpExchangeType,
|
|
|
|
Value: cfg.ExchangeType,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpDeliveryMode,
|
|
|
|
Value: strconv.Itoa(int(cfg.DeliveryMode)),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpMandatory,
|
|
|
|
Value: config.FormatBool(cfg.Mandatory),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpInternal,
|
|
|
|
Value: config.FormatBool(cfg.Immediate),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpDurable,
|
|
|
|
Value: config.FormatBool(cfg.Durable),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpNoWait,
|
|
|
|
Value: config.FormatBool(cfg.NoWait),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpAutoDeleted,
|
|
|
|
Value: config.FormatBool(cfg.AutoDeleted),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpQueueDir,
|
|
|
|
Value: cfg.QueueDir,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.AmqpQueueLimit,
|
|
|
|
Value: strconv.Itoa(int(cfg.QueueLimit)),
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNotifyES - helper for config migration from older config.
|
|
|
|
func SetNotifyES(s config.Config, esName string, cfg target.ElasticsearchArgs) error {
|
2019-11-13 20:38:05 -05:00
|
|
|
if !cfg.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
if err := cfg.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s[config.NotifyESSubSys][esName] = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOn,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.ElasticFormat,
|
|
|
|
Value: cfg.Format,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.ElasticURL,
|
|
|
|
Value: cfg.URL.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.ElasticIndex,
|
|
|
|
Value: cfg.Index,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.ElasticQueueDir,
|
|
|
|
Value: cfg.QueueDir,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.ElasticQueueLimit,
|
|
|
|
Value: strconv.Itoa(int(cfg.QueueLimit)),
|
|
|
|
},
|
2020-08-23 12:43:48 -04:00
|
|
|
config.KV{
|
|
|
|
Key: target.ElasticUsername,
|
|
|
|
Value: cfg.Username,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.ElasticPassword,
|
|
|
|
Value: cfg.Password,
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNotifyRedis - helper for config migration from older config.
|
|
|
|
func SetNotifyRedis(s config.Config, redisName string, cfg target.RedisArgs) error {
|
2019-11-13 20:38:05 -05:00
|
|
|
if !cfg.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
if err := cfg.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s[config.NotifyRedisSubSys][redisName] = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOn,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.RedisFormat,
|
|
|
|
Value: cfg.Format,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.RedisAddress,
|
|
|
|
Value: cfg.Addr.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.RedisPassword,
|
|
|
|
Value: cfg.Password,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.RedisKey,
|
|
|
|
Value: cfg.Key,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.RedisQueueDir,
|
|
|
|
Value: cfg.QueueDir,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.RedisQueueLimit,
|
|
|
|
Value: strconv.Itoa(int(cfg.QueueLimit)),
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNotifyWebhook - helper for config migration from older config.
|
|
|
|
func SetNotifyWebhook(s config.Config, whName string, cfg target.WebhookArgs) error {
|
2019-11-13 20:38:05 -05:00
|
|
|
if !cfg.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
if err := cfg.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s[config.NotifyWebhookSubSys][whName] = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOn,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.WebhookEndpoint,
|
|
|
|
Value: cfg.Endpoint.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.WebhookAuthToken,
|
|
|
|
Value: cfg.AuthToken,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.WebhookQueueDir,
|
|
|
|
Value: cfg.QueueDir,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.WebhookQueueLimit,
|
|
|
|
Value: strconv.Itoa(int(cfg.QueueLimit)),
|
|
|
|
},
|
2020-06-08 08:55:44 -04:00
|
|
|
config.KV{
|
|
|
|
Key: target.WebhookClientCert,
|
|
|
|
Value: cfg.ClientCert,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.WebhookClientKey,
|
|
|
|
Value: cfg.ClientKey,
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNotifyPostgres - helper for config migration from older config.
|
|
|
|
func SetNotifyPostgres(s config.Config, psqName string, cfg target.PostgreSQLArgs) error {
|
2019-11-13 20:38:05 -05:00
|
|
|
if !cfg.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
if err := cfg.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s[config.NotifyPostgresSubSys][psqName] = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOn,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresFormat,
|
|
|
|
Value: cfg.Format,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresConnectionString,
|
|
|
|
Value: cfg.ConnectionString,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresTable,
|
|
|
|
Value: cfg.Table,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresHost,
|
|
|
|
Value: cfg.Host.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresPort,
|
|
|
|
Value: cfg.Port,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresUsername,
|
2020-08-03 12:16:00 -04:00
|
|
|
Value: cfg.Username,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresPassword,
|
|
|
|
Value: cfg.Password,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresDatabase,
|
|
|
|
Value: cfg.Database,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresQueueDir,
|
|
|
|
Value: cfg.QueueDir,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresQueueLimit,
|
|
|
|
Value: strconv.Itoa(int(cfg.QueueLimit)),
|
|
|
|
},
|
2020-09-25 01:20:30 -04:00
|
|
|
config.KV{
|
|
|
|
Key: target.PostgresMaxOpenConnections,
|
|
|
|
Value: strconv.Itoa(cfg.MaxOpenConnections),
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNotifyNSQ - helper for config migration from older config.
|
|
|
|
func SetNotifyNSQ(s config.Config, nsqName string, cfg target.NSQArgs) error {
|
2019-11-13 20:38:05 -05:00
|
|
|
if !cfg.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
if err := cfg.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s[config.NotifyNSQSubSys][nsqName] = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOn,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NSQAddress,
|
|
|
|
Value: cfg.NSQDAddress.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NSQTopic,
|
|
|
|
Value: cfg.Topic,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NSQTLS,
|
|
|
|
Value: config.FormatBool(cfg.TLS.Enable),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NSQTLSSkipVerify,
|
|
|
|
Value: config.FormatBool(cfg.TLS.SkipVerify),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NSQQueueDir,
|
|
|
|
Value: cfg.QueueDir,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NSQQueueLimit,
|
|
|
|
Value: strconv.Itoa(int(cfg.QueueLimit)),
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNotifyNATS - helper for config migration from older config.
|
|
|
|
func SetNotifyNATS(s config.Config, natsName string, cfg target.NATSArgs) error {
|
2019-11-13 20:38:05 -05:00
|
|
|
if !cfg.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
if err := cfg.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s[config.NotifyNATSSubSys][natsName] = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOn,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSAddress,
|
|
|
|
Value: cfg.Address.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSSubject,
|
|
|
|
Value: cfg.Subject,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSUsername,
|
|
|
|
Value: cfg.Username,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSPassword,
|
|
|
|
Value: cfg.Password,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSToken,
|
|
|
|
Value: cfg.Token,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSCertAuthority,
|
|
|
|
Value: cfg.CertAuthority,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSClientCert,
|
|
|
|
Value: cfg.ClientCert,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSClientKey,
|
|
|
|
Value: cfg.ClientKey,
|
|
|
|
},
|
|
|
|
config.KV{
|
2019-12-06 16:53:51 -05:00
|
|
|
Key: target.NATSTLS,
|
|
|
|
Value: config.FormatBool(cfg.Secure),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSTLSSkipVerify,
|
2019-11-20 18:10:24 -05:00
|
|
|
Value: config.FormatBool(cfg.Secure),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSPingInterval,
|
|
|
|
Value: strconv.FormatInt(cfg.PingInterval, 10),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSQueueDir,
|
|
|
|
Value: cfg.QueueDir,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSQueueLimit,
|
|
|
|
Value: strconv.Itoa(int(cfg.QueueLimit)),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSStreaming,
|
|
|
|
Value: func() string {
|
|
|
|
if cfg.Streaming.Enable {
|
2019-12-04 18:32:37 -05:00
|
|
|
return config.EnableOn
|
2019-11-20 18:10:24 -05:00
|
|
|
}
|
2019-12-04 18:32:37 -05:00
|
|
|
return config.EnableOff
|
2019-11-20 18:10:24 -05:00
|
|
|
}(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSStreamingClusterID,
|
|
|
|
Value: cfg.Streaming.ClusterID,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSStreamingAsync,
|
|
|
|
Value: config.FormatBool(cfg.Streaming.Async),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.NATSStreamingMaxPubAcksInFlight,
|
|
|
|
Value: strconv.Itoa(cfg.Streaming.MaxPubAcksInflight),
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNotifyMySQL - helper for config migration from older config.
|
|
|
|
func SetNotifyMySQL(s config.Config, sqlName string, cfg target.MySQLArgs) error {
|
2019-11-13 20:38:05 -05:00
|
|
|
if !cfg.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
if err := cfg.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s[config.NotifyMySQLSubSys][sqlName] = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOn,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLFormat,
|
|
|
|
Value: cfg.Format,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLDSNString,
|
|
|
|
Value: cfg.DSN,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLTable,
|
|
|
|
Value: cfg.Table,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLHost,
|
|
|
|
Value: cfg.Host.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLPort,
|
|
|
|
Value: cfg.Port,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLUsername,
|
|
|
|
Value: cfg.User,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLPassword,
|
|
|
|
Value: cfg.Password,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLDatabase,
|
|
|
|
Value: cfg.Database,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLQueueDir,
|
|
|
|
Value: cfg.QueueDir,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLQueueLimit,
|
|
|
|
Value: strconv.Itoa(int(cfg.QueueLimit)),
|
|
|
|
},
|
2020-09-25 01:20:30 -04:00
|
|
|
config.KV{
|
|
|
|
Key: target.MySQLMaxOpenConnections,
|
|
|
|
Value: strconv.Itoa(cfg.MaxOpenConnections),
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNotifyMQTT - helper for config migration from older config.
|
|
|
|
func SetNotifyMQTT(s config.Config, mqttName string, cfg target.MQTTArgs) error {
|
2019-11-13 20:38:05 -05:00
|
|
|
if !cfg.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
if err := cfg.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s[config.NotifyMQTTSubSys][mqttName] = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOn,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MqttBroker,
|
|
|
|
Value: cfg.Broker.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MqttTopic,
|
|
|
|
Value: cfg.Topic,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MqttQoS,
|
|
|
|
Value: fmt.Sprintf("%d", cfg.QoS),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MqttUsername,
|
|
|
|
Value: cfg.User,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MqttPassword,
|
|
|
|
Value: cfg.Password,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MqttReconnectInterval,
|
|
|
|
Value: cfg.MaxReconnectInterval.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MqttKeepAliveInterval,
|
|
|
|
Value: cfg.KeepAlive.String(),
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MqttQueueDir,
|
|
|
|
Value: cfg.QueueDir,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: target.MqttQueueLimit,
|
|
|
|
Value: strconv.Itoa(int(cfg.QueueLimit)),
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|