[master] 5687c10ed Add JSON support for the "panic.show" CLI command.
Geoff Simmons
geoff at uplex.de
Mon Oct 8 11:28:12 UTC 2018
commit 5687c10edc88758dadbf4b9367b20d0ed862ea69
Author: Geoff Simmons <geoff at uplex.de>
Date: Tue Sep 25 09:47:57 2018 +0200
Add JSON support for the "panic.show" CLI command.
The panic string is added as a JSON string in the output array.
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index 026bdd8e8..16050b33a 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -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 }
};
diff --git a/bin/varnishtest/tests/c00057.vtc b/bin/varnishtest/tests/c00057.vtc
index 2b2f38891..5118c79a0 100644
--- a/bin/varnishtest/tests/c00057.vtc
+++ b/bin/varnishtest/tests/c00057.vtc
@@ -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"
diff --git a/bin/varnishtest/tests/v00010.vtc b/bin/varnishtest/tests/v00010.vtc
index b948d0187..c488f377f 100644
--- a/bin/varnishtest/tests/v00010.vtc
+++ b/bin/varnishtest/tests/v00010.vtc
@@ -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"
More information about the varnish-commit
mailing list