diff options
author | Steven A. Falco <sfalco@coincident.com> | 2012-04-13 15:14:31 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-04-13 15:14:31 +0200 |
commit | d4c048af3e275e90683ae6c49f9c0b2aea9f2f03 (patch) | |
tree | a9677702f852c3efa9c6f0551c96b5822cbe005b /runtime/msg.c | |
parent | 05efee80c1f9ef74b912d12709919153b8d1440a (diff) | |
download | rsyslog-d4c048af3e275e90683ae6c49f9c0b2aea9f2f03.tar.gz rsyslog-d4c048af3e275e90683ae6c49f9c0b2aea9f2f03.tar.xz rsyslog-d4c048af3e275e90683ae6c49f9c0b2aea9f2f03.zip |
Add a system property, PROP_SYS_UPTIME, to place up-time markers into rsyslog output.
Here is an example template, where this is used:
$template CoincidentFileFormat,"[UP=%$uptime%sec] %TIMESTAMP% %HOSTNAME% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
and here is an example line of output using the above template:
[UP=20sec] Apr 12 21:50:00 atom kernel: imklog 5.8.7, log source = /proc/kmsg started.
Diffstat (limited to 'runtime/msg.c')
-rw-r--r-- | runtime/msg.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/runtime/msg.c b/runtime/msg.c index a52d0cce..e1b3b0da 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -36,6 +36,7 @@ #include <assert.h> #include <ctype.h> #include <sys/socket.h> +#include <sys/sysinfo.h> #include <netdb.h> #include <libee/libee.h> #if HAVE_MALLOC_H @@ -568,6 +569,8 @@ rsRetVal propNameToID(cstr_t *pCSPropName, propid_t *pPropID) *pPropID = PROP_CEE; } else if(!strcmp((char*) pName, "$bom")) { *pPropID = PROP_SYS_BOM; + } else if(!strcmp((char*) pName, "$uptime")) { + *pPropID = PROP_SYS_UPTIME; } else { *pPropID = PROP_INVALID; iRet = RS_RET_VAR_NOT_FOUND; @@ -2548,6 +2551,23 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, pRes = (uchar*) "\xEF\xBB\xBF"; *pbMustBeFreed = 0; break; + case PROP_SYS_UPTIME: + { + struct sysinfo s_info; + + if((pRes = (uchar*) MALLOC(sizeof(uchar) * 32)) == NULL) { + RET_OUT_OF_MEMORY; + } + *pbMustBeFreed = 1; + + if(sysinfo(&s_info) < 0) { + *pPropLen = sizeof("**SYSCALL FAILED**") - 1; + return(UCHAR_CONSTANT("**SYSCALL FAILED**")); + } + + snprintf((char*) pRes, sizeof(uchar) * 32, "%ld", s_info.uptime); + } + break; default: /* there is no point in continuing, we may even otherwise render the * error message unreadable. rgerhards, 2007-07-10 |