diff --git a/changelogs/fragments/49568-type-checking.yaml b/changelogs/fragments/49568-type-checking.yaml new file mode 100644 index 00000000000..ab4bedbaa64 --- /dev/null +++ b/changelogs/fragments/49568-type-checking.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- "nagios - Removed redundant type check which caused crashes. Guardrails added elsewhere in earlier change." diff --git a/lib/ansible/modules/monitoring/nagios.py b/lib/ansible/modules/monitoring/nagios.py index 24cade85c90..d144ea6cb54 100644 --- a/lib/ansible/modules/monitoring/nagios.py +++ b/lib/ansible/modules/monitoring/nagios.py @@ -65,6 +65,7 @@ options: description: - Minutes to schedule downtime for. - Only usable with the C(downtime) action. + type: int default: 30 services: description: @@ -193,7 +194,6 @@ EXAMPLES = ''' command: DISABLE_FAILURE_PREDICTION ''' -import types import time import os.path import stat @@ -271,7 +271,6 @@ 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'] command = module.params['command'] @@ -284,7 +283,7 @@ def main(): # command = command # # AnsibleModule will verify most stuff, we need to verify - # 'minutes' and 'service' manually. + # 'service' manually. ################################################################## if action not in ['command', 'silence_nagios', 'unsilence_nagios']: @@ -295,13 +294,6 @@ def main(): # Make sure there's an actual service selected if not services: module.fail_json(msg='no service 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 == 'delete_downtime': @@ -315,13 +307,6 @@ def main(): # 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']: @@ -367,7 +352,7 @@ class Nagios(object): self.comment = kwargs['comment'] self.host = kwargs['host'] self.servicegroup = kwargs['servicegroup'] - self.minutes = int(kwargs['minutes']) + self.minutes = kwargs['minutes'] self.cmdfile = kwargs['cmdfile'] self.command = kwargs['command']