]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add new Director plugin variables
authorEric Bollengier <eric@baculasystems.com>
Thu, 7 Oct 2021 16:31:20 +0000 (18:31 +0200)
committerEric Bollengier <eric@baculasystems.com>
Wed, 6 Sep 2023 07:49:01 +0000 (09:49 +0200)
  bDirVarWorkingDir
  bDirVarInfo

bacula/src/dird/dir_plugins.c
bacula/src/dird/dir_plugins.h
bacula/src/dird/protos.h
bacula/src/dird/ua_status.c

index f9a806195f73663423f7a9c5f01c88e5c811d0f7..04d9d7987a1e27b9de6543ba89ca08b56f4c46ad 100644 (file)
@@ -314,6 +314,9 @@ static bRC baculaGetValue(bpContext *ctx, brDirVariable var, void *value)
    STORE *rstore = jcr->store_mngr->get_rstore();
    STORE *wstore = jcr->store_mngr->get_wstore();
    switch (var) {
+   case bDirVarWorkingDir:
+      *(void **)value = director->working_directory;
+      break;
    case bDirVarJobId:
       *((int *)value) = jcr->JobId;
       Dmsg1(dbglvl, "dir-plugin: return bDirVarJobId=%d\n", jcr->JobId);
@@ -433,6 +436,9 @@ static bRC baculaGetValue(bpContext *ctx, brDirVariable var, void *value)
       *((int *)value) = jcr->SDJobStatus;
       Dmsg1(dbglvl, "Bacula: return bDirVarSDJobStatus=%c\n", jcr->SDJobStatus);
       break;
+   case bDirVarInfo:
+      dir_get_information(jcr, (POOLMEM **) value);
+      break;
    default:
       break;
    }
index ea82c093a37cc7487ca640754dd98784a4aa6763..1938965e6e6dba94308c7fc87f1e1c4014ab247b 100644 (file)
@@ -84,7 +84,9 @@ typedef enum {
   bDirVarSDJobFiles = 20,          // int
   bDirVarSDErrors   = 21,          // int
   bDirVarFDJobStatus = 22,         // int
-  bDirVarSDJobStatus = 23          // int
+  bDirVarSDJobStatus = 23,         // int
+  bDirVarWorkingDir  = 24,         // const char *
+  bDirVarInfo        = 25          // must provide POOLMEM **
 } brDirVariable;
 
 typedef enum {
index 5d123942f14416b68aa5703ed36da3e972738ef6..1b0757856be0fb4ed20eef66cd98093747c051ee 100644 (file)
@@ -317,6 +317,7 @@ int scan_truncate_cmd(UAContext *ua, const char *cmd,
                      char *truncate_opt);
 /* ua_status.c */
 void list_dir_status_header(UAContext *ua);
+char *dir_get_information(JCR *jcr, POOLMEM **mem);
 
 /* ua_tree.c */
 bool user_select_files_from_tree(TREE_CTX *tree);
index a8b2d865c4659c2a300d95b2bd07a23cb8bc616d..a19f88b73e7cdcf4034399200876b63041ac1696 100644 (file)
@@ -1708,3 +1708,87 @@ static void api_collectors_status(UAContext *ua, char *collname)
    ua->send_msg("%s", buf);
    Dmsg0(200, "leave api_collectors_status()\n");
 };
+
+/* Display only one instance of each plugin */
+struct singleton
+{
+   hlink hp;
+   char  value[1];
+};
+
+static int store_singleton(void *ctx, int num_fields, char **row)
+{
+   htable *h = (htable *) ctx;
+   char *start = row[0];
+   for(char *p = row[0] ; p && *p ; p++) {
+      if (*p == ',' || *(p+1) == 0) {
+         if (*p == ',') {
+            *p = 0;
+         } // else it's already the end
+         strip_trailing_junk(start);
+         if (!h->lookup(start)) {
+            singleton *elt = (singleton *)h->hash_malloc(sizeof(singleton) + strlen(start));
+            bstrncpy(elt->value, start, strlen(start)+1);
+            h->insert(elt->value, elt);
+            start = p+1;
+         }
+      }
+   }
+   return 0;
+}
+   
+static void list_plugins(JCR *jcr, alist *list)
+{
+   if (!jcr->db) {
+      return;
+   }
+
+   singleton *v = NULL;
+   htable h(v, &v->hp, 50);
+   /* stored as plug1,plug2,plug3 */
+   db_sql_query(jcr->db, "SELECT Plugins FROM Client", store_singleton, &h);
+   foreach_htable(v, &h) {
+      list->append(bstrdup(v->value));
+   }
+}
+
+/* Get JSON information about the system */
+char *dir_get_information(JCR *jcr, POOLMEM **mem)
+{
+   if (!jcr->db) {
+      pm_strcpy(mem, "");
+      return *mem;
+   }
+
+   alist lst(10, owned_by_alist);
+   OutputWriter wt("j");
+   int64_t backups[3] = {0,0,0}, volumes[2] = {0,0};
+   db_sql_query(jcr->db,
+                "SELECT SUM(JobBytes), SUM(JobFiles), count(1) FROM Job WHERE Type IN ('B', 'C', 'M') AND JobStatus = 'T'",
+                db_mint64_handler, backups);
+
+   db_sql_query(jcr->db, "SELECT SUM(VolBytes)+SUM(VolABytes), count(1) FROM Media",
+                db_mint64_handler, volumes);
+   list_plugins(jcr, &lst);
+
+   wt.start_group("data");
+   wt.get_output(
+      OT_START_OBJ,
+      OT_STRING, "name",        my_name,
+      OT_STRING, "bacula_version",     VERSION " (" BDATE ")",
+      OT_STRING, "uname",       HOST_OS " " DISTNAME " " DISTVER,
+      OT_INT,    "nclients",    ((rblist *)res_head[R_CLIENT-r_first]->res_list)->size(),
+      OT_ALIST_STR, "plugins",  &lst,
+      OT_INT64,  "backup_size", backups[0],
+      OT_INT64,  "backup_files",backups[1],
+      OT_INT64,  "backup_nb",   backups[2],
+      OT_INT64,  "media_size",  volumes[0],
+      OT_INT64,  "media_nb",    volumes[1],
+      OT_STRING, "customerid",  NPRTB(director->customerid),
+      OT_INT,    "version",     1,
+      OT_END_OBJ,
+      OT_END);
+
+   pm_strcpy(mem,  wt.end_group());
+   return *mem;
+}