公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

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,则一切正常!

分享到:
标签:字符串解析
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定