From 938edebb15bcb6783b1046b5ff36d0551441f733 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Fri, 5 May 2017 10:21:24 +0200 Subject: [PATCH] Fix json output for Director::Autochanger directive with yes/no value --- bacula/src/dird/bdirjson.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/bacula/src/dird/bdirjson.c b/bacula/src/dird/bdirjson.c index ef5bf10c20..343c80aecf 100644 --- a/bacula/src/dird/bdirjson.c +++ b/bacula/src/dird/bdirjson.c @@ -897,7 +897,7 @@ static void display_run(HPKT &hpkt) */ static void dump_json(display_filter *filter) { - int resinx, item, first_directive; + int resinx, item, first_directive, name_pos=0; bool first_res; RES_ITEM *items; RES *res; @@ -967,6 +967,14 @@ static void dump_json(display_filter *filter) sendit(NULL, ",\n"); } + /* Find where the Name is defined, should always be 0 */ + for (item=0; items[item].name; item++) { + if (strcmp(items[item].name, "Name") == 0) { + name_pos = item; + break; + } + } + if (filter->do_only_data) { sendit(NULL, " {"); @@ -1059,6 +1067,18 @@ static void dump_json(display_filter *filter) } } else { /* end if is present */ /* For some directive, the bitmap is not set (like addresses) */ + + /* Special trick for the Autochanger directive, it can be yes/no/storage */ + if (strcmp(resources[resinx].name, "Storage") == 0) { + if (strcmp(items[item].name, "Autochanger") == 0 + && items[item].handler == store_bool /* yes or no */ + && *(items[item].value) != NULL + && *(items[item-1].value) == NULL) /* The previous "Autochanger" name is not set */ + { + if (first_directive++ > 0) sendit(NULL, ","); + sendit(NULL, "\n \"Autochanger\": %s", quote_string(hpkt.edbuf2, *items[name_pos].value)); + } + } if (strcmp(resources[resinx].name, "Director") == 0) { if (strcmp(items[item].name, "DirPort") == 0) { if (get_first_port_host_order(director->DIRaddrs) != items[item].default_value) { -- 2.39.5