Skip to content

Commit

Permalink
Fix tabs, typos and default checking for the acknowledge close argument
Browse files Browse the repository at this point in the history
  • Loading branch information
talek authored and mbakke committed Oct 17, 2022
1 parent c8c71a4 commit f0f4590
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions zabbix_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4880,8 +4880,8 @@ def do_acknowledge_event(self, args):
Values:
false - (default) Let the event opened.
true - Manualy close the event.
false - (default) Leave the event opened.
true - Close the event.
"""
ack_message_default = '[Zabbix-CLI] Acknowledged via acknowledge_events'
ack_close_default = 'false'
Expand Down Expand Up @@ -4909,17 +4909,27 @@ def do_acknowledge_event(self, args):
elif len(arg_list) == 2:
event_ids = arg_list[0].strip()
ack_message = arg_list[1].strip()
close = ack_close_default
close = ack_close_default

elif len(arg_list) == 3:
event_ids = arg_list[0].strip()
ack_message = arg_list[1].strip()
close = arg_list[2].strip().lower()
close = arg_list[2].strip().lower()

else:
self.generate_feedback('Error', ' Wrong number of parameters used.\n Type help or \\? to list commands')
return False

#
# Sanity check
#

if ack_message == '':
ack_message = ack_message_default

if close == '':
close = ack_close_default

if close not in ['false', 'true']:
self.generate_feedback('Error', ' Invalid value for [close] argument')
return False
Expand All @@ -4934,12 +4944,6 @@ def do_acknowledge_event(self, args):
else:
action = None # Zabbix pre 4.0 does not have action

#
# Sanity check
#

if ack_message == '':
ack_message = ack_message_default

event_ids = event_ids.replace(' ', '').split(',')

Expand Down Expand Up @@ -4982,8 +4986,8 @@ def do_acknowledge_trigger_last_event(self, args):
Values:
false - (default) Let the event opened.
true - Manualy close the event.
false - (default) Leave the event opened.
true - Close the event.
"""
event_ids = []
ack_message_default = '[Zabbix-CLI] Acknowledged via acknowledge_trigger_last_event'
Expand Down Expand Up @@ -5012,28 +5016,31 @@ def do_acknowledge_trigger_last_event(self, args):
elif len(arg_list) == 2:
trigger_ids = arg_list[0].strip()
ack_message = arg_list[1].strip()
close = ack_close_default
close = ack_close_default

elif len(arg_list) == 3:
trigger_ids = arg_list[0].strip()
ack_message = arg_list[1].strip()
close = arg_list[2].strip().lower()
close = arg_list[2].strip().lower()

else:
self.generate_feedback('Error', ' Wrong number of parameters used.\n Type help or \\? to list commands')
return False

if close not in ['false', 'true']:
self.generate_feedback('Error', ' Invalid value for [close] argument')
return False

#
# Sanity check
#

if ack_message == '':
ack_message = ack_message_default

if close == '':
close = ack_close_default

if close not in ['false', 'true']:
self.generate_feedback('Error', ' Invalid value for [close] argument')
return False

trigger_ids = trigger_ids.replace(' ', '').split(',')

try:
Expand Down

0 comments on commit f0f4590

Please sign in to comment.