[syslog-ng] setting facility/level of source log messages ?

Xavier Lapie bana at docisland.org
Tue Mar 3 16:02:53 CET 2009


On Mon, Mar 02, 2009 at 03:25:53PM +0100, Balazs Scheidler wrote:
> In 3.0 OSE there are options to set these for file sources, but no options to set 
> them for no-parse sources. I'll take care about this when I get there, but please file
> a bugzilla ticket.
> 
> Alternatively you could submit your patches, that could potentially solve this 
> problem faster.

Hi,

The patch is attached to this mail, and adds two new options for source files
in the syslog-ng configuration file:

fake_facility(facility) and fake_level(level)
These options don't have any effect when used without the no-parse flag.

Ex:
source s_file {
    file("/tmp/f1" fake_facility(local7) fake_level(debug) flags(no-parse));
    file("/tmp/f2" fake_facility(local4) fake_level(warn) flags(no-parse));
};

-- 
Xavier
-------------- next part --------------
diff -ubr syslog-ng-2.1.3/aclocal.m4 syslog-ng-2.1.3-fakepri/aclocal.m4
--- syslog-ng-2.1.3/aclocal.m4	2008-11-19 14:03:40.000000000 +0100
+++ syslog-ng-2.1.3-fakepri/aclocal.m4	2009-03-03 15:39:59.000000000 +0100
@@ -998,6 +998,7 @@
 AC_REQUIRE([AC_PROG_LEX])dnl
 if test "$LEX" = :; then
   LEX=${am_missing_run}flex
+  AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])
 fi])
 
 # pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
diff -ubr syslog-ng-2.1.3/src/affile.c syslog-ng-2.1.3-fakepri/src/affile.c
--- syslog-ng-2.1.3/src/affile.c	2008-06-09 10:33:08.000000000 +0200
+++ syslog-ng-2.1.3-fakepri/src/affile.c	2009-03-03 15:39:59.000000000 +0100
@@ -166,6 +166,26 @@
   gint fd;
   gboolean file_opened, open_deferred = FALSE;
 
+  /*
+   * Did not find a better place to check no-parse and fake_{facility,level}
+   * per source destination, and one time only
+   */
+
+  if (!(self->reader_options.options & LRO_NOPARSE))
+    {
+      if (self->reader_options.fake_facility)
+        msg_error("Can not set fake facility when no-parse is not defined",
+		  evt_tag_str("source file", self->filename->str),
+		  NULL);
+      if (self->reader_options.fake_level)
+        msg_error("Can not set fake level when no-parse is not defined",
+		  evt_tag_str("source file", self->filename->str),
+		  NULL);
+     
+      self->reader_options.fake_level = 0;
+      self->reader_options.fake_facility = 0;
+    }
+
   log_reader_options_init(&self->reader_options, cfg);
 
   file_opened = affile_sd_open_file(self, &fd);
diff -ubr syslog-ng-2.1.3/src/cfg-grammar.y syslog-ng-2.1.3-fakepri/src/cfg-grammar.y
--- syslog-ng-2.1.3/src/cfg-grammar.y	2008-11-05 09:07:33.000000000 +0100
+++ syslog-ng-2.1.3-fakepri/src/cfg-grammar.y	2009-03-03 15:47:32.000000000 +0100
@@ -109,6 +109,8 @@
 %token KW_TEMPLATE KW_TEMPLATE_ESCAPE
 %token KW_FOLLOW_FREQ
 %token KW_OVERWRITE_IF_OLDER
+%token KW_FAKE_FACILITY
+%token KW_FAKE_LEVEL
 
 /* socket related options */
 %token KW_KEEP_ALIVE KW_MAX_CONNECTIONS
@@ -196,8 +198,10 @@
 
 %type   <num> filter_fac_list
 %type   <num> filter_fac
+%type   <num> fake_facility
 %type	<num> filter_level_list
 %type   <num> filter_level
+%type   <num> fake_level
 
 %type	<num> yesno
 %type   <num> dnsmode
@@ -466,6 +470,8 @@
 	| KW_LOG_PREFIX '(' string ')'		{ last_reader_options->prefix = $3; }
 	| KW_PAD_SIZE '(' NUMBER ')'		{ last_reader_options->padding = $3; }
 	| KW_FOLLOW_FREQ '(' NUMBER ')'		{ last_reader_options->follow_freq = $3; }
+	| KW_FAKE_FACILITY '(' fake_facility ')'{ last_reader_options->fake_facility = $3; }
+	| KW_FAKE_LEVEL '(' fake_level ')'      { last_reader_options->fake_level = $3; }
 	| KW_TIME_ZONE '(' string ')'		{ cfg_timezone_value($3, &last_reader_options->zone_offset); free($3); }
 	| KW_KEEP_TIMESTAMP '(' yesno ')'	{ last_reader_options->keep_timestamp = $3; }
 	;
@@ -880,6 +886,24 @@
 	  }
 	;
 
+fake_facility
+	: IDENTIFIER				
+	  {
+	    int n = syslog_name_lookup_facility_by_name($1);
+
+	    if (n == -1)
+	      {
+	        msg_error("Warning: Unknown facility", 
+	                  evt_tag_str("facility", $1),
+	                  NULL);
+	        $$ = 0;
+	      }
+	    else
+	      $$ = n << 3; 
+	    free($1); 
+	  }
+	;
+
 filter_level_list
 	: filter_level filter_level_list	{ $$ = $1 | $2; }
 	| filter_level				{ $$ = $1; }
@@ -922,6 +946,24 @@
 	  }
 	;
 
+fake_level	
+	: IDENTIFIER
+	  {
+	    int n = syslog_name_lookup_level_by_name($1);
+	    
+            if (n == -1)
+	      {
+		msg_error("Warning: Unknown priority level",
+                          evt_tag_str("priority", $1),
+                          NULL);
+		$$ = 0;
+	      }
+	    else
+	      $$ = n;
+	    free($1);
+	  }
+	;
+
 yesno
 	: KW_YES				{ $$ = 1; }
 	| KW_NO					{ $$ = 0; }
diff -ubr syslog-ng-2.1.3/src/cfg-lex.l syslog-ng-2.1.3-fakepri/src/cfg-lex.l
--- syslog-ng-2.1.3/src/cfg-lex.l	2008-11-06 11:46:30.000000000 +0100
+++ syslog-ng-2.1.3-fakepri/src/cfg-lex.l	2009-03-03 15:39:59.000000000 +0100
@@ -117,6 +117,8 @@
  	{ "time_reap",          KW_TIME_REAP },
  	{ "time_sleep",         KW_TIME_SLEEP },
  	{ "follow_freq",	KW_FOLLOW_FREQ },
+	{ "fake_facility", 	KW_FAKE_FACILITY },
+	{ "fake_level",		KW_FAKE_LEVEL },
  	{ "remove_if_older",	KW_OVERWRITE_IF_OLDER }, /* obsolete */
  	{ "overwrite_if_older",	KW_OVERWRITE_IF_OLDER },
  	{ "file_template",	KW_FILE_TEMPLATE },
diff -ubr syslog-ng-2.1.3/src/logreader.c syslog-ng-2.1.3-fakepri/src/logreader.c
--- syslog-ng-2.1.3/src/logreader.c	2008-04-13 11:15:28.000000000 +0200
+++ syslog-ng-2.1.3-fakepri/src/logreader.c	2009-03-03 15:39:59.000000000 +0100
@@ -194,6 +194,11 @@
   if (self->options->prefix)
     g_string_prepend(&m->msg, self->options->prefix);
       
+  /* setting fake facility / severity for log msg */
+  if (parse_flags & LRO_NOPARSE) {
+    m->pri = self->options->fake_facility | self->options->fake_level;
+  }
+  
   if (m->stamp.zone_offset == -1)
     m->stamp.zone_offset = self->options->zone_offset;
   if (!self->options->keep_timestamp)
diff -ubr syslog-ng-2.1.3/src/logreader.h syslog-ng-2.1.3-fakepri/src/logreader.h
--- syslog-ng-2.1.3/src/logreader.h	2008-03-23 22:04:20.000000000 +0100
+++ syslog-ng-2.1.3-fakepri/src/logreader.h	2009-03-03 15:39:59.000000000 +0100
@@ -54,6 +54,8 @@
   gchar *follow_filename;
   gint follow_freq;
   gint fetch_limit;
+  gint fake_facility;
+  gint fake_level;
   
   /* source time zone if one is not specified in the message */
   glong zone_offset;


More information about the syslog-ng mailing list