Skip to content

Commit

Permalink
Fix double heredoc in get_mailbox_properties
Browse files Browse the repository at this point in the history
  • Loading branch information
deajan committed Nov 11, 2024
1 parent 55c6f72 commit 226c954
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions grommunio_exporter/grommunio_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 226c954

Please sign in to comment.