zabbix_maintenance small stylistic updates and ansible version bump

pull/6125/merge
abulimov 11 years ago committed by Michael DeHaan
parent ccf031f1c5
commit 469f619598

@ -25,7 +25,7 @@ module: zabbix_maintenance
short_description: Create Zabbix maintenance windows short_description: Create Zabbix maintenance windows
description: description:
- This module will let you create Zabbix maintenance windows. - This module will let you create Zabbix maintenance windows.
version_added: "1.6" version_added: "1.7"
author: Alexander Bulimov author: Alexander Bulimov
requirements: requirements:
- zabbix-api python module - zabbix-api python module
@ -55,17 +55,21 @@ options:
default: null default: null
host_names: host_names:
description: description:
- Hosts to manage maintenance window for. Separate multiple hosts with commas. - Hosts to manage maintenance window for.
Separate multiple hosts with commas.
C(host_name) is an alias for C(host_names). C(host_name) is an alias for C(host_names).
B(Required) option when C(state) is I(present) and no C(host_groups) specified. B(Required) option when C(state) is I(present)
and no C(host_groups) specified.
required: false required: false
default: null default: null
aliases: [ "host_name" ] aliases: [ "host_name" ]
host_groups: host_groups:
description: description:
- Host groups to manage maintenance window for. Separate multiple groups with commas. - Host groups to manage maintenance window for.
Separate multiple groups with commas.
C(host_group) is an alias for C(host_groups). C(host_group) is an alias for C(host_groups).
B(Required) option when C(state) is I(present) and no C(host_names) specified. B(Required) option when C(state) is I(present)
and no C(host_names) specified.
required: false required: false
default: null default: null
aliases: [ "host_group" ] aliases: [ "host_group" ]
@ -138,7 +142,8 @@ EXAMPLES = '''
login_password=pAsSwOrD login_password=pAsSwOrD
''' '''
import datetime, time import datetime
import time
try: try:
from zabbix_api import ZabbixAPI from zabbix_api import ZabbixAPI
@ -146,6 +151,7 @@ try:
except ImportError: except ImportError:
HAS_ZABBIX_API = False HAS_ZABBIX_API = False
def create_maintenance(zbx, group_ids, host_ids, start_time, maintenance_type, period, name, desc): def create_maintenance(zbx, group_ids, host_ids, start_time, maintenance_type, period, name, desc):
end_time = start_time + period end_time = start_time + period
try: try:
@ -169,6 +175,7 @@ def create_maintenance(zbx, group_ids, host_ids, start_time, maintenance_type, p
return 1, None, str(e) return 1, None, str(e)
return 0, None, None return 0, None, None
def get_maintenance_id(zbx, name): def get_maintenance_id(zbx, name):
try: try:
result = zbx.maintenance.get( result = zbx.maintenance.get(
@ -188,13 +195,15 @@ def get_maintenance_id(zbx, name):
return 0, maintenance_ids, None return 0, maintenance_ids, None
def delete_maintenance(zbx, maintenance_id): def delete_maintenance(zbx, maintenance_id):
try: try:
result = zbx.maintenance.delete(maintenance_id) zbx.maintenance.delete(maintenance_id)
except BaseException as e: except BaseException as e:
return 1, None, str(e) return 1, None, str(e)
return 0, None, None return 0, None, None
def check_maintenance(zbx, name): def check_maintenance(zbx, name):
try: try:
result = zbx.maintenance.exists( result = zbx.maintenance.exists(
@ -206,6 +215,7 @@ def check_maintenance(zbx, name):
return 1, None, str(e) return 1, None, str(e)
return 0, result, None return 0, result, None
def get_group_ids(zbx, host_groups): def get_group_ids(zbx, host_groups):
group_ids = [] group_ids = []
for group in host_groups: for group in host_groups:
@ -229,6 +239,7 @@ def get_group_ids(zbx, host_groups):
return 0, group_ids, None return 0, group_ids, None
def get_host_ids(zbx, host_names): def get_host_ids(zbx, host_names):
host_ids = [] host_ids = []
for host in host_names: for host in host_names:
@ -288,7 +299,6 @@ def main():
else: else:
maintenance_type = 1 maintenance_type = 1
try: try:
zbx = ZabbixAPI(server_url) zbx = ZabbixAPI(server_url)
zbx.login(login_user, login_password) zbx.login(login_user, login_password)
@ -355,7 +365,6 @@ def main():
else: else:
module.fail_json(msg="Failed to remove maintenance: %s" % error) module.fail_json(msg="Failed to remove maintenance: %s" % error)
module.exit_json(changed=changed) module.exit_json(changed=changed)
# include magic from lib/ansible/module_common.py # include magic from lib/ansible/module_common.py

Loading…
Cancel
Save