python写的部署windows下zabbix客户端脚本
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: www.2cto.com
os.popen('C:\\zabbix\\bin\\win32\\zabbix_agentd.exe -c C:\\zabbix\\conf\\zabbix_agentd.win.conf -i')
#以下是添加windows网卡流量监控的自定key,注意:一般的执行命令或脚本自定义key格式为:UserParameter=keyname,commd,网卡的为 PerfCounter=keyname,""
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[i])
if c:
b = "PerfCounter " + "=" + " eth"+str(e) + "_Out," + '"''"' + str(conm[i]).strip() + '",30'
#print b
f.write("%s \n" %b)
e += 1
e = 0
for i in range(len(conm)):
c = re.search('Received',conm[i])
if c:
b = "PerfCounter " + "=" + " eth"+str(e) + "_In," + '"' + str(conm[i]).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 !")
相关内容
- 暂无相关文章
评论关闭