1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

add function for servicegrup downtimes

This commit is contained in:
Michael Gröning 2014-11-07 14:14:12 +01:00 committed by Matt Clay
parent edf63b1e60
commit 8a209ed30b

View file

@ -178,6 +178,7 @@ def main():
'silence_nagios',
'unsilence_nagios',
'command',
'servicegroup_downtime'
]
module = AnsibleModule(
@ -186,6 +187,7 @@ def main():
author=dict(default='Ansible'),
comment=dict(default='Scheduling downtime'),
host=dict(required=False, default=None),
servicegroup=dict(required=False, default=None),
minutes=dict(default=30),
cmdfile=dict(default=which_cmdfile()),
services=dict(default=None, aliases=['service']),
@ -195,6 +197,7 @@ def main():
action = module.params['action']
host = module.params['host']
servicegroup = module.params['servicegroup']
minutes = module.params['minutes']
services = module.params['services']
cmdfile = module.params['cmdfile']
@ -211,7 +214,7 @@ def main():
# 'minutes' and 'service' manually.
##################################################################
if action not in ['command', 'silence_nagios', 'unsilence_nagios']:
if action not in ['command', 'silence_nagios', 'unsilence_nagios', 'servicegroup_downtime']:
if not host:
module.fail_json(msg='no host specified for action requiring one')
######################################################################
@ -227,6 +230,20 @@ def main():
except Exception:
module.fail_json(msg='invalid entry for minutes')
######################################################################
if action == 'servicegroup_downtime':
# Make sure there's an actual service selected
if not servicegroup:
module.fail_json(msg='no servicegroup selected to set downtime for')
# Make sure minutes is a number
try:
m = int(minutes)
if not isinstance(m, types.IntType):
module.fail_json(msg='minutes must be a number')
except Exception:
module.fail_json(msg='invalid entry for minutes')
##################################################################
if action in ['enable_alerts', 'disable_alerts']:
if not services:
@ -270,6 +287,7 @@ class Nagios(object):
self.author = kwargs['author']
self.comment = kwargs['comment']
self.host = kwargs['host']
self.service_group = kwargs['servicegroup']
self.minutes = int(kwargs['minutes'])
self.cmdfile = kwargs['cmdfile']
self.command = kwargs['command']
@ -861,6 +879,9 @@ class Nagios(object):
self.schedule_svc_downtime(self.host,
services=self.services,
minutes=self.minutes)
if self.action == "servicegroup_downtime":
if self.services == 'servicegroup':
self.schedule_servicegroup_host_downtime(self, self.servicegroup, minutes=30)
# toggle the host AND service alerts
elif self.action == 'silence':