Add support for macro contexts that have colons (#51853)

Currently when used with macro contexts that have a colon inside, 
macro_name gets truncated. A common case is contexts that represent a 
Windows drive. Examples:

  - 'C_DRIVE_THRESHOLD: "C:"'
  - 'C_DRIVE_THRESHOLD: "D:"'

This happens because line 189 assumes there are only one colon in 
macro_name, and thus two substrings to join.

To solve this, it is necessary considering that macro_name could have 
more that one colon. After the split, the first element is the proper 
Zabbix macro name. Then, the solution is joining all the remaining 
substrings after that.

This is backwards compatible in the case macro_name have only one colon.
This commit is contained in:
Pablo Piaggio 2019-02-18 11:51:35 -06:00 committed by John R Barker
parent a1ec74334a
commit d1d4f4bd27

View file

@ -186,7 +186,7 @@ def main():
force = module.params['force']
if ':' in macro_name:
macro_name = ':'.join([macro_name.split(':')[0].upper(), macro_name.split(':')[1]])
macro_name = ':'.join([macro_name.split(':')[0].upper(), ':'.join(macro_name.split(':')[1:])])
else:
macro_name = macro_name.upper()