使用说明:
此脚本使用方法,详细步骤如下(不清楚的可以加我微信或QQ咨询)
脚本默认添加内容如excel模板所示:主机名、显示名、IP地址、所属组、所属模板1、所属模板2(如需要添加其他内容如: 多个所属组、多个模板、DNS、SNMP等,可联系本人)
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
资源下载价格9.9元立即支付
注意:本站部分资源网络收集,如涉及版权问题请及时与站长联系,我们会在第一时间内与您协商解决。如非特殊说明,本站所有资源解压密码均为:zhangqiongjie.com。
客服:1923002089