Skip to content

Commit a9e488d

Browse files
ariel-anielilukebakken
authored andcommitted
Fix for #8557, removed ANSI codes in JSON output
Add missing newline chars
1 parent f2fa293 commit a9e488d

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/cluster_status_command.ex

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
3232
use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments
3333
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
3434

35-
def run([], %{node: node_name, timeout: timeout}) do
35+
def run([], %{node: node_name, timeout: timeout} = opts) do
3636
status =
3737
case :rabbit_misc.rpc_call(node_name, :rabbit_db_cluster, :cli_cluster_status, []) do
3838
{:badrpc, {:EXIT, {:undef, _}}} ->
@@ -72,7 +72,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
7272
maintenance_status_by_node =
7373
Enum.map(
7474
nodes,
75-
fn n -> maintenance_status_by_node(n, per_node_timeout(timeout, count)) end
75+
fn n -> maintenance_status_by_node(n, per_node_timeout(timeout, count), opts) end
7676
)
7777

7878
cpu_cores_by_node =
@@ -340,26 +340,26 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
340340
}}
341341
end
342342

343-
defp maintenance_status_by_node(node, timeout) do
343+
defp maintenance_status_by_node(node, timeout, opts) do
344344
target = to_atom(node)
345+
formatter = Map.get(opts, :formatter)
346+
347+
rpc_result =
348+
:rabbit_misc.rpc_call(target, :rabbit_maintenance, :status_local_read, [target], timeout)
345349

346350
result =
347-
case :rabbit_misc.rpc_call(
348-
target,
349-
:rabbit_maintenance,
350-
:status_local_read,
351-
[target],
352-
timeout
353-
) do
354-
{:badrpc, _} -> "unknown"
355-
:regular -> "not under maintenance"
356-
:draining -> magenta("marked for maintenance")
351+
case {rpc_result, formatter} do
352+
{{:badrpc, _}, _} -> "unknown"
353+
{:regular, _} -> "not under maintenance"
354+
{:draining, "json"} -> "marked for maintenance"
355+
{:draining, _} -> magenta("marked for maintenance")
357356
# forward compatibility: should we figure out a way to know when
358357
# draining completes (it involves inherently asynchronous cluster
359358
# operations such as quorum queue leader re-election), we'd introduce
360359
# a new state
361-
:drained -> magenta("marked for maintenance")
362-
value -> to_string(value)
360+
{:drained, "json"} -> "marked for maintenance"
361+
{:drained, _} -> magenta("marked for maintenance")
362+
{value, _} -> to_string(value)
363363
end
364364

365365
{node, result}

deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/erlang_cookie_sources_command.ex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.ErlangCookieSourcesCommand do
88
@behaviour RabbitMQ.CLI.CommandBehaviour
99

1010
import RabbitMQ.CLI.Core.ANSI
11+
import RabbitMQ.CLI.Core.Platform, only: [line_separator: 0]
1112

1213
use RabbitMQ.CLI.Core.AcceptsDefaultSwitchesAndTimeout
1314
use RabbitMQ.CLI.Core.MergesNoDefaults
@@ -67,7 +68,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.ErlangCookieSourcesCommand do
6768

6869
def output(result, _opts) do
6970
cookie_file_lines = [
70-
"#{bright("Cookie File")}\n",
71+
"#{bright("Cookie File")}",
7172
"Effective user: #{result[:effective_user] || "(none)"}",
7273
"Effective home directory: #{result[:home_dir] || "(none)"}",
7374
"Cookie file path: #{result[:cookie_file_path]}",
@@ -78,20 +79,20 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.ErlangCookieSourcesCommand do
7879
]
7980

8081
switch_lines = [
81-
"\n#{bright("Cookie CLI Switch")}\n",
82+
"#{line_separator()}#{bright("Cookie CLI Switch")}",
8283
"--erlang-cookie value set? #{result[:switch_cookie_set]}",
8384
"--erlang-cookie value length: #{result[:switch_cookie_value_length] || 0}"
8485
]
8586

8687
os_env_lines = [
87-
"\n#{bright("Env variable ")} #{bright_red("(Deprecated)")}\n",
88+
"#{line_separator()}#{bright("Env variable ")} #{bright_red("(Deprecated)")}",
8889
"RABBITMQ_ERLANG_COOKIE value set? #{result[:os_env_cookie_set]}",
8990
"RABBITMQ_ERLANG_COOKIE value length: #{result[:os_env_cookie_value_length] || 0}"
9091
]
9192

9293
lines = cookie_file_lines ++ switch_lines ++ os_env_lines
9394

94-
{:ok, lines}
95+
{:ok, Enum.join(lines, line_separator())}
9596
end
9697

9798
def help_section(), do: :configuration
@@ -102,7 +103,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.ErlangCookieSourcesCommand do
102103

103104
def usage, do: "erlang_cookie_sources"
104105

105-
def formatter(), do: RabbitMQ.CLI.Formatters.StringPerLine
106+
def formatter(), do: RabbitMQ.CLI.Formatters.String
106107

107108
#
108109
# Implementation

0 commit comments

Comments
 (0)