Commit 5687c10e authored by Geoff Simmons's avatar Geoff Simmons

Add JSON support for the "panic.show" CLI command.

The panic string is added as a JSON string in the output array.
parent 8d83019a
...@@ -117,12 +117,9 @@ mgt_panic_clear(void) ...@@ -117,12 +117,9 @@ mgt_panic_clear(void)
VSB_destroy(&child_panic); VSB_destroy(&child_panic);
} }
static void v_matchproto_(cli_func_t) static void
mch_cli_panic_show(struct cli *cli, const char * const *av, void *priv) cli_panic_show(struct cli *cli, const char * const *av, int json)
{ {
(void)av;
(void)priv;
if (!child_panic) { if (!child_panic) {
VCLI_SetResult(cli, CLIS_CANT); VCLI_SetResult(cli, CLIS_CANT);
VCLI_Out(cli, VCLI_Out(cli,
...@@ -130,7 +127,29 @@ mch_cli_panic_show(struct cli *cli, const char * const *av, void *priv) ...@@ -130,7 +127,29 @@ mch_cli_panic_show(struct cli *cli, const char * const *av, void *priv)
return; return;
} }
VCLI_Out(cli, "%s\n", VSB_data(child_panic)); if (!json) {
VCLI_Out(cli, "%s\n", VSB_data(child_panic));
return;
}
VCLI_JSON_begin(cli, 2, av);
VCLI_Out(cli, ",\n");
VCLI_JSON_str(cli, VSB_data(child_panic));
VCLI_JSON_end(cli);
}
static void v_matchproto_(cli_func_t)
mch_cli_panic_show(struct cli *cli, const char * const *av, void *priv)
{
(void)priv;
cli_panic_show(cli, av, 0);
}
static void v_matchproto_(cli_func_t)
mch_cli_panic_show_json(struct cli *cli, const char * const *av, void *priv)
{
(void)priv;
cli_panic_show(cli, av, 1);
} }
static void v_matchproto_(cli_func_t) static void v_matchproto_(cli_func_t)
...@@ -694,7 +713,8 @@ static struct cli_proto cli_mch[] = { ...@@ -694,7 +713,8 @@ static struct cli_proto cli_mch[] = {
mch_cli_server_status_json }, mch_cli_server_status_json },
{ CLICMD_SERVER_START, "", mch_cli_server_start }, { CLICMD_SERVER_START, "", mch_cli_server_start },
{ CLICMD_SERVER_STOP, "", mch_cli_server_stop }, { CLICMD_SERVER_STOP, "", mch_cli_server_stop },
{ CLICMD_PANIC_SHOW, "", mch_cli_panic_show }, { CLICMD_PANIC_SHOW, "", mch_cli_panic_show,
mch_cli_panic_show_json },
{ CLICMD_PANIC_CLEAR, "", mch_cli_panic_clear }, { CLICMD_PANIC_CLEAR, "", mch_cli_panic_clear },
{ NULL } { NULL }
}; };
......
...@@ -44,6 +44,7 @@ client c1 { ...@@ -44,6 +44,7 @@ client c1 {
} -run } -run
varnish v1 -cliexpect "STACK OVERFLOW" "panic.show" varnish v1 -cliexpect "STACK OVERFLOW" "panic.show"
varnish v1 -clijson "panic.show -j"
varnish v1 -cliok "panic.clear" varnish v1 -cliok "panic.clear"
...@@ -81,6 +82,7 @@ client c2 -connect ${v2_sock} { ...@@ -81,6 +82,7 @@ client c2 -connect ${v2_sock} {
} -run } -run
varnish v2 -cliexpect "[bB]us error|Segmentation [fF]ault" "panic.show" varnish v2 -cliexpect "[bB]us error|Segmentation [fF]ault" "panic.show"
varnish v2 -clijson "panic.show -j"
varnish v2 -cliok "panic.clear" varnish v2 -cliok "panic.clear"
......
...@@ -54,6 +54,7 @@ client c1 { ...@@ -54,6 +54,7 @@ client c1 {
varnish v1 -wait-stopped varnish v1 -wait-stopped
varnish v1 -cliok "panic.show" varnish v1 -cliok "panic.show"
varnish v1 -clijson "panic.show -j"
varnish v1 -cliok "panic.clear" varnish v1 -cliok "panic.clear"
varnish v1 -expect MGT.child_panic == 1 varnish v1 -expect MGT.child_panic == 1
varnish v1 -clierr 300 "panic.clear" varnish v1 -clierr 300 "panic.clear"
...@@ -70,6 +71,7 @@ client c1 { ...@@ -70,6 +71,7 @@ client c1 {
varnish v1 -wait-stopped varnish v1 -wait-stopped
varnish v1 -cliok "panic.show" varnish v1 -cliok "panic.show"
varnish v1 -clijson "panic.show -j"
varnish v1 -cliok "panic.clear -z" varnish v1 -cliok "panic.clear -z"
varnish v1 -expect MGT.child_panic == 0 varnish v1 -expect MGT.child_panic == 0
varnish v1 -clierr 300 "panic.clear" varnish v1 -clierr 300 "panic.clear"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment