zabbix_maintenance small stylistic updates and ansible version bump

This commit is contained in:
abulimov 2014-07-11 11:09:05 +04:00 committed by Michael DeHaan
parent a8d5a3f849
commit 6834ee7977

View file

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