Skip to content
Jul 28 / Greg

Ansible Zabbix Modules – Controlling Maintenance Mode

Ansible has a lot of good Zabbix control modules found here:.
zabbix_action – Create/Delete/Update Zabbix actions
zabbix_group – Create/delete Zabbix host groups
zabbix_group_info – Gather information about Zabbix hostgroup
zabbix_host – Create/update/delete Zabbix hosts
zabbix_host_info – Gather information about Zabbix host
zabbix_hostmacro – Create/update/delete Zabbix host macros
zabbix_maintenance – Create Zabbix maintenance windows
zabbix_map – Create/update/delete Zabbix maps
zabbix_mediatype – Create/Update/Delete Zabbix media types
zabbix_proxy – Create/delete/get/update Zabbix proxies
zabbix_screen – Create/update/delete Zabbix screens
zabbix_template – Create/update/delete/dump Zabbix template

I decided that in my Cisco IOS upgrade workflow I wanted the devices being updated to be in maintenance mode to cut down on notification spam. The playbook I used is linked here, so the version you see below may be old.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
---
- name: Put Zabbix groups into maint
  hosts: all
  gather_facts: false
  vars:
    maint_desc: IOS upgrades
    maint_group: cat_update_lab
    maint_mins: 90
    zab_host: 192.168.51.5
# gen1_user/pass are custom credentials I use in tower
#    gen1_user: username
#    gen1_pword: password
 
  tasks:
  - name: put the devices undergoing work into maint
    run_once: True
    zabbix_maintenance:
      name: "{{ maint_desc }}"
      host_groups: 
        - "{{ maint_group }}"
      state: present
      minutes: "{{ maint_mins }}"
      server_url: "http://{{ zab_host }}/zabbix"
      login_user: "{{ gen1_user }}"
      login_password: "{{ gen1_pword }}"

I’ve gotten where I variablize as much of the work as I can so that I can just pass parameters in via Tower.
In this case I created a custom credential for username and password, so that is passed in at run time.
zab_host is the IP or DNS name of the user.
Also notice the server_url; the default install path is /zabbix, so if you changed that adjust it here.
I’m using host_groups, which means I’m disabling a group of devices at a time. You could also just do the individual hosts or hosts and groups if you want.

Something important to note is that the zabbix API must be installed on the zabbix server:

1
pip3 install zabbix-api

Here’s a shot of my workflow.

First I put the kit into maintenance mode.
Second I perform a backup of the devices to be upgraded.
Last I check if the devices are at the correct version and if not, perform the upgrade.

With so many options, I’m sure I’ll keep building; let me know what you envision having Ansible do?

Leave a Comment

 

*