Nagios module: minor change, added "start" parameter (#61562)

* Finished implementing the "start" parameter to the nagios module. The backend functions already had it; this change just exposes it. This allows setting the time a Nagios outage begins rather than always starting at the time the module was run. If not provided, "start" defaults to the current time (preserving compability with existing playbooks).
* Changed default start time to None, as per comment by @goneri. This avoids initializing the variable twice.
pull/65616/head
Dan Ramaley 5 years ago committed by Gonéri Le Bouder
parent b8cd4c5409
commit 09fca101b7

@ -0,0 +1,5 @@
minor_changes:
- nagios module - a start parameter has been added, allowing the time a
Nagios outage starts to be set. It defaults to the current time if not
provided, preserving the previous behavior and ensuring compatibility with
existing playbooks.

@ -61,6 +61,10 @@ options:
description:
- Comment for C(downtime) action.
default: Scheduling downtime
start:
version_added: "2.10"
description:
- When downtime should start, in time_t format (epoch seconds).
minutes:
description:
- Minutes to schedule downtime for.
@ -104,6 +108,14 @@ EXAMPLES = '''
service: host
host: '{{ inventory_hostname }}'
# schedule an hour of HOST downtime starting at 2019-04-23T02:00:00+00:00
- nagios:
action: downtime
start: 1555984800
minutes: 60
service: host
host: '{{ inventory_hostname }}'
# schedule an hour of HOST downtime, with a comment describing the reason
- nagios:
action: downtime
@ -261,6 +273,7 @@ def main():
comment=dict(default='Scheduling downtime'),
host=dict(required=False, default=None),
servicegroup=dict(required=False, default=None),
start=dict(required=False, default=None),
minutes=dict(default=30, type='int'),
cmdfile=dict(default=which_cmdfile()),
services=dict(default=None, aliases=['service']),
@ -271,6 +284,7 @@ def main():
action = module.params['action']
host = module.params['host']
servicegroup = module.params['servicegroup']
start = module.params['start']
services = module.params['services']
cmdfile = module.params['cmdfile']
command = module.params['command']
@ -352,6 +366,7 @@ class Nagios(object):
self.comment = kwargs['comment']
self.host = kwargs['host']
self.servicegroup = kwargs['servicegroup']
self.start = int(kwargs['start'])
self.minutes = kwargs['minutes']
self.cmdfile = kwargs['cmdfile']
self.command = kwargs['command']
@ -507,7 +522,7 @@ class Nagios(object):
return notif_str
def schedule_svc_downtime(self, host, services=None, minutes=30):
def schedule_svc_downtime(self, host, services=None, minutes=30, start=None):
"""
This command is used to schedule downtime for a particular
service.
@ -526,10 +541,10 @@ class Nagios(object):
services = []
for service in services:
dt_cmd_str = self._fmt_dt_str(cmd, host, minutes, svc=service)
dt_cmd_str = self._fmt_dt_str(cmd, host, minutes, start=start, svc=service)
self._write_command(dt_cmd_str)
def schedule_host_downtime(self, host, minutes=30):
def schedule_host_downtime(self, host, minutes=30, start=None):
"""
This command is used to schedule downtime for a particular
host.
@ -542,10 +557,10 @@ class Nagios(object):
"""
cmd = "SCHEDULE_HOST_DOWNTIME"
dt_cmd_str = self._fmt_dt_str(cmd, host, minutes)
dt_cmd_str = self._fmt_dt_str(cmd, host, minutes, start=start)
self._write_command(dt_cmd_str)
def schedule_host_svc_downtime(self, host, minutes=30):
def schedule_host_svc_downtime(self, host, minutes=30, start=None):
"""
This command is used to schedule downtime for
all services associated with a particular host.
@ -558,7 +573,7 @@ class Nagios(object):
"""
cmd = "SCHEDULE_HOST_SVC_DOWNTIME"
dt_cmd_str = self._fmt_dt_str(cmd, host, minutes)
dt_cmd_str = self._fmt_dt_str(cmd, host, minutes, start=start)
self._write_command(dt_cmd_str)
def delete_host_downtime(self, host, services=None, comment=None):
@ -580,7 +595,7 @@ class Nagios(object):
dt_del_cmd_str = self._fmt_dt_del_str(cmd, host, svc=service, comment=comment)
self._write_command(dt_del_cmd_str)
def schedule_hostgroup_host_downtime(self, hostgroup, minutes=30):
def schedule_hostgroup_host_downtime(self, hostgroup, minutes=30, start=None):
"""
This command is used to schedule downtime for all hosts in a
particular hostgroup.
@ -593,10 +608,10 @@ class Nagios(object):
"""
cmd = "SCHEDULE_HOSTGROUP_HOST_DOWNTIME"
dt_cmd_str = self._fmt_dt_str(cmd, hostgroup, minutes)
dt_cmd_str = self._fmt_dt_str(cmd, hostgroup, minutes, start=start)
self._write_command(dt_cmd_str)
def schedule_hostgroup_svc_downtime(self, hostgroup, minutes=30):
def schedule_hostgroup_svc_downtime(self, hostgroup, minutes=30, start=None):
"""
This command is used to schedule downtime for all services in
a particular hostgroup.
@ -613,10 +628,10 @@ class Nagios(object):
"""
cmd = "SCHEDULE_HOSTGROUP_SVC_DOWNTIME"
dt_cmd_str = self._fmt_dt_str(cmd, hostgroup, minutes)
dt_cmd_str = self._fmt_dt_str(cmd, hostgroup, minutes, start=start)
self._write_command(dt_cmd_str)
def schedule_servicegroup_host_downtime(self, servicegroup, minutes=30):
def schedule_servicegroup_host_downtime(self, servicegroup, minutes=30, start=None):
"""
This command is used to schedule downtime for all hosts in a
particular servicegroup.
@ -630,10 +645,10 @@ class Nagios(object):
"""
cmd = "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME"
dt_cmd_str = self._fmt_dt_str(cmd, servicegroup, minutes)
dt_cmd_str = self._fmt_dt_str(cmd, servicegroup, minutes, start=start)
self._write_command(dt_cmd_str)
def schedule_servicegroup_svc_downtime(self, servicegroup, minutes=30):
def schedule_servicegroup_svc_downtime(self, servicegroup, minutes=30, start=None):
"""
This command is used to schedule downtime for all services in
a particular servicegroup.
@ -651,7 +666,7 @@ class Nagios(object):
"""
cmd = "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME"
dt_cmd_str = self._fmt_dt_str(cmd, servicegroup, minutes)
dt_cmd_str = self._fmt_dt_str(cmd, servicegroup, minutes, start=start)
self._write_command(dt_cmd_str)
def disable_host_svc_notifications(self, host):
@ -1002,13 +1017,16 @@ class Nagios(object):
# host or service downtime?
if self.action == 'downtime':
if self.services == 'host':
self.schedule_host_downtime(self.host, self.minutes)
self.schedule_host_downtime(self.host, minutes=self.minutes,
start=self.start)
elif self.services == 'all':
self.schedule_host_svc_downtime(self.host, self.minutes)
self.schedule_host_svc_downtime(self.host, minutes=self.minutes,
start=self.start)
else:
self.schedule_svc_downtime(self.host,
services=self.services,
minutes=self.minutes)
minutes=self.minutes,
start=self.start)
elif self.action == 'delete_downtime':
if self.services == 'host':
@ -1020,10 +1038,10 @@ class Nagios(object):
elif self.action == "servicegroup_host_downtime":
if self.servicegroup:
self.schedule_servicegroup_host_downtime(servicegroup=self.servicegroup, minutes=self.minutes)
self.schedule_servicegroup_host_downtime(servicegroup=self.servicegroup, minutes=self.minutes, start=self.start)
elif self.action == "servicegroup_service_downtime":
if self.servicegroup:
self.schedule_servicegroup_svc_downtime(servicegroup=self.servicegroup, minutes=self.minutes)
self.schedule_servicegroup_svc_downtime(servicegroup=self.servicegroup, minutes=self.minutes, start=self.start)
# toggle the host AND service alerts
elif self.action == 'silence':

Loading…
Cancel
Save