Merge pull request #228 from michaelgroening/devel

enable setting downtimes for Service-Group services and hosts
reviewable/pr18780/r1
Brian Coca 11 years ago
commit 35a86c3423

@ -0,0 +1 @@
1.8.2

@ -33,7 +33,8 @@ options:
required: true required: true
default: null default: null
choices: [ "downtime", "enable_alerts", "disable_alerts", "silence", "unsilence", choices: [ "downtime", "enable_alerts", "disable_alerts", "silence", "unsilence",
"silence_nagios", "unsilence_nagios", "command" ] "silence_nagios", "unsilence_nagios", "command", "servicegroup_service_downtime",
"servicegroup_host_downtime" ]
host: host:
description: description:
- Host to operate on in Nagios. - Host to operate on in Nagios.
@ -71,6 +72,10 @@ options:
aliases: [ "service" ] aliases: [ "service" ]
required: true required: true
default: null default: null
servicegroup:
description:
- the Servicegroup we want to set downtimes/alerts for.
B(Required) option when using the C(servicegroup_service_downtime) amd C(servicegroup_host_downtime).
command: command:
description: description:
- The raw command to send to nagios, which - The raw command to send to nagios, which
@ -100,6 +105,12 @@ EXAMPLES = '''
# schedule downtime for a few services # schedule downtime for a few services
- nagios: action=downtime services=frob,foobar,qeuz host={{ inventory_hostname }} - nagios: action=downtime services=frob,foobar,qeuz host={{ inventory_hostname }}
# set 30 minutes downtime for all services in servicegroup foo
- nagios: action=servicegroup_service_downtime minutes=30 servicegroup=foo host={{ inventory_hostname }}
# set 30 minutes downtime for all host in servicegroup foo
- nagios: action=servicegroup_host_downtime minutes=30 servicegroup=foo host={{ inventory_hostname }}
# enable SMART disk alerts # enable SMART disk alerts
- nagios: action=enable_alerts service=smart host={{ inventory_hostname }} - nagios: action=enable_alerts service=smart host={{ inventory_hostname }}
@ -179,14 +190,18 @@ def main():
'silence_nagios', 'silence_nagios',
'unsilence_nagios', 'unsilence_nagios',
'command', 'command',
'servicegroup_host_downtime',
'servicegroup_service_downtime',
] ]
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
action=dict(required=True, default=None, choices=ACTION_CHOICES), action=dict(required=True, default=None, choices=ACTION_CHOICES),
author=dict(default='Ansible'), author=dict(default='Ansible'),
comment=dict(default='Scheduling downtime'), comment=dict(default='Scheduling downtime'),
host=dict(required=False, default=None), host=dict(required=False, default=None),
servicegroup=dict(required=False, default=None),
minutes=dict(default=30), minutes=dict(default=30),
cmdfile=dict(default=which_cmdfile()), cmdfile=dict(default=which_cmdfile()),
services=dict(default=None, aliases=['service']), services=dict(default=None, aliases=['service']),
@ -196,6 +211,7 @@ def main():
action = module.params['action'] action = module.params['action']
host = module.params['host'] host = module.params['host']
servicegroup = module.params['servicegroup']
minutes = module.params['minutes'] minutes = module.params['minutes']
services = module.params['services'] services = module.params['services']
cmdfile = module.params['cmdfile'] cmdfile = module.params['cmdfile']
@ -228,6 +244,20 @@ def main():
except Exception: except Exception:
module.fail_json(msg='invalid entry for minutes') module.fail_json(msg='invalid entry for minutes')
######################################################################
if action in ['servicegroup_service_downtime', 'servicegroup_host_downtime']:
# Make sure there's an actual servicegroup 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 action in ['enable_alerts', 'disable_alerts']:
if not services: if not services:
@ -271,6 +301,7 @@ class Nagios(object):
self.author = kwargs['author'] self.author = kwargs['author']
self.comment = kwargs['comment'] self.comment = kwargs['comment']
self.host = kwargs['host'] self.host = kwargs['host']
self.servicegroup = kwargs['servicegroup']
self.minutes = int(kwargs['minutes']) self.minutes = int(kwargs['minutes'])
self.cmdfile = kwargs['cmdfile'] self.cmdfile = kwargs['cmdfile']
self.command = kwargs['command'] self.command = kwargs['command']
@ -862,6 +893,12 @@ class Nagios(object):
self.schedule_svc_downtime(self.host, self.schedule_svc_downtime(self.host,
services=self.services, services=self.services,
minutes=self.minutes) minutes=self.minutes)
elif self.action == "servicegroup_host_downtime":
if self.servicegroup:
self.schedule_servicegroup_host_downtime(servicegroup = self.servicegroup, minutes = self.minutes)
elif self.action == "servicegroup_service_downtime":
if self.servicegroup:
self.schedule_servicegroup_svc_downtime(servicegroup = self.servicegroup, minutes = self.minutes)
# toggle the host AND service alerts # toggle the host AND service alerts
elif self.action == 'silence': elif self.action == 'silence':

Loading…
Cancel
Save