192.168.29.130 是安裝zabbix主服務器php
192.168.29.129 是從服務器node
1)自動發現python
zabbix APIlinux
vim /etc/zabbix/zabbix_agentd.conf 在從服務器192.168.29.129 ipjson
ServerActive=192.168.29.129vim
Hostname=linux-node2.example.comapi
HostMetadataItem=system.uname服務器
zabbix_get -s 192.168.29.130 -k system.uname 在主服務器測試網絡
/etc/init.d/zabbix-agent restartsession
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"
]
}
}