mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-17 19:50:41 +01:00
upgraded omlibdbi to support the new v6 config format
This commit is contained in:
parent
b467b44dae
commit
8b7924fb8a
@ -1,5 +1,8 @@
|
||||
---------------------------------------------------------------------------
|
||||
Version 6.3.8 [DEVEL] 2012-02-??
|
||||
- upgraded more plugins to support the new v6 config format:
|
||||
- ommysql
|
||||
- omlibdbi
|
||||
- bugfix: abort during startup when rsyslog.conf v6+ format was used in
|
||||
a certain way
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
@ -54,32 +54,38 @@ dlopen()ed plugin (as omlibdbi is). So in short, you probably save you
|
||||
a lot of headache if you make sure you have at least libdbi version
|
||||
0.8.3 on your system.
|
||||
</p>
|
||||
<p><b>Configuration Directives</b>:</p>
|
||||
<p><b>Action Parameters</b>:</p>
|
||||
<ul>
|
||||
<li><span style="font-weight: bold;">$ActionLibdbiDriverDirectory /path/to/dbd/drivers</span><br>This
|
||||
is a global setting. It points libdbi to its driver directory. Usually,
|
||||
you do not need to set it. If you installed libdbi-driver's at a
|
||||
non-standard location, you may need to specify the directory here. If
|
||||
you are unsure, do <span style="font-weight: bold;">not</span> use this configuration directive. Usually, everything works just fine.<strong></strong></li><li><strong>$ActionLibdbiDriver drivername</strong><br>
|
||||
<li><b>server</b><br>Name or address of the MySQL server
|
||||
<li><b>db</b><br>Database to use
|
||||
<li><b>uid</b><br>logon userid used to connect to server. Must have proper permissions.
|
||||
<li><b>pwd</b><br>the user's password
|
||||
<li><b>template</b><br>Template to use when submitting messages.
|
||||
<li><b>driver</b><br>
|
||||
Name of the dbidriver to use, see libdbi-drivers documentation. As a
|
||||
quick excerpt, at least those were available at the time of this
|
||||
writiting "mysql" (suggest to use ommysql instead), "firebird" (Firbird
|
||||
and InterBase), "ingres", "msql", "Oracle", "sqlite", "sqlite3",
|
||||
"freetds" (for Microsoft SQL and Sybase) and "pgsql" (suggest to use
|
||||
ompgsql instead).</li>
|
||||
<li><span style="font-weight: bold;">$ActionLibdbiHost
|
||||
hostname</span><br>
|
||||
<li><b>driverdirectory</b><br>
|
||||
Path to the libdbi drivers. Usually,
|
||||
you do not need to set it. If you installed libdbi-drivers at a
|
||||
non-standard location, you may need to specify the directory here. If
|
||||
you are unsure, do <b>not</b> use this configuration directive.
|
||||
Usually, everything works just fine.</li>
|
||||
</ul>
|
||||
<p><b>Legacy (pre-v6) Configuration Directives</b>:</p>
|
||||
<ul>
|
||||
<li><b>$ActionLibdbiDriverDirectory /path/to/dbd/drivers</b>
|
||||
- like the driverdirectory action parameter.
|
||||
<li><strong>$ActionLibdbiDriver drivername</strong><br> - like the drivername action parameter.
|
||||
<li><span style="font-weight: bold;">$ActionLibdbiHost hostname</span> - like the server action parameter
|
||||
The host to connect to.</li>
|
||||
<li><span style="font-weight: bold;">$ActionLibdbiUserName
|
||||
user</span><br>
|
||||
The user used to connect to the database.</li>
|
||||
<li><span style="font-weight: bold;">$ActionlibdbiPassword</span><br>
|
||||
That user's password.</li>
|
||||
<li><span style="font-weight: bold;">$ActionlibdbiDBName
|
||||
db</span><br>
|
||||
The database that shall be written to.</li>
|
||||
<li><span style="font-weight: bold;">selector
|
||||
line: :omlibdbi:<span style="font-style: italic;">;template</span></span><br>
|
||||
<li><b>$ActionLibdbiUserName user</b> - like the uid action parameter
|
||||
<li><b>$ActionlibdbiPassword</b> - like the pwd action parameter
|
||||
<li><b>$ActionlibdbiDBName db</b> - like the db action parameter
|
||||
<li><b>selector line: :omlibdbi:<i>;template</i></b><br>
|
||||
executes the recently configured omlibdbi action. The ;template part is
|
||||
optional. If no template is provided, a default template is used (which
|
||||
is currently optimized for MySQL - sorry, folks...)</li>
|
||||
@ -108,7 +114,14 @@ database "syslog_db" on mysqlsever.example.com. The server is MySQL and
|
||||
being accessed under the account of "user" with password "pwd" (if you
|
||||
have empty passwords, just remove the $ActionLibdbiPassword line).<br>
|
||||
</p>
|
||||
<textarea rows="15" cols="60">$ModLoad omlibdbi
|
||||
<textarea rows="5" cols="60">$ModLoad omlibdbi
|
||||
*.* action(type="omlibdbi" driver="mysql"
|
||||
server="mysqlserver.example.com" db="syslog_db"
|
||||
uid="user" pwd="pwd"
|
||||
</textarea>
|
||||
<p><b>Sample:</b></p>
|
||||
<p>The same as above, but in legacy config format (pre rsyslog-v6):
|
||||
<textarea rows="10" cols="60">$ModLoad omlibdbi
|
||||
$ActionLibdbiDriver mysql
|
||||
$ActionLibdbiHost mysqlserver.example.com
|
||||
$ActionLibdbiUserName user
|
||||
@ -121,8 +134,7 @@ $ActionLibdbiDBName syslog_db
|
||||
<p><font size="2">This documentation is part of the
|
||||
<a href="http://www.rsyslog.com/">rsyslog</a>
|
||||
project.<br>
|
||||
Copyright © 2008 by <a href="http://www.gerhards.net/rainer">Rainer
|
||||
Gerhards</a> and
|
||||
Copyright © 2008-2012 by <a href="http://www.gerhards.net/rainer">Rainer Gerhards</a> and
|
||||
<a href="http://www.adiscon.com/">Adiscon</a>.
|
||||
Released under the GNU GPL version 3 or higher.</font></p>
|
||||
Released under the ASL 2.0.</font></p>
|
||||
</body></html>
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user