]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix json output for Director::Autochanger directive with yes/no value
authorEric Bollengier <eric@baculasystems.com>
Fri, 5 May 2017 08:21:24 +0000 (10:21 +0200)
committerKern Sibbald <kern@sibbald.com>
Mon, 22 May 2017 13:01:42 +0000 (15:01 +0200)
bacula/src/dird/bdirjson.c

index ef5bf10c20d07ec94bd45577a8e4ad3dca5946ce..343c80aecffa8e5fa9cb7f92e5ab0a247397c5ba 100644 (file)
@@ -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) {