1. 编写获取最新心跳时间戳脚本

root@zabbix-server-op:/etc/zabbix/scripts# cat proxy_check_new.py 
import requests
import json
import sys
def get_proxy(url):
    opname=sys.argv[1]
    headers={
        "Content-Type":"application/json"
    }
    body=json.dumps({
        "jsonrpc": "2.0",
        "method": "proxy.get",
        "params": {
        "output": "extend",
        "selectInterface": "extend"
        },
        "auth": "ed66dfbfe7e7a990e0a8b69b6c5ae93c",
        "id": 1
    })
    req=requests.post( url=url,headers=headers,data=body)
    proxy_time={}
    for l_dict in req.json()["result"]:
        #print(l_dict["host"],l_dict["lastaccess"])
        proxy_time[l_dict["host"]]=l_dict["lastaccess"]

   # return  proxy_time
    print(proxy_time[opname])

if __name__ == '__main__':
    url="http://zabbixserverip/zabbix/api_jsonrpc.php"
    get_proxy(url)
    #proxy_time=get_proxy(url)
    #print(str(proxy_time).replace("\'","\""))

2.添加userparameter

root@zabbix-server-op:/etc/zabbix/zabbix_agentd.d# cat proxy_check_new.conf 
UserParameter=proxy_check_new[*],python3 /etc/zabbix/scripts/proxy_check_new.py $1

注:zabbix_agentd.conf 有配置Include=/etc/zabbix/zabbix_agentd.d/*.conf

3.重启zabbix-agent,zabbix_get测试

root@zabbix-server-op:/etc/zabbix/zabbix_agentd.d# zabbix_get -s 127.0.0.1 -p 10050 -k "proxy_check_new[****-p-proxy]"
1651071273

 

4.创建模板

 

 5.创建监控项

 

 6.创建触发器