summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--doc/impstats.html4
-rw-r--r--plugins/impstats/impstats.c7
-rw-r--r--runtime/statsobj.c11
-rw-r--r--runtime/statsobj.h14
5 files changed, 32 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 8ac3f62c..4e2d0468 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
---------------------------------------------------------------------------
Version 6.3.8 [DEVEL] 2012-02-??
+- added $PStatsJSON directive to permit stats records in JSON format
- added "date-unixtimestamp" property replacer option to format as a
unix timestamp (seconds since epoch)
- added "json" property replacer option to support JSON encoding on a
diff --git a/doc/impstats.html b/doc/impstats.html
index 260c1aa4..64b04a30 100644
--- a/doc/impstats.html
+++ b/doc/impstats.html
@@ -36,6 +36,10 @@ is 5 (syslog).This is useful for filtering messages.</li>
<li>$PStatSeverity &lt;numerical severity&gt;<br>
The numerical syslog severity code to be used for generated messages. Default
is 6 (info).This is useful for filtering messages.</li>
+<li>$PStatJSON &lt;on/<b>off</b>&gt; (rsyslog v6.3.8+ only)<br>
+If set to on, stats messages are emitted as structured cee-enhanced syslog. If
+set to off, legacy format is used (which is compatible with pre v6-rsyslog).
+</li>
</ul>
<b>Caveats/Known Bugs:</b>
<ul>
diff --git a/plugins/impstats/impstats.c b/plugins/impstats/impstats.c
index 66c5fee6..dfca25da 100644
--- a/plugins/impstats/impstats.c
+++ b/plugins/impstats/impstats.c
@@ -58,6 +58,7 @@ typedef struct configSettings_s {
int iStatsInterval;
int iFacility;
int iSeverity;
+ int bJSON;
} configSettings_t;
struct modConfData_s {
@@ -65,6 +66,7 @@ struct modConfData_s {
int iStatsInterval;
int iFacility;
int iSeverity;
+ statsFmtType_t statsFmt;
};
static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */
static modConfData_t *runModConf = NULL;/* modConf ptr to use for the current load process */
@@ -87,6 +89,7 @@ initConfigSettings(void)
cs.iStatsInterval = DEFAULT_STATS_PERIOD;
cs.iFacility = DEFAULT_FACILITY;
cs.iSeverity = DEFAULT_SEVERITY;
+ cs.bJSON = 0;
}
@@ -136,7 +139,7 @@ doStatsLine(void __attribute__((unused)) *usrptr, cstr_t *cstr)
static inline void
generateStatsMsgs(void)
{
- statsobj.GetAllStatsLines(doStatsLine, NULL);
+ statsobj.GetAllStatsLines(doStatsLine, NULL, runModConf->statsFmt);
}
@@ -155,6 +158,7 @@ CODESTARTendCnfLoad
loadModConf->iStatsInterval = cs.iStatsInterval;
loadModConf->iFacility = cs.iFacility;
loadModConf->iSeverity = cs.iSeverity;
+ loadModConf->statsFmt = cs.bJSON ? statsFmt_JSON : statsFmt_Legacy;
ENDendCnfLoad
@@ -256,6 +260,7 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatinterval", 0, eCmdHdlrInt, NULL, &cs.iStatsInterval, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatfacility", 0, eCmdHdlrInt, NULL, &cs.iFacility, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatseverity", 0, eCmdHdlrInt, NULL, &cs.iSeverity, STD_LOADABLE_MODULE_ID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatjson", 0, eCmdHdlrBinary, NULL, &cs.bJSON, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
CHKiRet(prop.Construct(&pInputName));
diff --git a/runtime/statsobj.c b/runtime/statsobj.c
index 9169d7db..a21614f6 100644
--- a/runtime/statsobj.c
+++ b/runtime/statsobj.c
@@ -262,14 +262,21 @@ finalize_it:
* line. If the callback reports an error, processing is stopped.
*/
static rsRetVal
-getAllStatsLines(rsRetVal(*cb)(void*, cstr_t*), void *usrptr)
+getAllStatsLines(rsRetVal(*cb)(void*, cstr_t*), void *usrptr, statsFmtType_t fmt)
{
statsobj_t *o;
cstr_t *cstr;
DEFiRet;
for(o = objRoot ; o != NULL ; o = o->next) {
- CHKiRet(getStatsLine(o, &cstr));
+ switch(fmt) {
+ case statsFmt_Legacy:
+ CHKiRet(getStatsLine(o, &cstr));
+ break;
+ case statsFmt_JSON:
+ CHKiRet(getStatsLineCEE(o, &cstr));
+ break;
+ }
CHKiRet(cb(usrptr, cstr));
rsCStrDestruct(&cstr);
}
diff --git a/runtime/statsobj.h b/runtime/statsobj.h
index 90279883..f7de68ee 100644
--- a/runtime/statsobj.h
+++ b/runtime/statsobj.h
@@ -43,6 +43,12 @@ typedef enum statsCtrType_e {
ctrType_Int
} statsCtrType_t;
+/* stats line format types */
+typedef enum statsFmtType_e {
+ statsFmt_Legacy,
+ statsFmt_JSON
+} statsFmtType_t;
+
/* helper entity, the counter */
typedef struct ctr_s {
@@ -76,11 +82,15 @@ BEGINinterface(statsobj) /* name must also be changed in ENDinterface macro! */
rsRetVal (*Destruct)(statsobj_t **ppThis);
rsRetVal (*SetName)(statsobj_t *pThis, uchar *name);
rsRetVal (*GetStatsLine)(statsobj_t *pThis, cstr_t **ppcstr);
- rsRetVal (*GetAllStatsLines)(rsRetVal(*cb)(void*, cstr_t*), void *usrptr);
+ rsRetVal (*GetAllStatsLines)(rsRetVal(*cb)(void*, cstr_t*), void *usrptr, statsFmtType_t fmt);
rsRetVal (*AddCounter)(statsobj_t *pThis, uchar *ctrName, statsCtrType_t ctrType, void *pCtr);
rsRetVal (*EnableStats)(void);
ENDinterface(statsobj)
-#define statsobjCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
+#define statsobjCURR_IF_VERSION 10 /* increment whenever you change the interface structure! */
+/* Changes
+ * v2-v9 rserved for future use in "older" version branches
+ * v10, 2012-04-01: GetAllStatsLines got fmt parameter
+ */
/* prototypes */