jrgf 发表于 2013-1-10 08:56:49

python写的部署windows下zabbix客户端脚本


[*]#!/bin/env python
# -*- coding: utf-8 -*-
##########################################################
# @This script is used to Install zabbix clent for Windows(32/64)
# @Function: Install zabbix clent for Windows
# @Create Date: 2013-01-02
#打包官方zabbix_agents_2.0.4.win.zip为rar包,指定解压软件rar的路径。
##########################################################
import os,re,sys,urllib,wmi

c = wmi.WMI ()
for s in c.Win32_Service ():
if s.Caption == "Zabbix Agent":
sys.exit("zabbix already install")

url = 'http://192.168.110.110/zabbix_agents_2.0.4.win.rar'
local = 'C:\\zabbix_agents_2.0.4.win.rar'
urllib.urlretrieve(url,local,)
url = 'http://192.168.110.110/rar.exe'
local = 'C:\\rar.exe'#本地如果安装了指定相应的目录
urllib.urlretrieve(url,local,)
os.popen('C:\\rar.exe x -y C:\\zabbix_agents_2.0.4.win.rar -ed C:\\')

sProgramFiles = os.environ['PROGRAMFILES']
if "(86)" in sProgramFiles:
os.popen('C:\\zabbix\\bin\\win64\\zabbix_agentd.exe -c C:\\zabbix\\conf\\zabbix_agentd.win.conf -i')
else:
os.popen('C:\\zabbix\\bin\\win32\\zabbix_agentd.exe -c C:\\zabbix\\conf\\zabbix_agentd.win.conf -i')

conm = os.popen('typeperf.exe -qx|find "Network Interface"|find "Bytes"|find /v "Total"|find /v "Loopback"').readlines()
f=open('C:\zabbix\conf\zabbix_agentd.win.conf','a+')
f.write('\n')
e = 0
for i in range(len(conm)):
c = re.search('Sent',conm)
if c:
b = "PerfCounter " + "=" + " eth"+str(e) + "_Out," + '"''"' + str(conm).strip() + '",30'
#print b
f.write("%s \n" %b)
e += 1
e = 0
for i in range(len(conm)):
c = re.search('Received',conm)
if c:
b = "PerfCounter " + "=" + " eth"+str(e) + "_In," + '"' + str(conm).strip() + '",30'
#print b
f.write("%s \n" %b)
e += 1
f.close()
'''''
f = open('C:\zabbix\zabbix_agentd.conf','r+')
ip = f.read()
ip = ip.replace('192.168.1.100',ipnew)
f.seek(0)
f.write(ip)
f.close()
'''
os.popen('net start "Zabbix Agent"')
os.popen('net stop "Zabbix Agent"')
os.popen('net start "Zabbix Agent"')
os.remove('C:\\rar.exe')
os.remove('C:\\zabbix_agents_2.0.4.win.rar')
sys.exit("zabbix install success !")

lichaoyue888 发表于 2013-3-14 05:59:07

不错不错,楼主您辛苦了。。。

fish3129 发表于 2013-5-16 00:32:21

.其实我是一个天才,可惜天妒英才!

xuanhao 发表于 2013-5-16 17:59:04

漏洞与补丁齐飞,蓝屏共死机一色!

asfsd 发表于 2013-5-17 14:38:15

穿别人的鞋,走自己的路,让他们找去吧。

midea2 发表于 2013-5-19 05:59:12

沙发!沙发!
页: [1]
查看完整版本: python写的部署windows下zabbix客户端脚本