Commit 128fd400 authored by Geoff Simmons's avatar Geoff Simmons Committed by Dridi Boukelmoune

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

The panic string is added as a JSON string in the output array.
parent 95e9cfe6
......@@ -117,12 +117,9 @@ mgt_panic_clear(void)
VSB_destroy(&child_panic);
}
static void v_matchproto_(cli_func_t)
mch_cli_panic_show(struct cli *cli, const char * const *av, void *priv)
static void
cli_panic_show(struct cli *cli, const char * const *av, int json)
{
(void)av;
(void)priv;
if (!child_panic) {
VCLI_SetResult(cli, CLIS_CANT);
VCLI_Out(cli,
......@@ -130,7 +127,29 @@ mch_cli_panic_show(struct cli *cli, const char * const *av, void *priv)
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)
......@@ -694,7 +713,8 @@ static struct cli_proto cli_mch[] = {
mch_cli_server_status_json },
{ CLICMD_SERVER_START, "", mch_cli_server_start },
{ 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 },
{ NULL }
};
......
......@@ -44,6 +44,7 @@ client c1 {
} -run
varnish v1 -cliexpect "STACK OVERFLOW" "panic.show"
varnish v1 -clijson "panic.show -j"
varnish v1 -cliok "panic.clear"
......@@ -81,6 +82,7 @@ client c2 -connect ${v2_sock} {
} -run
varnish v2 -cliexpect "[bB]us error|Segmentation [fF]ault" "panic.show"
varnish v2 -clijson "panic.show -j"
varnish v2 -cliok "panic.clear"
......
......@@ -54,6 +54,7 @@ client c1 {
varnish v1 -wait-stopped
varnish v1 -cliok "panic.show"
varnish v1 -clijson "panic.show -j"
varnish v1 -cliok "panic.clear"
varnish v1 -expect MGT.child_panic == 1
varnish v1 -clierr 300 "panic.clear"
......@@ -70,6 +71,7 @@ client c1 {
varnish v1 -wait-stopped
varnish v1 -cliok "panic.show"
varnish v1 -clijson "panic.show -j"
varnish v1 -cliok "panic.clear -z"
varnish v1 -expect MGT.child_panic == 0
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