1397535668 发表于 2019-1-24 14:19:06

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-agentrestart
  

  

https://s4.运维网.com/wyfs02/M00/96/4E/wKioL1kfNb2xVTWwAAECF_TKsO0634.png-wh_500x0-wm_3-wmp_4-s_1263013424.png
https://s2.运维网.com/wyfs02/M01/96/4E/wKioL1kfNfKy-2WtAAEHWpi1w4I574.png-wh_500x0-wm_3-wmp_4-s_3870207626.png
https://s2.运维网.com/wyfs02/M01/96/4D/wKiom1kfNhuTTh_KAADzulm39oY637.png-wh_500x0-wm_3-wmp_4-s_4116108618.png
https://s3.运维网.com/wyfs02/M01/96/4E/wKioL1kfNkShzZBiAADzXxtuAgE300.png-wh_500x0-wm_3-wmp_4-s_1564832604.png
  

2)网络发现
关闭自动注册
vim /etc/zabbix/zabbix_agentd.conf在从服务器
Server=192.168.29.130
StartAgents=3
ServerActive=127.0.0.1
grep '^' /etc/zabbix/zabbix_agentd.conf
/etc/init.d/zabbix-agentrestart


http://192.168.29.130/zabbix/hosts.php?ddreset=1&sid=9d7240bdae42f8f3
在网页中执行相关操作
  

https://s4.运维网.com/wyfs02/M02/96/4D/wKiom1kfNqzhvtsHAADwHaDNjUY958.png-wh_500x0-wm_3-wmp_4-s_1649946869.png
  

  

  

  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"
  ]
  }
  }
  




页: [1]
查看完整版本: zabbix 自动监控