1.安装python的xlrd包(用于支持读取excel文件),我这里是python2.7环境
方法一:
(1)到官网下载xlrd模块:https://pypi.python.org/pypi/xlrd (2)解压压缩包:tar xvf xlrd-1.0.0.tar.gz (3)进入到解压的文件夹运行python setup.py install命令安装
方法二:
#使用pypi安装模块,需先安装pypi包 apt-get install pypi #安装xlrd pip install xlrd
2.编写批量添加主机的脚本(注意:网上的脚本仅支持添加1个模板,这里支持添加2个模板)
执行脚本和excel模板,可以通过文末资源下载获取,亲测可用。
3.编辑excel模板
excel文件中的每列对应,在zabbix上创建主机时的相关设置
第一列 Host name:主机名 第二列 Visible name:现实的名称 第三列 IPaddress:IP地址 第四列 hostgroup:所属组 第五列 hosttemp1:模板1 第六列 hosttemp2:模板2
4. 执行脚本
将excel文件和批量脚本放到同一个目录下,填写好excel后,直接执行脚本即可,如下:
[root@localhost sh]# cd /opt/package/zabbix/sh/ [root@localhost sh]# ll -h total 24K -rw-r--r-- 1 root root 12K Dec 2 14:09 ServerList.xlsx -rwxr-xr-x 1 root root 9.9K Dec 2 16:15 ZabbixHostImport.sh
执行及执行结果如下:
[root@localhost sh]# python addhost.sh Number Of cnhshacdc1ms026: 1 cnhshacdc1ms026+130.147.219.41 have exist! Cannot recreate ! Number Of bama-vms-02: 0 host : 130.147.219.56 is created! id is 10398 Number Of bama-vms-03: 0 host : 130.147.219.52 is created! id is 10399 Number Of shatgw01: 0 host : 130.147.219.203 is created! id is 10400 Number Of CNHSZHDCS1VU107: 0 host : 130.147.219.15 is created! id is 10401 Number Of CNHSZHDCS1VU108: 0 host : 130.147.219.16 is created! id is 10402 Number Of CNHSZHDCS1VU109: 0 host : 130.147.219.18 is created! id is 10403 Number Of CNHSZHDCS1VU116: 0 host : 130.147.219.19 is created! id is 10404 Number Of CNHSZHDCS1VU111: 0 host : 130.147.219.20 is created! id is 10405 Number Of CNHSZHDCS1VU113: 0 host : 130.147.219.24 is created! id is 10406 Number Of CNHSZHDCS1VU114: 0 host : 130.147.219.60 is created! id is 10407 Number Of cdc-infrman70: 0 host : 130.147.219.196 is created! id is 10408 Number Of CNHSZHDCS1VU115: 0 host : 130.147.219.9 is created! id is 10409
也可以参考:https://www.cnblogs.com/momoshouhu/p/8053907.html
资源下载价格2元立即支付
注意:本站少数资源收集于网络,如涉及版权等问题请及时与站长联系,我们会在第一时间内与您协商解决。如非特殊说明,本站所有资源解压密码均为:zhangqiongjie.com。
作者:1923002089
评论前必须登录!
注册