- #!/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`)
- #以下是新增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:zabbixconfzabbix_agentd.win.conf`,`a+`)
- f.write(` `)
- 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 " %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 " %b)
- e += 1
- f.close()
- `````
- f = open(`C:zabbixzabbix_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 !")