summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--configure.ac41
-rw-r--r--msg.c26
-rw-r--r--msg.h2
-rw-r--r--syslogd.c16
-rw-r--r--syslogd.h1
-rw-r--r--template.c5
-rw-r--r--template.h2
8 files changed, 91 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am
index b3bca98c..a7825447 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -83,3 +83,7 @@ SUBDIRS = doc
if ENABLE_MYSQL
SUBDIRS += plugins/ommysql
endif
+
+if ENABLE_PGSQL
+SUBDIRS += plugins/ompgsql
+endif
diff --git a/configure.ac b/configure.ac
index 90d684dd..b4892f68 100644
--- a/configure.ac
+++ b/configure.ac
@@ -262,7 +262,7 @@ fi
-# SQL support
+# MySQL support
AC_ARG_ENABLE(mysql,
[AS_HELP_STRING([--enable-mysql],[Enable MySql database support @<:@default=no@:>@])],
[case "${enableval}" in
@@ -299,10 +299,42 @@ AM_CONDITIONAL(ENABLE_MYSQL, test x$enable_mysql = xyes)
AC_SUBST(mysql_cflags)
AC_SUBST(mysql_libs)
+# PostgreSQL support
+AC_ARG_ENABLE(pgsql,
+ [AS_HELP_STRING([--enable-pgsql],[Enable PostgreSQL database support @<:@default=no@:>@])],
+ [case "${enableval}" in
+ yes) enable_pgsql="yes" ;;
+ no) enable_pgsql="no" ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-pgsql) ;;
+ esac],
+ [enable_pgsql=no]
+)
+if test "x$enable_pgsql" = "xyes"; then
+ AC_CHECK_PROG(
+ [HAVE_PGSQL_CONFIG],
+ [pg_config],
+ [yes],,,
+ )
+ if test "x${HAVE_PGSQL_CONFIG}" != "xyes"; then
+ AC_MSG_FAILURE([pg_config not found in PATH])
+ fi
+ AC_CHECK_LIB(
+ [pq],
+ [PQconnectdb],
+ [pgsql_cflags="-I`pg_config --includedir`"
+ pgsql_libs="`pg_config --libdir` -lpq"
+ ],
+ [AC_MSG_FAILURE([PgSQL library is missing])],
+ [-L`pg_config --libdir`]
+ )
+fi
+AM_CONDITIONAL(ENABLE_PGSQL, test x$enable_pgsql = xyes)
+AC_SUBST(pgsql_cflags)
+AC_SUBST(pgsql_libs)
-AC_CONFIG_FILES([Makefile doc/Makefile plugins/ommysql/Makefile])
+AC_CONFIG_FILES([Makefile doc/Makefile plugins/ommysql/Makefile plugins/ompgsql/Makefile])
AC_OUTPUT
echo "****************************************************"
@@ -311,10 +343,11 @@ echo
echo "Multithreading support enabled: $enable_pthreads"
echo "Klogd functionality enabled: $enable_klogd"
echo "Regular expressions support enabled: $enable_regexp"
-echo "Zlib compression support enabled: $enable_zlib"
+echo "Zlib compression support enabled: $enable_zlib"
echo "MySql support enabled: $enable_mysql"
+echo "PostgreSQL support enabled: $enable_pgsql"
echo "Large file support enabled: $enable_largefile"
echo "Networking support enabled: $enable_inet"
-echo "Enable GSSAPI Kerberos 5 support: $want_gssapi_krb5"
+echo "Enable GSSAPI Kerberos 5 support: $want_gssapi_krb5"
echo "Debug mode enabled: $enable_debug"
diff --git a/msg.c b/msg.c
index 2cfa592d..a2f47975 100644
--- a/msg.c
+++ b/msg.c
@@ -536,6 +536,18 @@ char *getTimeReported(msg_t *pM, enum tplFormatTypes eFmt)
}
MsgUnlock();
return(pM->pszTIMESTAMP_MySQL);
+ case tplFmtPgSQLDate:
+ MsgLock();
+ if(pM->pszTIMESTAMP_PgSQL == NULL) {
+ if((pM->pszTIMESTAMP_PgSQL = malloc(21)) == NULL) {
+ glblHadMemShortage = 1;
+ MsgUnlock();
+ return "";
+ }
+ formatTimestampToPgSQL(&pM->tTIMESTAMP, pM->pszTIMESTAMP_PgSQL, 21);
+ }
+ MsgUnlock();
+ return(pM->pszTIMESTAMP_PgSQL);
case tplFmtRFC3164Date:
MsgLock();
if(pM->pszTIMESTAMP3164 == NULL) {
@@ -554,7 +566,7 @@ char *getTimeReported(msg_t *pM, enum tplFormatTypes eFmt)
if((pM->pszTIMESTAMP3339 = malloc(33)) == NULL) {
glblHadMemShortage = 1;
MsgUnlock();
- return "";
+ return ""; /* TODO: check this: can it cause a free() of constant memory?) */
}
formatTimestamp3339(&pM->tTIMESTAMP, pM->pszTIMESTAMP3339, 33);
}
@@ -594,6 +606,18 @@ char *getTimeGenerated(msg_t *pM, enum tplFormatTypes eFmt)
}
MsgUnlock();
return(pM->pszRcvdAt_MySQL);
+ case tplFmtPgSQLDate:
+ MsgLock();
+ if(pM->pszRcvdAt_PgSQL == NULL) {
+ if((pM->pszRcvdAt_PgSQL = malloc(21)) == NULL) {
+ glblHadMemShortage = 1;
+ MsgUnlock();
+ return "";
+ }
+ formatTimestampToPgSQL(&pM->tRcvdAt, pM->pszRcvdAt_PgSQL, 21);
+ }
+ MsgUnlock();
+ return(pM->pszRcvdAt_PgSQL);
case tplFmtRFC3164Date:
MsgLock();
if(pM->pszRcvdAt3164 == NULL) {
diff --git a/msg.h b/msg.h
index 8f411f77..3ad63b46 100644
--- a/msg.h
+++ b/msg.h
@@ -91,10 +91,12 @@ struct msg {
char *pszRcvdAt3164; /* time as RFC3164 formatted string (always 15 charcters) */
char *pszRcvdAt3339; /* time as RFC3164 formatted string (32 charcters at most) */
char *pszRcvdAt_MySQL; /* rcvdAt as MySQL formatted string (always 14 charcters) */
+ char *pszRcvdAt_PgSQL; /* rcvdAt as PgSQL formatted string (always 21 characters) */
struct syslogTime tTIMESTAMP;/* (parsed) value of the timestamp */
char *pszTIMESTAMP3164; /* TIMESTAMP as RFC3164 formatted string (always 15 charcters) */
char *pszTIMESTAMP3339; /* TIMESTAMP as RFC3339 formatted string (32 charcters at most) */
char *pszTIMESTAMP_MySQL;/* TIMESTAMP as MySQL formatted string (always 14 charcters) */
+ char *pszTIMESTAMP_PgSQL;/* TIMESTAMP as PgSQL formatted string (always 21 characters) */
int msgFlags; /* flags associated with this message */
};
typedef struct msg msg_t; /* new name */
diff --git a/syslogd.c b/syslogd.c
index 7a8ec535..a0c34ab5 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -644,6 +644,7 @@ static uchar template_WallFmt[] = "\"\r\n\7Message from syslogd@%HOSTNAME% at %t
static uchar template_StdFwdFmt[] = "\"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag%%msg%\"";
static uchar template_StdUsrMsgFmt[] = "\" %syslogtag%%msg%\n\r\"";
static uchar template_StdDBFmt[] = "\"insert into SystemEvents (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%, '%HOSTNAME%', %syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')\",SQL";
+static uchar template_StdPgSQLFmt[] = "\"insert into SystemEvents (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%, '%HOSTNAME%', %syslogpriority%, '%timereported:::date-pgsql%', '%timegenerated:::date-pgsql%', %iut%, '%syslogtag%')\",STDSQL";
/* end template */
@@ -1440,6 +1441,19 @@ int formatTimestampToMySQL(struct syslogTime *ts, char* pDst, size_t iLenDst)
}
+int formatTimestampToPgSQL(struct syslogTime *ts, char *pDst, size_t iLenDst)
+{
+ /* see note in formatTimestampToMySQL, applies here as well */
+ assert(ts != NULL);
+ assert(pDst != NULL);
+
+ if (iLenDst < 21) /* we need 20 bytes + '\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));
+}
+
/**
* Format a syslogTimestamp to a RFC3339 timestamp string (as
* specified in syslog-protocol).
@@ -6101,6 +6115,8 @@ static void mainThread()
tplAddLine(" StdUsrMsgFmt", &pTmp);
pTmp = template_StdDBFmt;
tplLastStaticInit(tplAddLine(" StdDBFmt", &pTmp));
+ pTmp = template_StdPgSQLFmt;
+ tplLastStaticInit(tplAddLine(" StdPgSQLFmt", &pTmp));
dbgprintf("Starting.\n");
init();
diff --git a/syslogd.h b/syslogd.h
index 75338e4e..c1d765eb 100644
--- a/syslogd.h
+++ b/syslogd.h
@@ -59,6 +59,7 @@ void freeAllSockets(int **socks);
int isAllowedSender(struct AllowedSenders *pAllowRoot, struct sockaddr *pFrom, const char *pszFromHost);
void getCurrTime(struct syslogTime *t);
int formatTimestampToMySQL(struct syslogTime *ts, char* pDst, size_t iLenDst);
+int formatTimestampToPgSQL(struct syslogTime *ts, char* pDst, size_t iLenDst);
int formatTimestamp3339(struct syslogTime *ts, char* pBuf, size_t iLenBuf);
int formatTimestamp3164(struct syslogTime *ts, char* pBuf, size_t iLenBuf);
void untty(void);
diff --git a/template.c b/template.c
index 59e74844..048d9314 100644
--- a/template.c
+++ b/template.c
@@ -424,6 +424,8 @@ static void doOptions(unsigned char **pp, struct templateEntry *pTpe)
*/
if(!strcmp((char*)Buf, "date-mysql")) {
pTpe->data.field.eDateFormat = tplFmtMySQLDate;
+ } else if(!strcmp((char*)Buf, "date-pgsql")) {
+ pTpe->data.field.eDateFormat = tplFmtPgSQLDate;
} else if(!strcmp((char*)Buf, "date-rfc3164")) {
pTpe->data.field.eDateFormat = tplFmtRFC3164Date;
} else if(!strcmp((char*)Buf, "date-rfc3339")) {
@@ -941,6 +943,9 @@ void tplPrintList(void)
case tplFmtMySQLDate:
dbgprintf("[Format as MySQL-Date] ");
break;
+ case tplFmtPgSQLDate:
+ dbgprintf("[Format as PgSQL-Date] ");
+ break;
case tplFmtRFC3164Date:
dbgprintf("[Format as RFC3164-Date] ");
break;
diff --git a/template.h b/template.h
index e099e58a..c5ea8c48 100644
--- a/template.h
+++ b/template.h
@@ -34,7 +34,7 @@ struct template {
enum EntryTypes { UNDEFINED = 0, CONSTANT = 1, FIELD = 2 };
enum tplFormatTypes { tplFmtDefault = 0, tplFmtMySQLDate = 1,
- tplFmtRFC3164Date = 2, tplFmtRFC3339Date = 3 };
+ tplFmtRFC3164Date = 2, tplFmtRFC3339Date = 3, tplFmtPgSQLDate = 4 };
enum tplFormatCaseConvTypes { tplCaseConvNo = 0, tplCaseConvUpper = 1, tplCaseConvLower = 2 };
#include "msg.h"