impl.Tracef("received publish from [%s] on topic '%s' got: %s", ms.broker.url, msg.Topic(), string(msg.Payload()))
** Copyright (C) 2001-2025 Zabbix SIA
** 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, version 3.
** 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 <https://www.gnu.org/licenses/>.
** We use the library Eclipse Paho (eclipse/paho.mqtt.golang), which is
** distributed under the terms of the Eclipse Distribution License 1.0 (The 3-Clause BSD License)
** available at https://www.eclipse.org/org/documents/edl-v10.php
mqtt "github.com/eclipse/paho.mqtt.golang"
"golang.zabbix.com/agent2/pkg/itemutil"
"golang.zabbix.com/agent2/pkg/watch"
"golang.zabbix.com/sdk/metric"
"golang.zabbix.com/sdk/plugin"
"golang.zabbix.com/sdk/tlsconfig"
"golang.zabbix.com/sdk/zbxerr"
mqttClients map[broker]*mqttClient
func (p *Plugin) createOptions(
clientid, username, password string, b broker, details tlsconfig.Details) (*mqtt.ClientOptions, error) {
opts := mqtt.NewClientOptions().AddBroker(b.url).SetClientID(clientid).SetCleanSession(true).SetConnectTimeout(
time.Duration(impl.options.Timeout) * time.Second)
opts.SetUsername(username)
opts.SetPassword(password)
opts.OnConnectionLost = func(client mqtt.Client, reason error) {
impl.Warningf("connection lost to [%s]: %s", b.url, reason.Error())
opts.OnConnect = func(client mqtt.Client) {
impl.Debugf("connected to [%s]", b.url)