1、agent自动注册
2、sever端自动发现discovery
3、zabbix api
agent自动注册
主动模式自动注册配置
主动模式配置items监控类型要改成zabbix agent active
vim /etc/zabbix/zabbix_agentd.conf
1
2
3
4
5
6
7
8
|
#注释Server #Server=192.168.217.20 #StartAgents=0表示关闭被动模式 StartAgents = 0 ServerActive = 192.168 . 217.20 #主机名唯一 Hostname = compute HostMetadataItem = system.uname |
被动模式配置
1
2
3
4
5
6
7
8
|
vim / etc / zabbix / zabbix_agentd.conf 注释Server Server = 192.168 . 217.20 StartAgents = 3 #ServerActive=192.168.217.20 #主机名唯一 Hostname = compute #HostMetadataItem=system.uname |
在服务端的web界面配置自动注册事件
configuration--->Actions--->选择事件源Auto registration---->create action
--->选择action-->填写相关信息-->选择operation-->填写相关信息-->enable-->add
保存关闭重启agent
1
|
service zabbix - agent restart |
sever端自动发现discovery
被动模式配置
1
2
3
4
5
6
7
8
|
vim / etc / zabbix / zabbix_agentd.conf 注释Server Server = 192.168 . 217.20 StartAgents = 3 #ServerActive=192.168.217.20 #主机名唯一 Hostname = compute #HostMetadataItem=system.uname |
配置discovery rule
configuration--->discovery--->create discovery rule---->填写相关信息(主要是checks条件)-->add
配置与discovery的Actions
configuration--->Actions--->选择事件源discovery---->create action-->填写相关信息(主要是Conditions条件)-->选择operation-->填写相关信息(主要是operation条件)-->enable-->add
zabbix api
1、验证
2、请求API,附带上session id
3、host.create
获取登录的session id
1
2
3
4
5
6
7
8
9
10
|
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 . 217.20 / zabbix / api_jsonrpc.php | python - mjson.tool |
输出结果:
1
2
3
4
5
|
{ "id" : 1 , "jsonrpc" : "2.0" , "result" : "40b0c714a09b3eb70c32c596ba2e8514" } |
添加主机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
curl - s - X POST - H 'Content-Type:application/json ' - d ' { "jsonrpc" : "2.0" , "method" : "host.create" , "params" : { "host" : "compute" , "interfaces" : [ { "type" : 1 , "main" : 1 , "useip" : 1 , "ip" : "192.168.217.20" , "dns" : "", "port" : "10050" } ], "groups" : [ { "groupid" : "4" } ], "templates" : [ { "templateid" : "10001" } ] }, "auth" : "40b0c714a09b3eb70c32c596ba2e8514" , "id" : 1 }' http: / / 192.168 . 217.20 / zabbix / api_jsonrpc.php | python - mjson.tool |