From b7fda43b06fae5705acf62889064dc6c5b658432 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 13 Nov 2008 15:17:38 +0000 Subject: [PATCH] ebl Add more variable accessible through the director plugin interface. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8044 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dir_plugins.c | 113 ++++++++++++++++++++ bacula/src/dird/dir_plugins.h | 46 ++++---- bacula/src/plugins/dir/Makefile.in | 4 +- bacula/src/plugins/dir/example-plugin-dir.c | 24 +++++ bacula/technotes-2.5 | 3 + 5 files changed, 166 insertions(+), 24 deletions(-) diff --git a/bacula/src/dird/dir_plugins.c b/bacula/src/dird/dir_plugins.c index 4f0dc71503..0985ed3e28 100644 --- a/bacula/src/dird/dir_plugins.c +++ b/bacula/src/dird/dir_plugins.c @@ -200,6 +200,119 @@ static bRC baculaGetValue(bpContext *ctx, brVariable var, void *value) *((char **)value) = jcr->Job; Dmsg1(dbglvl, "Bacula: return bVarJobName=%s\n", jcr->Job); break; + case bVarJob: + *((char **)value) = jcr->job->hdr.name; + Dmsg1(dbglvl, "Bacula: return bVarJob=%s\n", jcr->job->hdr.name); + break; + case bVarLevel: + *((int *)value) = jcr->get_JobLevel(); + Dmsg1(dbglvl, "Bacula: return bVarLevel=%c\n", jcr->get_JobLevel()); + break; + case bVarType: + *((int *)value) = jcr->get_JobType(); + Dmsg1(dbglvl, "Bacula: return bVarType=%c\n", jcr->get_JobType()); + break; + case bVarClient: + *((char **)value) = jcr->client->hdr.name; + Dmsg1(dbglvl, "Bacula: return bVarClient=%s\n", jcr->client->hdr.name); + break; + case bVarNumVols: + POOL_DBR pr; + memset(&pr, 0, sizeof(pr)); + bstrncpy(pr.Name, jcr->pool->hdr.name, sizeof(pr.Name)); + if (!db_get_pool_record(jcr, jcr->db, &pr)) { + ret=bRC_Error; + } + *((int *)value) = pr.NumVols; + Dmsg1(dbglvl, "Bacula: return bVarNumVols=%d\n", pr.NumVols); + break; + case bVarPool: + *((char **)value) = jcr->pool->hdr.name; + Dmsg1(dbglvl, "Bacula: return bVarPool=%s\n", jcr->pool->hdr.name); + break; + case bVarStorage: + if (jcr->wstore) { + *((char **)value) = jcr->wstore->hdr.name; + } else if (jcr->rstore) { + *((char **)value) = jcr->rstore->hdr.name; + } else { + *((char **)value) = NULL; + ret=bRC_Error; + } + Dmsg1(dbglvl, "Bacula: return bVarStorage=%s\n", NPRT(*((char **)value))); + break; + case bVarWriteStorage: + if (jcr->wstore) { + *((char **)value) = jcr->wstore->hdr.name; + } else { + *((char **)value) = NULL; + ret=bRC_Error; + } + Dmsg1(dbglvl, "Bacula: return bVarWriteStorage=%s\n", NPRT(*((char **)value))); + break; + case bVarReadStorage: + if (jcr->rstore) { + *((char **)value) = jcr->rstore->hdr.name; + } else { + *((char **)value) = NULL; + ret=bRC_Error; + } + Dmsg1(dbglvl, "Bacula: return bVarReadStorage=%s\n", NPRT(*((char **)value))); + break; + case bVarCatalog: + *((char **)value) = jcr->catalog->hdr.name; + Dmsg1(dbglvl, "Bacula: return bVarCatalog=%s\n", jcr->catalog->hdr.name); + break; + case bVarMediaType: + if (jcr->wstore) { + *((char **)value) = jcr->wstore->media_type; + } else if (jcr->rstore) { + *((char **)value) = jcr->rstore->media_type; + } else { + *((char **)value) = NULL; + ret=bRC_Error; + } + Dmsg1(dbglvl, "Bacula: return bVarMediaType=%s\n", NPRT(*((char **)value))); + break; + case bVarJobStatus: + *((int *)value) = jcr->JobStatus; + Dmsg1(dbglvl, "Bacula: return bVarJobStatus=%c\n", jcr->JobStatus); + break; + case bVarPriority: + *((int *)value) = jcr->JobPriority; + Dmsg1(dbglvl, "Bacula: return bVarPriority=%d\n", jcr->JobPriority); + break; + case bVarVolumeName: + *((char **)value) = jcr->VolumeName; + Dmsg1(dbglvl, "Bacula: return bVarVolumeName=%s\n", jcr->VolumeName); + break; + case bVarCatalogRes: + ret = bRC_Error; + break; + case bVarJobErrors: + *((int *)value) = jcr->JobErrors; + Dmsg1(dbglvl, "Bacula: return bVarErrors=%d\n", jcr->JobErrors); + break; + case bVarJobFiles: + *((int *)value) = jcr->JobFiles; + Dmsg1(dbglvl, "Bacula: return bVarFiles=%d\n", jcr->JobFiles); + break; + case bVarSDJobFiles: + *((int *)value) = jcr->SDJobFiles; + Dmsg1(dbglvl, "Bacula: return bVarSDFiles=%d\n", jcr->SDJobFiles); + break; + case bVarSDErrors: + *((int *)value) = jcr->SDErrors; + Dmsg1(dbglvl, "Bacula: return bVarSDErrors=%d\n", jcr->SDErrors); + break; + case bVarFDJobStatus: + *((int *)value) = jcr->FDJobStatus; + Dmsg1(dbglvl, "Bacula: return bVarFDJobStatus=%c\n", jcr->FDJobStatus); + break; + case bVarSDJobStatus: + *((int *)value) = jcr->SDJobStatus; + Dmsg1(dbglvl, "Bacula: return bVarSDJobStatus=%c\n", jcr->SDJobStatus); + break; default: ret = bRC_Error; break; diff --git a/bacula/src/dird/dir_plugins.h b/bacula/src/dird/dir_plugins.h index 1bf94e2a77..6158c8ed61 100644 --- a/bacula/src/dird/dir_plugins.h +++ b/bacula/src/dird/dir_plugins.h @@ -69,29 +69,31 @@ extern "C" { * * ****************************************************************************/ -/* Bacula Variable Ids */ +/* Bacula Variable Ids */ /* return value */ typedef enum { - bVarJob = 1, - bVarLevel = 2, - bVarType = 3, - bVarJobId = 4, - bVarClient = 5, - bVarNumVols = 6, - bVarPool = 7, - bVarStorage = 8, - bVarCatalog = 9, - bVarMediaType = 10, - bVarJobName = 11, - bVarJobStatus = 12, - bVarPriority = 13, - bVarVolumeName = 14, - bVarCatalogRes = 15, - bVarJobErrors = 16, - bVarJobFiles = 17, - bVarSDJobFiles = 18, - bVarSDErrors = 19, - bVarFDJobStatus = 20, - bVarSDJobStatus = 21 + bVarJob = 1, // string + bVarLevel = 2, // int + bVarType = 3, // int + bVarJobId = 4, // int + bVarClient = 5, // string + bVarNumVols = 6, // int + bVarPool = 7, // string + bVarStorage = 8, // string + bVarWriteStorage = 9, // string + bVarReadStorage = 10, // string + bVarCatalog = 11, // string + bVarMediaType = 12, // string + bVarJobName = 13, // string + bVarJobStatus = 14, // int + bVarPriority = 15, // int + bVarVolumeName = 16, // string + bVarCatalogRes = 17, // NYI + bVarJobErrors = 18, // int + bVarJobFiles = 19, // int + bVarSDJobFiles = 20, // int + bVarSDErrors = 21, // int + bVarFDJobStatus = 22, // int + bVarSDJobStatus = 23 // int } brVariable; typedef enum { diff --git a/bacula/src/plugins/dir/Makefile.in b/bacula/src/plugins/dir/Makefile.in index 8cb08df2e4..6c4582108a 100644 --- a/bacula/src/plugins/dir/Makefile.in +++ b/bacula/src/plugins/dir/Makefile.in @@ -31,7 +31,7 @@ main: dir_plugins.o $(CXX) $(LDFLAGS) -L${LIBDIR} dir_plugins.o -o main -lbac -lpthread -lssl -l crypto -ldl example-plugin-dir.o: example-plugin-dir.c ${DIRDIR}/dir_plugins.h - $(CXX) -fPIC -I../.. -I${DIRDIR} -c example-plugin-dir.c + $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -fPIC -I../.. -I${DIRDIR} -c example-plugin-dir.c example-plugin-dir.so: example-plugin-dir.o $(CXX) $(LDFLAGS) -shared example-plugin-dir.o -o example-plugin-dir.so @@ -40,7 +40,7 @@ example-plugin-dir.lo: example-plugin-dir.c ${DIRDIR}/dir_plugins.h $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CFLAGS) -I../.. -I${DIRDIR} -c example-plugin-dir.c example-plugin-dir.la: Makefile example-plugin-dir$(DEFAULT_OBJECT_TYPE) - $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CFLAGS) -I../.. -I${DIRDIR} -c example-plugin-dir.c + $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -shared example-plugin-dir.lo -o $@ -rpath $(plugindir) -module -export-dynamic -avoid-version install: all $(MKDIR) $(DESTDIR)$(plugindir) diff --git a/bacula/src/plugins/dir/example-plugin-dir.c b/bacula/src/plugins/dir/example-plugin-dir.c index e1441933be..8980c19b20 100644 --- a/bacula/src/plugins/dir/example-plugin-dir.c +++ b/bacula/src/plugins/dir/example-plugin-dir.c @@ -129,12 +129,36 @@ static bRC setPluginValue(bpContext *ctx, pVariable var, void *value) static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) { char *name; + int val; switch (event->eventType) { case bEventJobStart: printf("plugin: HandleEvent JobStart\n"); break; case bEventJobEnd: printf("plugin: HandleEvent JobEnd\n"); + bfuncs->getBaculaValue(ctx, bVarJob, (void *)&name); + printf("plugin: bVarJob=%s\n", name); + bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&val); + printf("plugin: bVarJobId=%d\n", val); + bfuncs->getBaculaValue(ctx, bVarType, (void *)&val); + printf("plugin: bVarType=%c\n", val); + bfuncs->getBaculaValue(ctx, bVarLevel, (void *)&val); + printf("plugin: bVarLevel=%c\n", val); + bfuncs->getBaculaValue(ctx, bVarClient, (void *)&name); + printf("plugin: bVarClient=%s\n", name); + bfuncs->getBaculaValue(ctx, bVarCatalog, (void *)&name); + printf("plugin: bVarCatalog=%s\n", name); + bfuncs->getBaculaValue(ctx, bVarPool, (void *)&name); + printf("plugin: bVarPool=%s\n", name); + bfuncs->getBaculaValue(ctx, bVarStorage, (void *)&name); + printf("plugin: bVarStorage=%s\n", name); + bfuncs->getBaculaValue(ctx, bVarJobErrors, (void *)&val); + printf("plugin: bVarJobErrors=%d\n", val); + bfuncs->getBaculaValue(ctx, bVarJobFiles, (void *)&val); + printf("plugin: bVarJobFiles=%d\n", val); + bfuncs->getBaculaValue(ctx, bVarNumVols, (void *)&val); + printf("plugin: bVarNumVols=%d\n", val); + break; } bfuncs->getBaculaValue(ctx, bVarJobName, (void *)&name); diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index 92396b0a5e..9a311512e1 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -10,6 +10,9 @@ filepattern (restore with regex in bsr) mixed priorities General: +13Nov08 +ebl Add more variable accessible through the director plugin + interface. 12Nov08 ebl Do work on plugins - fix compilation of the director plugins -- 2.39.5