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 在嘗試根據官方說明處理測試插件時拋出錯誤的詳細內容。更多資訊請關注PHP中文網其他相關文章!

C 更適合需要直接控制硬件資源和高性能優化的場景,而Golang更適合需要快速開發和高並發處理的場景。 1.C 的優勢在於其接近硬件的特性和高度的優化能力,適合遊戲開發等高性能需求。 2.Golang的優勢在於其簡潔的語法和天然的並發支持,適合高並發服務開發。

Golang在实际应用中表现出色,以简洁、高效和并发性著称。1)通过Goroutines和Channels实现并发编程,2)利用接口和多态编写灵活代码,3)使用net/http包简化网络编程,4)构建高效并发爬虫,5)通过工具和最佳实践进行调试和优化。

Go語言的核心特性包括垃圾回收、靜態鏈接和並發支持。 1.Go語言的並發模型通過goroutine和channel實現高效並發編程。 2.接口和多態性通過實現接口方法,使得不同類型可以統一處理。 3.基本用法展示了函數定義和調用的高效性。 4.高級用法中,切片提供了動態調整大小的強大功能。 5.常見錯誤如競態條件可以通過gotest-race檢測並解決。 6.性能優化通過sync.Pool重用對象,減少垃圾回收壓力。

Go語言在構建高效且可擴展的系統中表現出色,其優勢包括:1.高性能:編譯成機器碼,運行速度快;2.並發編程:通過goroutines和channels簡化多任務處理;3.簡潔性:語法簡潔,降低學習和維護成本;4.跨平台:支持跨平台編譯,方便部署。

關於SQL查詢結果排序的疑惑學習SQL的過程中,常常會遇到一些令人困惑的問題。最近,筆者在閱讀《MICK-SQL基礎�...

golang ...

Go語言中如何對比並處理三個結構體在Go語言編程中,有時需要對比兩個結構體的差異,並將這些差異應用到第�...


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Dreamweaver CS6
視覺化網頁開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

禪工作室 13.0.1
強大的PHP整合開發環境

WebStorm Mac版
好用的JavaScript開發工具