zabbix自定義item-監控UPS供電狀態


版本:Zabbix 4.0.4

監控目的:監控公司UPS供電設備狀態,及報警。

 

1、編寫自定義腳本,打印輸入電壓,輸出電壓,電池輸入電壓及溫度。放置於server端/Apps/script/get_ups_power.sh, 因為ups沒法作為客戶端上報數據,於是將server當作客戶端,通過串口服務器獲取數據后上傳到server端。

#!/bin/bash

#get power status of ups 
data=`(echo -e "Q1\n";sleep 1)|nc -u 192.168.255.21 1030 `
case "$1" in
        power_in)
                echo $data | awk -F" " '{print $1}'  | cut -f2 -d"("
        ;;
        power_out)
                echo $data | awk -F" " '{print $3}'
        ;;
        power_error)
                echo $data | awk -F" " '{print $2}'
        ;;
        tempature)
                echo $data | awk -F" " '{print $7}'
        ;;
        *)
                exit;
esac

2、zabbix_agent端配置。

vim /etc/zabbix/zabbix_agentd.conf
Server=zabbix服務端ip
ListenPort=10050 # 客戶端端口
ListenIP=客戶端ip
UnsafeUserParameters=1 # 設置為1 表示可使用特殊字符
UserParameter=check_UPS[*],/Apps/script/get_ups_power.sh $1  #check_UPS為自定義item,[*]表示有附加參數即$1等,如果沒有,去掉就行。

 

3、zabbix-server監控界面配置。

如果需要大批量添加host,最好建一個template,如果就一台,就在host上直接添加item就行。這里以template為例。

這里需要說明的就是key,之前在agent配置文件中已經定義item  check_UPS ,輸入參數為power_in 等(見腳本),添加完成后link到host就行,這邊不再贅述。

 

 

  

 4、故障的排查與處理思路。

a、監控圖斷斷續續。

圖沒有了,現象就是數據點斷斷續續,有時能去到數據,有時沒有,且無規律。監控界面沒有提示任何報錯,但查看/var/log/zabbix/zabbix_server.log,會發現如下報錯:

6491:20211217:160318.627 error reason for "10.25.25.5:check_UPS[power_in]" changed: Value "227.5" of type "string" is not suitable for value type "Numeric (unsigned)"
6492:20211217:160320.635 item "10.25.25.5:check_UPS[tempature]" became supported
6492:20211217:160347.880 error reason for "10.25.25.5:check_UPS[power_in]" changed: Value "227.1" of type "string" is not suitable for value type "Numeric (unsigned)"
6492:20211217:160418.057 error reason for "10.25.25.5:check_UPS[power_in]" changed: Value "227.3" of type "string" is not suitable for value type "Numeric (unsigned)"
6488:20211217:160419.059 item "10.25.25.5:check_UPS[power_out]" became not supported: Value "" of type "string" is not suitable for value type "Numeric (float)"
6488:20211217:160448.226 item "10.25.25.5:check_UPS[power_in]" became supported
6487:20211217:160449.228 item "10.25.25.5:check_UPS[power_out]" became supported 

報錯的大概意思就是上傳的數據類型為字符串,而配置的數據類型為數字(無正負),將類型改為浮點數即可。 如下:

 

 

附:官網關於字符類型的說明

https://www.zabbix.com/documentation/4.0/zh/manual/config/items/item

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM