summaryrefslogtreecommitdiffstats
path: root/syslogd.c
diff options
context:
space:
mode:
authorMichael Meckelein <mmeckelein@hq.adiscon.com>2004-11-18 15:38:15 +0000
committerMichael Meckelein <mmeckelein@hq.adiscon.com>2004-11-18 15:38:15 +0000
commit9b85e5147b9016f9a91fe8b716e5f07d8d913ce1 (patch)
treeefefa388140bcc8a383f50f1d18a6eef040df0b2 /syslogd.c
parentfb5606f892184461ba22c030090ec94913e4aeb1 (diff)
downloadrsyslog-9b85e5147b9016f9a91fe8b716e5f07d8d913ce1.tar.gz
rsyslog-9b85e5147b9016f9a91fe8b716e5f07d8d913ce1.tar.xz
rsyslog-9b85e5147b9016f9a91fe8b716e5f07d8d913ce1.zip
Added Adiscon DB shema in MySQL insert function
Diffstat (limited to 'syslogd.c')
-rw-r--r--syslogd.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/syslogd.c b/syslogd.c
index 595ced88..e4019199 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -579,6 +579,7 @@ static char sccsid[] = "@(#)rsyslogd.c 0.2 (Adiscon) 11/08/2004";
#ifdef WITH_DB
#include "mysql/mysql.h"
+#include "mysql/errmsg.h"
#endif
#if defined(__linux__)
@@ -1167,6 +1168,32 @@ static int srSLMGParseTIMESTAMP3164(struct syslogTime *pTime, unsigned char* psz
* END CODE-LIBLOGGING *
*******************************************************************/
+#ifdef WITH_DB
+/**
+ * Format a syslogTimestamp into format required by MySQL.
+ * We are using the 14 digits format. For example 20041111122600
+ * is interpreted as '2004-11-11 12:26:00'.
+ * The caller must provide the timestamp as well as a character
+ * buffer that will receive the resulting string. The function
+ * returns the size of the timestamp written in bytes (without
+ * the string terminator). If 0 is returend, an error occured.
+ */
+int formatTimestampToMySQL(struct syslogTime *ts, char* pDst, size_t iLenDst)
+{
+ /* TODO: currently we do not consider localtime/utc */
+ assert(ts != NULL);
+ assert(pDst != NULL);
+
+ if (iLenDst < 15) /* we need at least 14 bytes
+ 14 digits for timestamp + '\n' */
+ return(0);
+
+ return(snprintf(pDst, iLenDst, "%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d",
+ ts->year, ts->month, ts->day, ts->hour, ts->minute, ts->second));
+
+}
+#endif
+
/**
* Format a syslogTimestamp to a RFC3164 timestamp sring.
* The caller must provide the timestamp as well as a character
@@ -4052,13 +4079,23 @@ void closeMySQL(register struct filed *f)
void writeMySQL(register struct filed *f)
{
char sql_command[MAXLINE+1048];
+ char szTimestamp[15];
+ char szRcvAtTimestamp[15];
+ formatTimestampToMySQL(&f->f_pMsg->tTIMESTAMP, szTimestamp, sizeof(szTimestamp)/sizeof(char));
+ formatTimestampToMySQL(&f->f_pMsg->tRcvdAt, szRcvAtTimestamp, sizeof(szTimestamp)/sizeof(char));
printf("in writeMySQL()\n");
- /* TODO: Insert useful values */
- snprintf(sql_command, sizeof(sql_command), "INSERT INTO myTable VALUES (1,'test')");
+ snprintf(sql_command, sizeof(sql_command),
+ "INSERT INTO SystemEvents (Message, ReceivedAt, DeviceReportedTime,
+ Facility, Priority, FromHost, SysLogTag)
+ VALUES
+ ('%s', '%s', '%s', %d, %d, '%s', '%s')",
+ f->f_pMsg->pszMSG, szRcvAtTimestamp, szTimestamp,
+ f->f_pMsg->iFacility, f->f_pMsg->iSeverity,
+ f->f_pMsg->pszHOSTNAME, f->f_pMsg->pszTAG);
/* query */
if(mysql_query(&f->f_hmysql, sql_command)) {
- printf("mysql insert failed\n");
+ dprintf("mysql insert failed. ErrNo: %d\n", mysql_errno(&f->f_hmysql));
exit(0);
}
else {