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

 

posted @ 2021-12-17 16:40  运维军火库  阅读(1361)  评论(0编辑  收藏  举报