From d4c048af3e275e90683ae6c49f9c0b2aea9f2f03 Mon Sep 17 00:00:00 2001 From: "Steven A. Falco" Date: Fri, 13 Apr 2012 15:14:31 +0200 Subject: 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. --- runtime/msg.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'runtime/msg.c') 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 #include #include +#include #include #include #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 -- cgit