{"id":6368,"date":"2020-07-28T13:23:22","date_gmt":"2020-07-28T19:23:22","guid":{"rendered":"http:\/\/gregsowell.com\/?p=6368"},"modified":"2020-07-28T13:23:22","modified_gmt":"2020-07-28T19:23:22","slug":"ansible-zabbix-modules-controlling-maintenance-mode","status":"publish","type":"post","link":"https:\/\/gregsowell.com\/?p=6368","title":{"rendered":"Ansible Zabbix Modules &#8211; Controlling Maintenance Mode"},"content":{"rendered":"<p>Ansible has a lot of good <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/modules\/list_of_monitoring_modules.html#zabbix\">Zabbix control modules found here:<\/a>.<br \/>\nzabbix_action \u2013 Create\/Delete\/Update Zabbix actions<br \/>\nzabbix_group \u2013 Create\/delete Zabbix host groups<br \/>\nzabbix_group_info \u2013 Gather information about Zabbix hostgroup<br \/>\nzabbix_host \u2013 Create\/update\/delete Zabbix hosts<br \/>\nzabbix_host_info \u2013 Gather information about Zabbix host<br \/>\nzabbix_hostmacro \u2013 Create\/update\/delete Zabbix host macros<br \/>\nzabbix_maintenance \u2013 Create Zabbix maintenance windows<br \/>\nzabbix_map \u2013 Create\/update\/delete Zabbix maps<br \/>\nzabbix_mediatype \u2013 Create\/Update\/Delete Zabbix media types<br \/>\nzabbix_proxy \u2013 Create\/delete\/get\/update Zabbix proxies<br \/>\nzabbix_screen \u2013 Create\/update\/delete Zabbix screens<br \/>\nzabbix_template \u2013 Create\/update\/delete\/dump Zabbix template<\/p>\n<p>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 <a href=\"https:\/\/github.com\/gregsowell\/ansible-zabbix\/blob\/master\/zabbix_maint_group.yml\">playbook I used is linked here<\/a>, so the version you see below may be old.<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">---\r\n- name: Put Zabbix groups into maint\r\n  hosts: all\r\n  gather_facts: false\r\n  vars:\r\n    maint_desc: IOS upgrades\r\n    maint_group: cat_update_lab\r\n    maint_mins: 90\r\n    zab_host: 192.168.51.5\r\n# gen1_user\/pass are custom credentials I use in tower\r\n#    gen1_user: username\r\n#    gen1_pword: password\r\n\r\n  tasks:\r\n  - name: put the devices undergoing work into maint\r\n    run_once: True\r\n    zabbix_maintenance:\r\n      name: &quot;{{ maint_desc }}&quot;\r\n      host_groups: \r\n        - &quot;{{ maint_group }}&quot;\r\n      state: present\r\n      minutes: &quot;{{ maint_mins }}&quot;\r\n      server_url: &quot;http:\/\/{{ zab_host }}\/zabbix&quot;\r\n      login_user: &quot;{{ gen1_user }}&quot;\r\n      login_password: &quot;{{ gen1_pword }}&quot;<\/code><\/pre>\n<p>I&#8217;ve gotten where I variablize as much of the work as I can so that I can just pass parameters in via Tower.<br \/>\nIn this case I created a custom credential for username and password, so that is passed in at run time.<br \/>\nzab_host is the IP or DNS name of the user.<br \/>\nAlso notice the server_url; the default install path is \/zabbix, so if you changed that adjust it here.<br \/>\nI&#8217;m using host_groups, which means I&#8217;m disabling a group of devices at a time.  You could also just do the individual hosts or hosts and groups if you want.<\/p>\n<p><strong>Something important to note is that the zabbix API must be installed on the zabbix server<\/strong>:<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">pip3 install zabbix-api<\/code><\/pre>\n<p>Here&#8217;s a shot of my workflow.<br \/>\n<a href=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2020\/07\/workflow1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2020\/07\/workflow1-300x67.png\" alt=\"\" width=\"300\" height=\"67\" class=\"aligncenter size-medium wp-image-6369\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2020\/07\/workflow1-300x67.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2020\/07\/workflow1-768x173.png 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2020\/07\/workflow1-1024x230.png 1024w, https:\/\/gregsowell.com\/wp-content\/uploads\/2020\/07\/workflow1.png 1428w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nFirst I put the kit into maintenance mode.<br \/>\nSecond I perform a backup of the devices to be upgraded.<br \/>\nLast I check if the devices are at the correct version and if not, perform the upgrade.<\/p>\n<p>With so many options, I&#8217;m sure I&#8217;ll keep building; let me know what you envision having Ansible do?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ansible has a lot of good Zabbix control modules found here:. zabbix_action \u2013 Create\/Delete\/Update Zabbix actions zabbix_group \u2013 Create\/delete Zabbix host groups zabbix_group_info \u2013\u2026<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49,50],"tags":[],"class_list":["post-6368","post","type-post","status-publish","format-standard","hentry","category-ansible","category-zabbix"],"_links":{"self":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/6368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6368"}],"version-history":[{"count":1,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/6368\/revisions"}],"predecessor-version":[{"id":6370,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/6368\/revisions\/6370"}],"wp:attachment":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}