summaryrefslogtreecommitdiffstats
path: root/plugins/omlibdbi
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-02-02 17:51:08 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2012-02-02 17:51:08 +0100
commit8b7924fb8a3fa24cefc573b7372514d26a684b2d (patch)
tree0a29cab53c3f4ab38eb1efb891ac6303df4ca00d /plugins/omlibdbi
parentb467b44dae691c14cd2ddbaf90467e75063a237b (diff)
downloadrsyslog-8b7924fb8a3fa24cefc573b7372514d26a684b2d.tar.gz
rsyslog-8b7924fb8a3fa24cefc573b7372514d26a684b2d.tar.xz
rsyslog-8b7924fb8a3fa24cefc573b7372514d26a684b2d.zip
upgraded omlibdbi to support the new v6 config format
Diffstat (limited to 'plugins/omlibdbi')
-rw-r--r--plugins/omlibdbi/omlibdbi.c84
1 files changed, 82 insertions, 2 deletions
diff --git a/plugins/omlibdbi/omlibdbi.c b/plugins/omlibdbi/omlibdbi.c
index 44e635c1..8f5fa944 100644
--- a/plugins/omlibdbi/omlibdbi.c
+++ b/plugins/omlibdbi/omlibdbi.c
@@ -61,6 +61,7 @@ DEFobjCurrIf(errmsg)
static int bDbiInitialized = 0; /* dbi_initialize() can only be called one - this keeps track of it */
typedef struct _instanceData {
+ uchar *dbiDrvrDir; /* where do the dbi drivers reside? */
dbi_conn conn; /* handle to database */
uchar *drvrName; /* driver to use */
uchar *host; /* host to connect to */
@@ -68,6 +69,7 @@ typedef struct _instanceData {
uchar *pwd; /* password for connect */
uchar *dbName; /* database to use */
unsigned uLastDBErrno; /* last errno returned by libdbi or 0 if all is well */
+ uchar *tplName; /* format template to use */
} instanceData;
typedef struct configSettings_s {
@@ -80,6 +82,24 @@ typedef struct configSettings_s {
} configSettings_t;
static configSettings_t cs;
+/* tables for interfacing with the v6 config system */
+/* action (instance) parameters */
+static struct cnfparamdescr actpdescr[] = {
+ { "server", eCmdHdlrGetWord, 1 },
+ { "db", eCmdHdlrGetWord, 1 },
+ { "uid", eCmdHdlrGetWord, 1 },
+ { "pwd", eCmdHdlrGetWord, 1 },
+ { "driverdirectory", eCmdHdlrGetWord, 0 },
+ { "driver", eCmdHdlrGetWord, 1 },
+ { "template", eCmdHdlrGetWord, 0 }
+};
+static struct cnfparamblk actpblk =
+ { CNFPARAMBLK_VERSION,
+ sizeof(actpdescr)/sizeof(struct cnfparamdescr),
+ actpdescr
+ };
+
+
BEGINinitConfVars /* (re)set config variables to default values */
CODESTARTinitConfVars
cs.dbiDrvrDir = NULL;
@@ -124,6 +144,7 @@ static void closeConn(instanceData *pData)
BEGINfreeInstance
CODESTARTfreeInstance
closeConn(pData);
+ free(pData->dbiDrvrDir);
free(pData->drvrName);
free(pData->host);
free(pData->usrName);
@@ -184,9 +205,9 @@ static rsRetVal initConn(instanceData *pData, int bSilent)
if(bDbiInitialized == 0) {
/* we need to init libdbi first */
# ifdef HAVE_DBI_R
- iDrvrsLoaded = dbi_initialize_r((char*) cs.dbiDrvrDir, &dbiInst);
+ iDrvrsLoaded = dbi_initialize_r((char*) pData->dbiDrvrDir, &dbiInst);
# else
- iDrvrsLoaded = dbi_initialize((char*) cs.dbiDrvrDir);
+ iDrvrsLoaded = dbi_initialize((char*) pData->dbiDrvrDir);
# endif
if(iDrvrsLoaded == 0) {
errmsg.LogError(0, RS_RET_SUSPENDED, "libdbi error: libdbi or libdbi drivers not present on this system - suspending.");
@@ -281,6 +302,62 @@ CODESTARTdoAction
ENDdoAction
+static inline void
+setInstParamDefaults(instanceData *pData)
+{
+ pData->tplName = NULL;
+}
+
+
+BEGINnewActInst
+ struct cnfparamvals *pvals;
+ int i;
+CODESTARTnewActInst
+ if((pvals = nvlstGetParams(lst, &actpblk, NULL)) == NULL) {
+ ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
+ }
+
+ CHKiRet(createInstance(&pData));
+ setInstParamDefaults(pData);
+
+ CODE_STD_STRING_REQUESTparseSelectorAct(1)
+ for(i = 0 ; i < actpblk.nParams ; ++i) {
+ if(!pvals[i].bUsed)
+ continue;
+ if(!strcmp(actpblk.descr[i].name, "server")) {
+ pData->host = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else if(!strcmp(actpblk.descr[i].name, "db")) {
+ pData->dbName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else if(!strcmp(actpblk.descr[i].name, "uid")) {
+ pData->usrName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else if(!strcmp(actpblk.descr[i].name, "pwd")) {
+ pData->pwd = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else if(!strcmp(actpblk.descr[i].name, "driverdirectory")) {
+ pData->dbiDrvrDir = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else if(!strcmp(actpblk.descr[i].name, "driver")) {
+ pData->drvrName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else if(!strcmp(actpblk.descr[i].name, "template")) {
+ pData->tplName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else {
+ dbgprintf("ommysql: program error, non-handled "
+ "param '%s'\n", actpblk.descr[i].name);
+ }
+ }
+
+ if(pData->tplName == NULL) {
+ CHKiRet(OMSRsetEntry(*ppOMSR, 0, (uchar*) strdup(" StdDBFmt"),
+ OMSR_RQD_TPL_OPT_SQL));
+ } else {
+ CHKiRet(OMSRsetEntry(*ppOMSR, 0,
+ (uchar*) strdup((char*) pData->tplName),
+ OMSR_RQD_TPL_OPT_SQL));
+ }
+CODE_STD_FINALIZERnewActInst
+dbgprintf("XXXX: added param, iRet %d\n", iRet);
+ cnfparamvalsDestruct(pvals, &actpblk);
+ENDnewActInst
+
+
BEGINparseSelectorAct
CODESTARTparseSelectorAct
CODE_STD_STRING_REQUESTparseSelectorAct(1)
@@ -311,6 +388,8 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1)
if((pData->dbName = (uchar*) strdup((char*)cs.dbName)) == NULL) ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
if(cs.pwd != NULL)
if((pData->pwd = (uchar*) strdup((char*)cs.pwd)) == NULL) ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+ if(cs.dbiDrvrDir != NULL)
+ if((pData->dbiDrvrDir = (uchar*) strdup((char*)cs.dbiDrvrDir)) == NULL) ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
CHKiRet(cflineParseTemplateName(&p, *ppOMSR, 0, OMSR_RQD_TPL_OPT_SQL, (uchar*) " StdDBFmt"));
@@ -334,6 +413,7 @@ ENDmodExit
BEGINqueryEtryPt
CODESTARTqueryEtryPt
CODEqueryEtryPt_STD_OMOD_QUERIES
+CODEqueryEtryPt_STD_CONF2_OMOD_QUERIES
ENDqueryEtryPt