Zabbix Agent 2 在嘗試根據官方說明處理測試插件時拋出錯誤
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中文網其他相關文章!

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

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

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

我有一個jwt令牌,我可以在https://jwt.io/網站上看到解碼後的令牌。它不需要我設定任何秘密或聲明。所以我正在尋找一種方法來解碼令牌以獲得過期日期而不提供任何秘密。我正在使用庫ngopkg.in/square/go-jose.v2/jwt,下面是我的程式碼:token,err:=jwt.ParseSigned(jwtToken)返回值token有一個標頭字段,其中包括keyid、演算法,但它沒有給我過期日期。我搜尋過這個主題,人們說使用github.com/a

parse 函數解析字串,將其轉換為由分隔符號分隔的令牌清單。步驟:1. 從字串開頭搜尋第一個非分隔符字元;2. 繼續搜尋直到遇到分隔符,並在該分隔符處終止字串;3. 將令牌儲存在令牌數組中;4 . 重複1-3 步,直到字串結束;5. 在陣列結尾加上指向NULL 的指針,表示陣列結束。

我有一個用例,我們在x-www-form-urlencoded主體中取得嵌套鍵值,如下所示name=abc&age=12¬es[key1]=value1¬es[key2]=value2我嘗試了url.parsequery("name= abc&age=12¬es\[key1\]=value1¬es\[key2\]=value2")但它給了{"name":"abc","age":12,"notes[key1]":"value1", "note

在 C++ 中,有兩種將 string 轉換為 int 的方法:使用 sto i() 函數,直接接收字串並傳回整數。使用 istringstream 類,將字串解析為輸入流,然後提取整數。選擇方法取決於字串格式:如果格式明確且無非數字字符,stoi() 更簡潔;如果字串可能包含非數字字元或需要自訂轉換,則 istringstream 更靈活。

Java中的parse指將字串或其他表示轉換為指定類型或物件的處理過程。常見的應用包括將字串轉換為數字類型、日期/時間物件、JSON物件以及從XML文件中提取資料。透過內建方法、格式化器類別或第三方函式庫進行parse。

Go語言中解析位址的關鍵函數包括:net.ParseIP():解析IPv4或IPv6位址。 net.ParseCIDR():解析CIDR標記。 net.ResolveIPAddr():解析主機名稱或IP位址為IP位址。 net.ResolveTCPAddr():解析主機名稱和連接埠為TCP位址。 net.ResolveUDPAddr():解析主機名稱和連接埠為UDP位址。

Go語言反射允許在運行時操控變數值,包括修改布林值、整數、浮點數和字串。透過取得變數的Value,可以呼叫SetBool、SetInt、SetFloat和SetString方法來進行修改。例如,可以解析JSON字串為結構體,然後使用反射修改結構體欄位的值。需要注意,反射操作較慢,且無法修改不可修改字段,修改結構體字段值時可能不會自動更新相關字段。

深入了解PHP:JSONUnicode轉中文的實作方法在開發中,我們經常會遇到需要處理JSON資料的情況,而JSON中的Unicode編碼在一些場景下會為我們帶來一些問題,特別是當需要將Unicode編碼轉換為中文字元時。在PHP中,有一些方法可以幫助我們實現這個轉換過程,以下將介紹常用的方法,並提供具體的程式碼範例。首先,讓我們先來了解一下JSON中Un
