From 226c954a40959f080f9460439599a251aa0ef808 Mon Sep 17 00:00:00 2001 From: Orsiris de Jong Date: Mon, 11 Nov 2024 12:37:18 +0100 Subject: [PATCH] Fix double heredoc in get_mailbox_properties --- grommunio_exporter/grommunio_api.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/grommunio_exporter/grommunio_api.py b/grommunio_exporter/grommunio_api.py index 22ad10d..c35fa39 100644 --- a/grommunio_exporter/grommunio_api.py +++ b/grommunio_exporter/grommunio_api.py @@ -191,11 +191,12 @@ def _get_mailbox_properties(self, usernames: List[str]): grommunio-admin shell -x << EOF 2>/dev/null | awk 'BEGIN {printf "["} {if ($1=="exmdb") { if (first==1) { printf "],["} else {first=1}}; if ($1~/^0x/) {next} ; printf"\n%s{\"%s\": \"%s\"}", sep,$1,$2; sep=","} END { printf "]" }' """ mailbox_properties = {} - awk_cmd = r"""grommunio-admin shell -x << EOF 2>/dev/null | awk 'BEGIN {printf "["} {if ($1=="exmdb") { if (first==1) { printf "],["} else {first=1}}; if ($1~/^0x/) {next} ; printf"\n%s{\"%s\": \"%s\"}", sep,$1,$2; sep=","} END { printf "]" }'""" - grommunio_shell_cmd = "" + awk_cmd = r"""awk 'BEGIN {printf "["} {if ($1=="exmdb") { if (first==1) { printf "],["} else {first=1}}; if ($1~/^0x/) {next} ; printf"\n%s{\"%s\": \"%s\"}", sep,$1,$2; sep=","} END { printf "]" }'""" + grommunio_shell_cmds = "" for username in usernames: - grommunio_shell_cmd += f"exmdb {username} store get\n" - cmd = f"{self.cli_binary} shell -x << EOF 2>/dev/null | {awk_cmd}\n{grommunio_shell_cmd}\nEOF" + grommunio_shell_cmds += f"exmdb {username} store get\n" + cmd = f"{self.cli_binary} shell -x << EOF 2>/dev/null | {awk_cmd}\n{grommunio_shell_cmds}\nEOF" + exit_code, result = command_runner(cmd, shell=True) if exit_code == 0: print(result)