From: Eric Bollengier Date: Thu, 7 Oct 2021 16:31:20 +0000 (+0200) Subject: Add new Director plugin variables X-Git-Tag: Beta-15.0.0~856 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b303057e81cd180321f53d6eb89d08625f673ba;p=thirdparty%2Fbacula.git Add new Director plugin variables bDirVarWorkingDir bDirVarInfo --- diff --git a/bacula/src/dird/dir_plugins.c b/bacula/src/dird/dir_plugins.c index f9a806195..04d9d7987 100644 --- a/bacula/src/dird/dir_plugins.c +++ b/bacula/src/dird/dir_plugins.c @@ -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; } diff --git a/bacula/src/dird/dir_plugins.h b/bacula/src/dird/dir_plugins.h index ea82c093a..1938965e6 100644 --- a/bacula/src/dird/dir_plugins.h +++ b/bacula/src/dird/dir_plugins.h @@ -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 { diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 5d123942f..1b0757856 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -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); diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index a8b2d865c..a19f88b73 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -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; +}