Zabbix Agent for WAPT
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

92 regels
3.8 KiB

  1. # -*- coding: utf-8 -*-
  2. from setuphelpers import *
  3. uninstallkey = []
  4. variables = {
  5. 'zabbix_servers': [ '127.0.0.1' ]
  6. }
  7. # Read local variables file if available
  8. if isfile(makepath(programfiles32,'wapt','private','symetric.txt')) and isfile(makepath(programfiles32,'wapt','private','variables.txt')):
  9. print('Reading local encrypted variables file')
  10. from cryptography.fernet import Fernet
  11. import yaml
  12. f = Fernet(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read())
  13. variables.update(yaml.safe_load(f.decrypt(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read())))
  14. props = {
  15. 'RMTCMD':0,
  16. 'SERVER':','.join(variables['zabbix_servers'])
  17. }
  18. def install():
  19. version = control['version'].split('-',1)[0]
  20. # Remove previous version from suiviperf, if present
  21. print('Checking old Zabbix Agent version...')
  22. old_agent = installed_softwares('{65BE9C8D-BE1D-4AEA-A144-9F52D57A3D12}')
  23. for uninstall in old_agent:
  24. if Version(uninstall['version'].split('.',1)[0]) < Version(version) :
  25. if Version(uninstall['version']) < Version(version):
  26. killalltasks(['zabbix_agentd.exe'])
  27. print('Uninstalling previous version %s' % uninstall['version'])
  28. cmd = uninstall_cmd(uninstall['key'])
  29. run_notfatal(cmd)
  30. print('Installing Zabbix Agent version %s' % version)
  31. if iswin64():
  32. msi = 'zabbix_agent-%s-windows-amd64-openssl.msi' % version
  33. else:
  34. msi = 'zabbix_agent-%s-windows-i386-openssl.msi' % version
  35. install_msi_if_needed(msi,killbefore=['zabbix_agentd.exe'],properties=props,remove_old_version=True)
  36. print('Opening port 10050 in the firewall')
  37. # Remove the previous rule if it existed. We don't mind the return code as the rule might not exist
  38. run_notfatal('netsh advfirewall firewall del rule name="Zabbix Agent"')
  39. # And add a new one
  40. 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'])))
  41. # Copy conf, scripts and binaries
  42. print('Copying additional configuration, scripts and binaries')
  43. for dir in ['zabbix_agentd.conf.d','scripts','bin']:
  44. mkdirs(makepath(programfiles,'Zabbix Agent',dir))
  45. copytree2(dir,makepath(programfiles,'Zabbix Agent',dir))
  46. # Restart the service
  47. print('Restarting the service')
  48. service_restart('Zabbix Agent')
  49. def uninstall():
  50. print('Removing firewall rule')
  51. run_notfatal('netsh advfirewall firewall del rule name="Zabbix Agent"')
  52. def update_package():
  53. import requests, re
  54. from waptpackage import PackageEntry
  55. print('Checking latest agent version')
  56. page = wgets('https://www.zabbix.com/download')
  57. latest_version = re.search('"latest":"(\d+(\.\d+)*)"', page).group(1)
  58. pe = PackageEntry()
  59. control = pe.load_control_from_wapt(os.getcwd())
  60. current_version = control['version'].split('-',1)[0]
  61. if Version(latest_version) > Version(current_version):
  62. print('Updating package from %s to %s' % (current_version, latest_version))
  63. for arch in ['amd64', 'i386']:
  64. filename ='zabbix_agent-%s-windows-%s-openssl.msi' % (latest_version, arch)
  65. if not isfile(filename):
  66. url = 'https://www.zabbix.com/downloads/%s/%s' % (latest_version, filename)
  67. print('Downloading %s from %s' % (filename, url))
  68. wget(url, filename)
  69. for old in glob.glob(r'zabbix_agent-*-windows-%s-openssl.msi' % arch):
  70. if not old == filename:
  71. remove_file(old)
  72. pe.version = latest_version + '-0'
  73. pe.maturity = 'PREPROD'
  74. pe.save_control_to_wapt(os.getcwd())