zabbix 自动监控
192.168.29.130 是安装zabbix主服务器
192.168.29.129 是从服务器
1)自动发现
zabbix API
vim /etc/zabbix/zabbix_agentd.conf 在从服务器192.168.29.129 ip
ServerActive=192.168.29.129
Hostname=linux-node2.example.com
HostMetadataItem=system.uname
zabbix_get -s 192.168.29.130 -k system.uname 在主服务器测试
/etc/init.d/zabbix-agent restart
2)网络发现
关闭自动注册
vim /etc/zabbix/zabbix_agentd.conf 在从服务器
Server=192.168.29.130
StartAgents=3
ServerActive=127.0.0.1
grep '^[a-Z]' /etc/zabbix/zabbix_agentd.conf
/etc/init.d/zabbix-agent restart
http://192.168.29.130/zabbix/hosts.php?ddreset=1&sid=9d7240bdae42f8f3
在网页中执行相关操作
3)API方式 关闭自动注册 自动发现 删除自动发现的机器
1.验证
https://www.zabbix.com/documentation/2.4/manual/api/reference/user/login
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "zabbix"
},
"id": 1
}' http://192.168.29.130/zabbix/api_jsonrpc.php |python -mjson.tool
返回数据
{
"id": 1,
"jsonrpc": "2.0",
"result": "72e104119c242914115b5221e5bf1672"
}
https://www.zabbix.com/documentation/2.4/manual/api/reference/host/get
2.请求api ,附带上sessionid
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid"],
"selectGroups": "extend",
"filter": {
"host": [
"Zabbix server"
]
}
},
"auth": "72e104119c242914115b5221e5bf1672",
"id": 2
}' http://192.168.29.130/zabbix/api_jsonrpc.php |python -mjson.tool
https://www.zabbix.com/documentation/2.4/manual/api/reference/host/create
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "Linux server",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "192.168.29.129",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2"
}
],
"templates": [
{
"templateid": "10001"
}
],
"inventory_mode": 0,
"inventory": {
"macaddress_a": "01234",
"macaddress_b": "56768"
}
},
"auth": "72e104119c242914115b5221e5bf1672",
"id": 5
}' http://192.168.29.130/zabbix/api_jsonrpc.php |python -mjson.tool
成功返回数据
{
"id": 5,
"jsonrpc": "2.0",
"result": {
"hostids": [
"10114"
]
}
}