wapt-zabbix-agent/setup.py

93 lines
3.9 KiB
Python
Raw Normal View History

2018-12-04 17:40:23 +01:00
# -*- coding: utf-8 -*-
from setuphelpers import *
uninstallkey = []
2018-12-05 10:35:10 +01:00
variables = {
'zabbix_servers': [ '127.0.0.1' ]
}
# Read local variables file if available
if isfile(makepath(programfiles32,'wapt','private','symetric.txt')) and isfile(makepath(programfiles32,'wapt','private','variables.txt')):
print('Reading local encrypted variables file')
2018-12-20 13:17:48 +01:00
from cryptography.fernet import Fernet
import yaml
2023-04-03 14:22:32 +02:00
f = Fernet(bytes(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read(), 'utf-8'))
variables.update(yaml.safe_load(f.decrypt(bytes(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read(), 'utf-8'))))
2018-12-05 10:35:10 +01:00
props = {
'RMTCMD':0,
'SERVER':','.join(variables['zabbix_servers'])
}
2018-12-04 17:40:23 +01:00
def install():
2018-12-05 10:35:10 +01:00
version = control['version'].split('-',1)[0]
2019-11-05 12:20:19 +01:00
# Remove previous version from suiviperf, if present
print('Checking old Zabbix Agent version...')
old_agent = installed_softwares('{65BE9C8D-BE1D-4AEA-A144-9F52D57A3D12}')
for uninstall in old_agent:
if Version(uninstall['version'].split('.',1)[0]) < Version(version) :
if Version(uninstall['version']) < Version(version):
killalltasks(['zabbix_agentd.exe'])
print('Uninstalling previous version %s' % uninstall['version'])
cmd = uninstall_cmd(uninstall['key'])
run_notfatal(cmd)
print('Installing Zabbix Agent version %s' % version)
2018-12-05 10:35:10 +01:00
if iswin64():
2020-02-03 09:44:37 +01:00
msi = 'zabbix_agent-%s-windows-amd64-openssl.msi' % version
2018-12-05 10:35:10 +01:00
else:
2020-02-03 09:44:37 +01:00
msi = 'zabbix_agent-%s-windows-i386-openssl.msi' % version
2019-11-05 12:20:19 +01:00
install_msi_if_needed(msi,killbefore=['zabbix_agentd.exe'],properties=props,remove_old_version=True)
2018-12-05 10:35:10 +01:00
print('Opening port 10050 in the firewall')
# Remove the previous rule if it existed. We don't mind the return code as the rule might not exist
run_notfatal('netsh advfirewall firewall del rule name="Zabbix Agent"')
2019-11-05 12:20:19 +01:00
2018-12-05 10:35:10 +01:00
# And add a new one
run('netsh advfirewall firewall add rule name="Zabbix Agent" dir=in action=allow protocol=TCP localport=10050 enable=yes remoteip=%s' % (','.join(variables['zabbix_servers'])))
# Copy conf, scripts and binaries
print('Copying additional configuration, scripts and binaries')
for dir in ['zabbix_agentd.conf.d','scripts','bin']:
mkdirs(makepath(programfiles,'Zabbix Agent',dir))
copytree2(dir,makepath(programfiles,'Zabbix Agent',dir))
# Restart the service
print('Restarting the service')
service_restart('Zabbix Agent')
2018-12-05 10:35:10 +01:00
def uninstall():
print('Removing firewall rule')
2018-12-15 15:25:14 +01:00
run_notfatal('netsh advfirewall firewall del rule name="Zabbix Agent"')
def update_package():
import requests, re
from waptpackage import PackageEntry
2019-11-05 12:20:19 +01:00
print('Checking latest agent version')
page = wgets('https://www.zabbix.com/download')
latest_version = re.search('"latest":"(\d+(\.\d+)*)"', page).group(1)
branch = re.search('"slug":"(\d+(\.\d+)*)"', page).group(1)
2018-12-15 15:25:14 +01:00
pe = PackageEntry()
control = pe.load_control_from_wapt(os.getcwd())
2019-11-05 12:20:19 +01:00
current_version = control['version'].split('-',1)[0]
if Version(latest_version) > Version(current_version):
print('Updating package from %s to %s' % (current_version, latest_version))
for arch in ['amd64', 'i386']:
2020-02-03 09:44:37 +01:00
filename ='zabbix_agent-%s-windows-%s-openssl.msi' % (latest_version, arch)
2019-11-05 12:20:19 +01:00
if not isfile(filename):
url = 'https://cdn.zabbix.com/zabbix/binaries/stable/%s/%s/%s' % (branch, latest_version, filename)
2019-11-05 12:20:19 +01:00
print('Downloading %s from %s' % (filename, url))
wget(url, filename)
for old in glob.glob(r'zabbix_agent-*-windows-%s-openssl.msi' % arch):
2019-11-05 12:20:19 +01:00
if not old == filename:
remove_file(old)
2018-12-15 15:25:14 +01:00
2019-11-05 12:20:19 +01:00
pe.version = latest_version + '-0'
pe.maturity = 'PREPROD'
2018-12-15 15:25:14 +01:00
pe.save_control_to_wapt(os.getcwd())