Commit 8c34b878 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Update zabbix and add version checks

parent b09bcf90
#!/usr/bin/env python3
import urllib.request
import re
PATTERN = r'<a\shref="(?P<link>\d\.\d/)">(?P<version>\d\.\d)/</a>\s+(?P<date>\d{2}-[A-Z][a-z]{2}-\d{4} \d{2}:\d{2})\s+-'
def get_versions():
response = urllib.request.urlopen("https://repo.zabbix.com/zabbix/")
page_content = response.read().decode("utf-8")
for match in re.findall(PATTERN, page_content):
link, version, date = match
major, minor = map(int, version.split("."))
if minor % 2 == 0:
yield (major, minor), date
def main():
import sys
current_version = sys.argv[1]
current_major, current_minor = map(int, current_version.split("."))
highest_version, date = sorted(get_versions())[-1]
if (current_major, current_minor) < highest_version:
print(
"New Zabbix version is available: {} from {}, please upgrade!".format(
'.'.join(map(str, highest_version)),
date))
if __name__ == "__main__":
main()
......@@ -17,9 +17,9 @@
repo: "{{ item }}"
state: absent
with_items:
- 'deb http://repo.zabbix.com/zabbix/3.0/debian {{ debian_version }} main'
- 'deb http://repo.zabbix.com/zabbix/{{old_zabbix_version}}/debian {{ debian_version }} main'
# yamllint disable-line rule:line-length
- 'deb-src http://repo.zabbix.com/zabbix/3.0/debian {{ debian_version }} main'
- 'deb-src http://repo.zabbix.com/zabbix/{{old_zabbix_version}}/debian {{ debian_version }} main'
notify:
- update apt cache
tags:
......@@ -31,9 +31,9 @@
repo: "{{ item }}"
state: present
with_items:
- 'deb http://repo.zabbix.com/zabbix/3.4/debian {{ debian_version }} main'
- 'deb http://repo.zabbix.com/zabbix/{{zabbix_version}}/debian {{ debian_version }} main'
# yamllint disable-line rule:line-length
- 'deb-src http://repo.zabbix.com/zabbix/3.4/debian {{debian_version }} main'
- 'deb-src http://repo.zabbix.com/zabbix/{{zabbix_version}}/debian {{debian_version }} main'
notify:
- update apt cache
tags:
......@@ -64,4 +64,32 @@
- zabbix
- chr
- name: query installed packages
package_facts:
register: installed_packages
tags:
- repos
- zabbix
- name: check for new packages
block:
- name: upload the version check script
copy:
src: check-update.py
dest: "/usr/local/sbin/check-update.py"
owner: root
group: root
mode: '0755'
- name: ensure the version check script is executed regularly
template:
src: crontab.j2
dest: /etc/cron.d/check-zabbix-version
owner: root
group: root
mode: '0644'
when: '"zabbix-server-pgsql" in installed_packages.ansible_facts.packages'
tags:
- repos
- zabbix
- meta: flush_handlers
{{60|random(seed=inventory_hostname)}} {{6|random(seed=inventory_hostname)}} * * * root /usr/local/sbin/check-update.py {{zabbix_version}}
---
old_zabbix_version: "3.4"
zabbix_version: "4.0"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment