[syslog-ng][PATCH] Unixtime (again)

Gert Menke gert@menke.za.net
Wed, 10 Apr 2002 14:29:10 +0200


--k+w/mQv8wyuph6w0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi!

Here's my Unixtime-Patch again, this time against syslog-ng-1.5.15.

Balazs, I understand that you don't have much time, but please tell me what
you think of it and if you will include it in 1.5.16, or why you won't.

Also, I would like to have an option do define one or more default
templates, perhaps like this:
  template t_unixtime { "$S_UNIXTIME $R_UNIXTIME $SOURCEIP $HOST $MSG\n" };
  template t_isotime { "$S_ISOTIME $R_ISOTIME $SOURCEIP $HOST $MSG\n" };
  destination d_foo { file("foo.log"); template(t_unixtime); };
  destination d_bar { file("bar.log"); template(t_unixtime); };
  destination d_human-readable { file("human-readable.log"); template(t_isotime); };

How can I do this? Could you help me implementing it?

Greetings
Gert

--k+w/mQv8wyuph6w0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="syslog-ng-1.5.15-unixtime.patch"

diff -u3 -r syslog-ng-1.5.15-orig/src/affile.c syslog-ng-1.5.15-p01-unixtime/src/affile.c
--- syslog-ng-1.5.15-orig/src/affile.c	Wed Feb  6 16:20:39 2002
+++ syslog-ng-1.5.15-p01-unixtime/src/affile.c	Wed Apr 10 14:08:11 2002
@@ -468,36 +468,39 @@
 #define M_MIN      10
 #define M_SEC      11
 #define M_WEEKDAY  12
+#define M_UNIXTIME 13
 
-#define M_DATE_RECVD     13
-#define M_FULLDATE_RECVD 14
-#define M_ISODATE_RECVD  15
-#define M_YEAR_RECVD     16
-#define M_MONTH_RECVD    17
-#define M_DAY_RECVD      18
-#define M_HOUR_RECVD     19
-#define M_MIN_RECVD      20
-#define M_SEC_RECVD      21
-#define M_WEEKDAY_RECVD  22
-
-#define M_DATE_STAMP     23
-#define M_FULLDATE_STAMP 24
-#define M_ISODATE_STAMP  25
-#define M_YEAR_STAMP     26
-#define M_MONTH_STAMP    27
-#define M_DAY_STAMP      28
-#define M_HOUR_STAMP     29
-#define M_MIN_STAMP      30
-#define M_SEC_STAMP      31
-#define M_WEEKDAY_STAMP  32
-
-#define M_FULLHOST 33
-#define M_HOST     34
-#define M_PROGRAM  35
+#define M_DATE_RECVD     14
+#define M_FULLDATE_RECVD 15
+#define M_ISODATE_RECVD  16
+#define M_YEAR_RECVD     17
+#define M_MONTH_RECVD    18
+#define M_DAY_RECVD      19
+#define M_HOUR_RECVD     20
+#define M_MIN_RECVD      21
+#define M_SEC_RECVD      22
+#define M_WEEKDAY_RECVD  23
+#define M_UNIXTIME_RECVD 24
+
+#define M_DATE_STAMP     25
+#define M_FULLDATE_STAMP 26
+#define M_ISODATE_STAMP  27
+#define M_YEAR_STAMP     28
+#define M_MONTH_STAMP    29
+#define M_DAY_STAMP      30
+#define M_HOUR_STAMP     31
+#define M_MIN_STAMP      32
+#define M_SEC_STAMP      33
+#define M_WEEKDAY_STAMP  34
+#define M_UNIXTIME_STAMP 35
+
+#define M_FULLHOST 36
+#define M_HOST     37
+#define M_PROGRAM  38
 
-#define M_MESSAGE  36
+#define M_MESSAGE  39
 
-#define M_SOURCE_IP 37
+#define M_SOURCE_IP 40
 
 int append_string(char **dest, int *left, char *str, int length, int escape)
 {
@@ -617,6 +620,7 @@
 	case M_HOUR_RECVD:
 	case M_MIN_RECVD:
 	case M_SEC_RECVD:
+	case M_UNIXTIME_RECVD:
 
 	case M_FULLDATE_STAMP:
 	case M_ISODATE_STAMP:
@@ -628,6 +632,7 @@
 	case M_HOUR_STAMP:
 	case M_MIN_STAMP:
 	case M_SEC_STAMP:
+	case M_UNIXTIME_STAMP:
 
 	case M_FULLDATE:
 	case M_ISODATE:
@@ -638,9 +643,11 @@
 	case M_DAY: 
 	case M_HOUR:
 	case M_MIN:
-	case M_SEC: {
+	case M_SEC:
+	case M_UNIXTIME: {
 		/* year, month, day */
 		struct tm *tm;
+		time_t unixtime;
 
 	       	switch(id) {
 	       	case M_FULLDATE_RECVD:
@@ -653,7 +660,8 @@
 	       	case M_HOUR_RECVD:    
 	       	case M_MIN_RECVD:     
 	       	case M_SEC_RECVD:     
-			tm = localtime(&msg->recvd);
+	       	case M_UNIXTIME_RECVD:     
+			unixtime = msg->recvd;
 			break;
 		case M_FULLDATE_STAMP:
 		case M_ISODATE_STAMP: 
@@ -665,16 +673,19 @@
 		case M_HOUR_STAMP:    
 		case M_MIN_STAMP:     
 		case M_SEC_STAMP:     
-			tm = localtime(&msg->stamp);
+		case M_UNIXTIME_STAMP:     
+			unixtime = msg->stamp;
 	                break;
 		default:
  		        if (cfg->use_time_recvd)
- 		                tm = localtime(&msg->recvd);
+				unixtime = msg->recvd;
  		        else
- 		            	tm = localtime(&msg->stamp);
+				unixtime = msg->stamp;
  		        break;
 		}
 		
+		tm = localtime(&unixtime);
+
 		switch (id) {
 		case M_WEEKDAY:
  	        case M_WEEKDAY_RECVD:
@@ -726,6 +737,11 @@
  	        case M_DATE_STAMP:
 	                length = strftime(*dest, *left - 1, "%h %e %H:%M:%S", tm);
 	                break;
+	        case M_UNIXTIME:
+ 	        case M_UNIXTIME_RECVD:
+ 	        case M_UNIXTIME_STAMP:
+			length = snprintf(*dest, *left, "%d", unixtime);
+	                break;
 		}
 		break;
 	}
@@ -760,6 +776,7 @@
 		{ "MIN", M_MIN },
 		{ "SEC", M_SEC },
 		{ "WEEKDAY", M_WEEKDAY },
+		{ "UNIXTIME", M_UNIXTIME },
 
  		{ "R_DATE", M_DATE_RECVD },
  		{ "R_FULLDATE", M_FULLDATE_RECVD },
@@ -771,6 +788,7 @@
  		{ "R_MIN", M_MIN_RECVD },
  		{ "R_SEC", M_SEC_RECVD },
  		{ "R_WEEKDAY", M_WEEKDAY_RECVD },
+		{ "R_UNIXTIME", M_UNIXTIME_RECVD },
  
  		{ "S_DATE", M_DATE_STAMP },
  		{ "S_FULLDATE", M_FULLDATE_STAMP },
@@ -782,6 +800,7 @@
  		{ "S_MIN", M_MIN_STAMP },
  		{ "S_SEC", M_SEC_STAMP },
  		{ "S_WEEKDAY", M_WEEKDAY_STAMP },
+ 		{ "S_UNIXTIME", M_UNIXTIME_STAMP },
 		
 		{ "HOST", M_HOST },
 		{ "FULLHOST", M_FULLHOST },

--k+w/mQv8wyuph6w0--