|
|
af6c5a |
diff -up ./plugins/imjournal/imjournal.c.default_tag ./plugins/imjournal/imjournal.c
|
|
|
af6c5a |
--- ./plugins/imjournal/imjournal.c.default_tag 2017-01-10 04:00:04.000000000 -0500
|
|
|
af6c5a |
+++ ./plugins/imjournal/imjournal.c 2017-08-28 07:55:19.545930923 -0400
|
|
|
af6c5a |
@@ -78,6 +78,7 @@ static struct configSettings_s {
|
|
|
fffb44 |
int iDfltSeverity;
|
|
|
fffb44 |
int iDfltFacility;
|
|
|
a856a8 |
int bUseJnlPID;
|
|
|
fffb44 |
+ char *dfltTag;
|
|
|
fffb44 |
} cs;
|
|
|
fffb44 |
|
|
|
fffb44 |
static rsRetVal facilityHdlr(uchar **pp, void *pVal);
|
|
|
af6c5a |
@@ -93,6 +94,7 @@ static struct cnfparamdescr modpdescr[]
|
|
|
fffb44 |
{ "defaultseverity", eCmdHdlrSeverity, 0 },
|
|
|
a856a8 |
{ "defaultfacility", eCmdHdlrString, 0 },
|
|
|
a856a8 |
{ "usepidfromsystem", eCmdHdlrBinary, 0 },
|
|
|
fffb44 |
+ { "defaulttag", eCmdHdlrGetWord, 0 },
|
|
|
fffb44 |
};
|
|
|
fffb44 |
static struct cnfparamblk modpblk =
|
|
|
fffb44 |
{ CNFPARAMBLK_VERSION,
|
|
|
af6c5a |
@@ -103,6 +105,7 @@ static struct cnfparamblk modpblk =
|
|
|
fffb44 |
#define DFLT_persiststateinterval 10
|
|
|
a856a8 |
#define DFLT_SEVERITY pri2sev(LOG_NOTICE)
|
|
|
a856a8 |
#define DFLT_FACILITY pri2fac(LOG_USER)
|
|
|
fffb44 |
+#define DFLT_TAG "journal"
|
|
|
fffb44 |
|
|
|
fffb44 |
static int bLegacyCnfModGlobalsPermitted = 1;/* are legacy module-global config parameters permitted? */
|
|
|
fffb44 |
|
|
|
af6c5a |
@@ -194,8 +197,13 @@ enqMsg(uchar *msg, uchar *pszTag, int iF
|
|
|
fffb44 |
}
|
|
|
fffb44 |
MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY);
|
|
|
fffb44 |
MsgSetInputName(pMsg, pInputName);
|
|
|
fffb44 |
+ /* Recalculating the message length shouldn't cause problems as all
|
|
|
a856a8 |
+ * potential zero-bytes have been excaped in sanitizeValue(). */
|
|
|
fffb44 |
len = strlen((char*)msg);
|
|
|
fffb44 |
MsgSetRawMsg(pMsg, (char*)msg, len);
|
|
|
fffb44 |
+ /* NB: SanitizeMsg() only touches the raw message and its
|
|
|
a856a8 |
+ * length which only contain the msg part. Thus the TAG and
|
|
|
a856a8 |
+ * other fields are not sanitized. */
|
|
|
fffb44 |
if(len > 0)
|
|
|
fffb44 |
parser.SanitizeMsg(pMsg);
|
|
|
fffb44 |
MsgSetMSGoffs(pMsg, 0); /* we do not have a header... */
|
|
|
af6c5a |
@@ -233,7 +241,7 @@ readjournal(void)
|
|
|
fffb44 |
|
|
|
fffb44 |
/* Information from messages */
|
|
|
fffb44 |
char *message = NULL;
|
|
|
fffb44 |
- char *sys_iden;
|
|
|
fffb44 |
+ char *sys_iden = NULL;
|
|
|
fffb44 |
char *sys_iden_help = NULL;
|
|
|
fffb44 |
|
|
|
fffb44 |
const void *get;
|
|
|
af6c5a |
@@ -294,29 +302,34 @@ readjournal(void)
|
|
|
fffb44 |
/* Get message identifier, client pid and add ':' */
|
|
|
fffb44 |
if (sd_journal_get_data(j, "SYSLOG_IDENTIFIER", &get, &length) >= 0) {
|
|
|
fffb44 |
CHKiRet(sanitizeValue(((const char *)get) + 18, length - 18, &sys_iden));
|
|
|
fffb44 |
- } else {
|
|
|
fffb44 |
- CHKmalloc(sys_iden = strdup("journal"));
|
|
|
fffb44 |
}
|
|
|
fffb44 |
|
|
|
a856a8 |
- if (sd_journal_get_data(j, pid_field_name, &pidget, &pidlength) >= 0) {
|
|
|
fffb44 |
- char *sys_pid;
|
|
|
a856a8 |
- int val_ofs;
|
|
|
a856a8 |
-
|
|
|
a856a8 |
- val_ofs = strlen(pid_field_name) + 1; /* name + '=' */
|
|
|
a856a8 |
- CHKiRet_Hdlr(sanitizeValue(((const char *)pidget) + val_ofs, pidlength - val_ofs, &sys_pid)) {
|
|
|
fffb44 |
- free (sys_iden);
|
|
|
fffb44 |
- FINALIZE;
|
|
|
a856a8 |
+ if (sys_iden == NULL && !cs.dfltTag[0]) {
|
|
|
a856a8 |
+ /* This is a special case: if no tag was obtained from
|
|
|
a856a8 |
+ * the message and the user has set the default tag to
|
|
|
a856a8 |
+ * an empty string, nothing is inserted.
|
|
|
a856a8 |
+ */
|
|
|
a856a8 |
+ CHKmalloc(sys_iden_help = calloc(1, 1));
|
|
|
a856a8 |
+ } else {
|
|
|
a856a8 |
+ if (sys_iden == NULL) {
|
|
|
a856a8 |
+ /* Use a predefined tag if it can't be obtained from the message */
|
|
|
a856a8 |
+ CHKmalloc(sys_iden = strdup(cs.dfltTag));
|
|
|
a856a8 |
+ }
|
|
|
a856a8 |
+ if (sd_journal_get_data(j, "SYSLOG_PID", &pidget, &pidlength) >= 0) {
|
|
|
a856a8 |
+ char *sys_pid;
|
|
|
a856a8 |
+ CHKiRet_Hdlr(sanitizeValue(((const char *)pidget) + 11, pidlength - 11, &sys_pid)) {
|
|
|
a856a8 |
+ free (sys_iden);
|
|
|
a856a8 |
+ FINALIZE;
|
|
|
a856a8 |
+ }
|
|
|
a856a8 |
+ r = asprintf(&sys_iden_help, "%s[%s]:", sys_iden, sys_pid);
|
|
|
a856a8 |
+ free (sys_pid);
|
|
|
a856a8 |
+ } else {
|
|
|
a856a8 |
+ r = asprintf(&sys_iden_help, "%s:", sys_iden);
|
|
|
a856a8 |
+ }
|
|
|
a856a8 |
+ free (sys_iden);
|
|
|
a856a8 |
+ if (-1 == r) {
|
|
|
a856a8 |
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
|
|
|
fffb44 |
}
|
|
|
fffb44 |
- r = asprintf(&sys_iden_help, "%s[%s]:", sys_iden, sys_pid);
|
|
|
fffb44 |
- free (sys_pid);
|
|
|
fffb44 |
- } else {
|
|
|
fffb44 |
- r = asprintf(&sys_iden_help, "%s:", sys_iden);
|
|
|
fffb44 |
- }
|
|
|
a856a8 |
-
|
|
|
fffb44 |
- free (sys_iden);
|
|
|
a856a8 |
-
|
|
|
fffb44 |
- if (-1 == r) {
|
|
|
fffb44 |
- ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
|
|
|
fffb44 |
}
|
|
|
fffb44 |
|
|
|
fffb44 |
json = json_object_new_object();
|
|
|
af6c5a |
@@ -585,6 +598,10 @@ CODESTARTrunInput
|
|
|
af6c5a |
pid_field_name = "SYSLOG_PID";
|
|
|
af6c5a |
}
|
|
|
af6c5a |
|
|
|
af6c5a |
+ if (cs.dfltTag == NULL) {
|
|
|
af6c5a |
+ cs.dfltTag = strdup(DFLT_TAG);
|
|
|
af6c5a |
+ }
|
|
|
af6c5a |
+
|
|
|
af6c5a |
/* this is an endless loop - it is terminated when the thread is
|
|
|
af6c5a |
* signalled to do so. This, however, is handled by the framework.
|
|
|
af6c5a |
*/
|
|
|
af6c5a |
@@ -633,6 +650,7 @@ CODESTARTbeginCnfLoad
|
|
|
fffb44 |
cs.ratelimitInterval = 600;
|
|
|
fffb44 |
cs.iDfltSeverity = DFLT_SEVERITY;
|
|
|
fffb44 |
cs.iDfltFacility = DFLT_FACILITY;
|
|
|
fffb44 |
+ cs.dfltTag = NULL;
|
|
|
a856a8 |
cs.bUseJnlPID = 0;
|
|
|
fffb44 |
ENDbeginCnfLoad
|
|
|
fffb44 |
|
|
|
af6c5a |
@@ -655,6 +673,7 @@ ENDactivateCnf
|
|
|
fffb44 |
BEGINfreeCnf
|
|
|
fffb44 |
CODESTARTfreeCnf
|
|
|
a856a8 |
free(cs.stateFile);
|
|
|
fffb44 |
+ free(cs.dfltTag);
|
|
|
fffb44 |
ENDfreeCnf
|
|
|
fffb44 |
|
|
|
fffb44 |
/* open journal */
|
|
|
af6c5a |
@@ -739,6 +758,8 @@ CODESTARTsetModCnf
|
|
|
fffb44 |
free(fac);
|
|
|
a856a8 |
} else if (!strcmp(modpblk.descr[i].name, "usepidfromsystem")) {
|
|
|
a856a8 |
cs.bUseJnlPID = (int) pvals[i].val.d.n;
|
|
|
fffb44 |
+ } else if (!strcmp(modpblk.descr[i].name, "defaulttag")) {
|
|
|
fffb44 |
+ cs.dfltTag = (char *)es_str2cstr(pvals[i].val.d.estr, NULL);
|
|
|
fffb44 |
} else {
|
|
|
fffb44 |
dbgprintf("imjournal: program error, non-handled "
|
|
|
fffb44 |
"param '%s' in beginCnfLoad\n", modpblk.descr[i].name);
|
|
|
af6c5a |
@@ -799,6 +820,8 @@ CODEmodInit_QueryRegCFSLineHdlr
|
|
|
fffb44 |
facilityHdlr, &cs.iDfltFacility, STD_LOADABLE_MODULE_ID));
|
|
|
a856a8 |
CHKiRet(omsdRegCFSLineHdlr((uchar *)"imjournalusepidfromsystem", 0, eCmdHdlrBinary,
|
|
|
a856a8 |
NULL, &cs.bUseJnlPID, STD_LOADABLE_MODULE_ID));
|
|
|
fffb44 |
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"imjournaldefaulttag", 0, eCmdHdlrGetWord,
|
|
|
fffb44 |
+ NULL, &cs.dfltTag, STD_LOADABLE_MODULE_ID));
|
|
|
fffb44 |
ENDmodInit
|
|
|
fffb44 |
/* vim:set ai:
|
|
|
fffb44 |
*/
|