php小编柚子今天要和大家分享关于Zabbix Agent 2的一则问题。在尝试根据官方说明处理测试插件时,一位用户遇到了错误的抛出问题。这个问题可能会影响插件的正常运行,因此我们将会探讨解决这个问题的方法。让我们一起来看看吧!
问题内容
我开始探索 zabbix agent 2 的可能性,并决定按照官方插件创建指南中的描述逐步创建一个测试插件。
在我完成所有步骤之后,zabbix agent 不想执行任何操作(除了 -h 选项)并给出以下错误:
zabbix_agent2 [10046]:错误:无法注册插件:无法解析代理版本strconv.atoi:解析“6.0.13”:语法无效
我在 ubuntu 22.04 上完成了这一切。
zabbix agent 2 版本:6.0.14。
go版本:go1.18.1 linux/amd64
我只通过 apt-get 安装了 zabbix agent 2。
我按照说明做了一切:
创建了目录 /home/ubuntu/myip创建了一个文件 main.go粘贴了指令中的代码
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())) } }
登录后复制go mod init example.test/myip整理模组开始构建我使用插件可执行文件的路径创建了文件 myip.conf 并将其放入目录 /etc/zabbix/zabbix_agent2.d/plugins.d并启动命令 zabbix_agent2 -t myip
并且……它不起作用并抛出有关错误解析代理版本的错误。
我认为 strconv.atoi 在 zabbix agent 2 本身的代码中以某种方式处理不正确,但是在使用代码编辑器查看整个项目后,我找不到任何值得注意的东西。
另外,奇怪的是zabbix agent版本是6.0.14,6.0.13是插件通信协议版本。我不明白为什么它试图将协议版本冒充代理版本。
所以,如果你对这个问题有什么想法,我请你表达出来。预先感谢您。
解决方法
我找到了解决办法! (嗯,实际上我的工作同事发现了这一点,但不是重点)
原因是文件 src/go/plugins/external/broker.go。在此文件中多次更改了请求结构中记录的逻辑。在 22 年夏天,他们改变了 Zabbix Agent 版本属性的方式(通过 strconv.Atoi 从字符串解析为整数)。
但在 23 年 1 月,他们删除了代理版本的属性,通过 strconv.Atoi 进行解析,并添加了协议版本的属性。这就是为什么它试图将协议版本冒充为项目版本。
Plugin Support包的plugin/container/handler.go文件中的checkVersion方法也已更改,用于检查协议版本。
所以,问题出在新的 Zabbix Agent 2 和旧的插件支持包上。
如果您对 Zabbix Agent 2 使用版本 6.4,对 git.zabbix.com/ap/plugin-support/plugin 使用版本 1.2.2,则一切正常!
以上就是Zabbix Agent 2 在尝试根据官方说明处理测试插件时抛出错误的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2483882.html