- - 时间:2020年11月10日

- - 作者:飞翔的小胖猪

前言:

使用zabbix作为基础环境的监控系统时,面对现网在用的2000+台把这些主机添加到zabbix监控中是一个问题,当然zabbix有自动发现的规则,但是应客户要求需要为每个资源填写特定的资产标签,在zabbix的管理页面上暂时没有发现可行的办法。文章使用python程序调用zabbix自带的API实现批量的主机资源添加,包括对应的资产项。(添加主机资源时不填入资产的标签方法,建议使用zabbix自带的服务发现)

文档最终实现的功能是用户把需要添加到zabbix的资源填入execl的对应列中,然后执行python程序实现批量添加host的目的。

环境说明

zabbix服务端安装在Centos 7.6操作系统上,版本为4.4。

Zabbix使用python批量添加主机及主机资产信息-从零到无

 

python使用的是3.9的版本,安装在win上。

Zabbix使用python批量添加主机及主机资产信息-从零到无

 

步骤说明

1.填写execl表格

2.按需修改该python脚本中的create_host_vm函数中的inventory的内容。

3.执行脚本实现主机添加,并确认主机添加情况。

 

文件说明

 Zabbix使用python批量添加主机及主机资产信息-从零到无

 1.表示HOST INVENTORY清单中的项。

 2.客户现场实际数据填入。

 3.python程序里create_host_vm函数inventory项值 i的下标。各位可以根据自己的实际情况增减python脚本中的值的写入。

(在写入数据的时候execl中的最后两行可以不用删除,方便用户自定义数据时做参考,但是一定要放在最后,因为我的python脚本很简洁没有异常处理和判断)

ps:这个execl表可以自己梳理,也可以私信我获取。

 

官方的列表对应:

#此处的ID号和EXECL中ID没有任何关系,这个数据是从官网截出来的。
https://www.zabbix.com/documentation/4.4/manual/api/reference/host/object#host_inventory
ID    Property    Type    Description
4    alias    string    Alias.
11    asset_tag    string    Asset tag.
28    chassis    string    Chassis.
23    contact    string    Contact person.
32    contract_number    string    Contract number.
47    date_hw_decomm    string    HW decommissioning date.
46    date_hw_expiry    string    HW maintenance expiry date.
45    date_hw_install    string    HW installation date.
44    date_hw_purchase    string    HW purchase date.
34    deployment_status    string    Deployment status.
14    hardware    string    Hardware.
15    hardware_full    string    Detailed hardware.
39    host_netmask    string    Host subnet mask.
38    host_networks    string    Host networks.
40    host_router    string    Host router.
30    hw_arch    string    HW architecture.
33    installer_name    string    Installer name.
24    location    string    Location.
25    location_lat    string    Location latitude.
26    location_lon    string    Location longitude.
12    macaddress_a    string    MAC address A.
13    macaddress_b    string    MAC address B.
29    model    string    Model.
3    name    string    Name.
27    notes    string    Notes.
41    oob_ip    string    OOB IP address.
42    oob_netmask    string    OOB host subnet mask.
43    oob_router    string    OOB router.
5    os    string    OS name.
6    os_full    string    Detailed OS name.
7    os_short    string    Short OS name.
61    poc_1_cell    string    Primary POC mobile number.
58    poc_1_email    string    Primary email.
57    poc_1_name    string    Primary POC name.
63    poc_1_notes    string    Primary POC notes.
59    poc_1_phone_a    string    Primary POC phone A.
60    poc_1_phone_b    string    Primary POC phone B.
62    poc_1_screen    string    Primary POC screen name.
68    poc_2_cell    string    Secondary POC mobile number.
65    poc_2_email    string    Secondary POC email.
64    poc_2_name    string    Secondary POC name.
70    poc_2_notes    string    Secondary POC notes.
66    poc_2_phone_a    string    Secondary POC phone A.
67    poc_2_phone_b    string    Secondary POC phone B.
69    poc_2_screen    string    Secondary POC screen name.
8    serialno_a    string    Serial number A.
9    serialno_b    string    Serial number B.
48    site_address_a    string    Site address A.
49    site_address_b    string    Site address B.
50    site_address_c    string    Site address C.
51    site_city    string    Site city.
53    site_country    string    Site country.
56    site_notes    string    Site notes.
55    site_rack    string    Site rack location.
52    site_state    string    Site state.
54    site_zip    string    Site ZIP/postal code.
16    software    string    Software.
18    software_app_a    string    Software application A.
19    software_app_b    string    Software application B.
20    software_app_c    string    Software application C.
21    software_app_d    string    Software application D.
22    software_app_e    string    Software application E.
17    software_full    string    Software details.
10    tag    string    Tag.
1    type    string    Type.
2    type_full    string    Type details.
35    url_a    string    URL A.
36    url_b    string    URL B.
37    url_c    string    URL C.
31    vendor    string    Vendor.
View Code

相关文章: