/*
** 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/>.
**/
package main
import (
"errors"
"flag"
"fmt"
"io"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"
"golang.zabbix.com/agent2/internal/agent"
"golang.zabbix.com/agent2/internal/agent/keyaccess"
"golang.zabbix.com/agent2/internal/agent/resultcache"
"golang.zabbix.com/agent2/internal/agent/runtimecontrol"
"golang.zabbix.com/agent2/internal/agent/scheduler"
"golang.zabbix.com/agent2/internal/agent/serverconnector"
"golang.zabbix.com/agent2/internal/agent/serverlistener"
"golang.zabbix.com/agent2/internal/agent/statuslistener"
"golang.zabbix.com/agent2/internal/monitor"
"golang.zabbix.com/agent2/pkg/pidfile"
"golang.zabbix.com/agent2/pkg/tls"
"golang.zabbix.com/agent2/pkg/version"
"golang.zabbix.com/agent2/pkg/zbxlib"
_ "golang.zabbix.com/agent2/plugins"
"golang.zabbix.com/sdk/conf"
"golang.zabbix.com/sdk/errs"
"golang.zabbix.com/sdk/log"
"golang.zabbix.com/sdk/plugin/comms"
"golang.zabbix.com/sdk/zbxerr"
"golang.zabbix.com/sdk/zbxflag"
)
const runtimeCommandSendingTimeout = time.Second
const usageMessageFormatRuntimeControlFormat = //
`Perform administrative functions (%s timeout)
Remote control interface, available commands:
log_level_increase Increase log level
log_level_decrease Decrease log level
userparameter_reload Reload user parameters
metrics List available metrics
version Display Agent version
`
const usageMessageFormat = //
`Usage of Zabbix agent 2:
%[1]s [-c config-file]
%[1]s [-c config-file] [-v] -p
%[1]s [-c config-file] [-v] -t item-key
%[1]s [-c config-file] -T
%[1]s [-c config-file] -R runtime-option
%[1]s -h
%[1]s -V
`
const helpMessageFormat = //
`A Zabbix daemon for monitoring of various server parameters.
Options:
%[1]s
Example: zabbix_agent2 -c %[2]s
Report bugs to: <https://support.zabbix.com>
Zabbix home page: <https://www.zabbix.com>
Documentation: <https://www.zabbix.com/documentation>
`
// variables set at build
var (
confDefault string
applicationName string