监控项配置在ZabbixServer
1、 修改Zabbix-agent开启自定义脚本,
vi /etc/zabbix/zabbix_agentd.conf
# 被动模式,修改server IP
Server=127.0.0.1
# 主动模式,配置上传数据IP
ServerActive=127.0.0.1
# 配置主机名
Hostname=zabbix-server
# 增加配置
UnsafeUserParameters=1
# 默认新增监控项配置
Include=/etc/zabbix/zabbix_agentd.d/*.conf
# 因为脚本要用到root权限来启动 zabbix_agent需要成root用户启动,默认启动用户是zabbix
AllowRoot=1
# 添加监控项文件
vi /etc/zabbix/zabbix_agentd.d/agentd-key.conf
UserParameter=luancheng-dtgk-online,python3 /usr/local/script/dome.py
2、?编写自定义的监控脚本
import requests
import json
try:
rest = 1
url_login = "url1"
url_get_enter = "url2"
data = '{ "username": "admin", "password": "password" }'
headers = {
'User-Agent': 'Apipost client Runtime/+https://www.apipost.cn/',
'Content-Type': 'application/json',
}
response = requests.post(url=url_login, headers=headers, data=data)
token = json.loads(response.text)['data']['token']
headers_enter = {
'User-Agent': 'Apipost client Runtime/+https://www.apipost.cn/',
'token': token
}
info_response = requests.get(url=url_get_enter, headers=headers_enter)
enter_info = json.loads(info_response.text)['data']
for info in enter_info:
if info.get("total") == 0:
rest = 0
break
except:
rest = 0
print(rest)
3 、zabbix WEB配置监控项
配置-> 主机- > zabbix-server->监控项->创建监控项
4 、配置触发器
?配置-> 主机- > zabbix-server->触发器->配置触发器
|