Home > Article > Backend Development > Zabbix Agent 2 throws error when trying to process test plugins according to official instructions
php editor Yuzi will share with you a question about Zabbix Agent 2 today. One user encountered an error being thrown while trying to handle the test plugin according to the official instructions. This issue may affect the proper functioning of the plugin, so we will explore ways to resolve this issue. Let’s take a look!
I started exploring the possibilities of zabbix agent 2 and decided to create a test plugin step by step as described in the official plugin creation guide.
After I complete all the steps, the zabbix agent doesn't want to do anything (except the -h option) and gives the following error:
zabbix_agent2[10046]: Error: Unable to register plugin: Unable to parse agent version strconv.atoi: Parsing '6.0.13': Invalid syntax
I did this on ubuntu 22.04.
zabbix agent 2 version: 6.0.14.
go version: go1.18.1 linux/amd64
I only installed zabbix agent 2 through apt-get.
I did everything according to the instructions:
package main import ( "fmt" "io/ioutil" "net/http" "git.zabbix.com/ap/plugin-support/plugin/container" "git.zabbix.com/ap/plugin-support/plugin" ) // Plugin must define structure and embed plugin.Base structure. type Plugin struct { plugin.Base } // Create a new instance of the defined plugin structure var impl Plugin // Plugin must implement one or several plugin interfaces. func (p *Plugin) Export(key string, params []string, ctx plugin.ContextProvider) (result interface{}, err error) { // You may use one of Critf, Errf, Infof, Warningf, Debugf, Tracef functions for logging. p.Infof("received request to handle %s key with %d parameters", key, len(params)) // Fetch response from the specified URL, it should be just the IP address. resp, err := http.Get("https://api.ipify.org") if err != nil { // Plugin will return an error response if the request failed return nil, err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { // Plugin will return an error response if it failed to read the response return nil, err } return string(body), nil } func init() { // Register our metric, specifying the plugin and metric details. // 1 - a pointer to plugin implementation // 2 - plugin name // 3 - metric name (item key) // 4 - metric description // // NB! The metric description must end with a period, otherwise the Zabbix agent 2 will return an error and won't start! // Metric name (item key) and metric description can be repeated in a loop to register additional metrics. plugin.RegisterMetrics(&impl, "Myip", "myip", "Return the external IP address of the host where agent is running.") } // This is the main function, it is required to compile the plugin. // By default the function implements our packages to handle the plugin creation and execution. func main() { h, err := container.NewHandler(impl.Name()) if err != nil { panic(fmt.Sprintf("failed to create plugin handler %s", err.Error())) } impl.Logger = &h err = h.Execute() if err != nil { panic(fmt.Sprintf("failed to execute plugin handler %s", err.Error())) } }
/etc/zabbix/zabbix_agent2.d/plugins.d
zabbix_agent2 -t myip
And...it doesn't work and throws an error about wrong parsing proxy version.
I think strconv.atoi
is somehow handled incorrectly in the code of zabbix agent 2 itself, but after looking at the entire project using the code editor I can't find anything of note .
In addition, it is strange that the zabbix agent version is 6.0.14, and 6.0.13 is the plug-in communication protocol version. I don't understand why it's trying to pass off the protocol version as the proxy version.
So, if you have any thoughts on this issue, I invite you to express them. Thank you in advance.
I found the solution! (Well, my work colleague actually discovered this, but not the point)
The reason is the file src/go/plugins/external/broker.go
. The logic documented in the request structure was changed several times in this file. In summer '22 they changed the way the Zabbix Agent version attribute is parsed from string to integer via strconv.Atoi
.
But in January '23, they removed the proxy version attribute, parsed it via strconv.Atoi
, and added the protocol version attribute. That's why it tries to pass off the protocol version as the project version.
checkVersion method in the
plugin/container/handler.go file of the
Plugin Support
package has also been changed, which is used to check the protocol version.
So, the problem is with the new Zabbix Agent 2 and the old plugin support package.
If you are using version 6.4 for Zabbix Agent 2 and version 1.2.2 for git.zabbix.com/ap/plugin-support/plugin
then everything works fine!
The above is the detailed content of Zabbix Agent 2 throws error when trying to process test plugins according to official instructions. For more information, please follow other related articles on the PHP Chinese website!