** 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 General Public License as published by
** the Free Software Foundation; either version 2 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 General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"zabbix.com/pkg/zbxcomms"
type MockServerOptions struct {
LogType string `conf:"default=console"`
LogFile string `conf:"optional"`
DebugLevel int `conf:"range=0:5,default=3"`
Port int `conf:"range=1:65535,default=10051"`
Timeout int `conf:"range=1:30,default=5"`
ActiveChecksFile string `conf:"optional"`
var options MockServerOptions
func handleConnection(c *zbxcomms.Connection) {
log.Warningf("Read failed: %s\n", err)
log.Debugf("got '%s'", string(js))
var pairs map[string]interface{}
if err := json.Unmarshal(js, &pairs); err != nil {
log.Warningf("Unmarshal failed: %s\n", err)
switch pairs["request"] {
activeChecks, err := ioutil.ReadFile(options.ActiveChecksFile)
err = c.Write(activeChecks)
log.Warningf("Write failed: %s\n", err)
err = c.WriteString("{\"response\":\"success\",\"info\":\"processed: 0; failed: 0; total: 0; seconds spent: 0.042523\"}")
log.Warningf("Write failed: %s\n", err)
log.Warningf("Unsupported request: %s\n", pairs["request"])
confDefault = "mock_server.conf"