On 6 April 2010 12:57, Dave Shield <[email protected]> wrote:
> There's something about specifying "logOption" in the config file that
> works in a different manner.   I'll investigate further, and get back to you.

OK - I think I've tracked down the problem.

If logging is specified on the command line, this is set up relatively
early (as part of the option processing - around line 837 of snmptrapd.c).

If logging is specified via the config file, this is set up by the library
config processing, which is triggered by "init_snmp()" - around line 1062

However, in between the two - immediately after the option processing
comes a block of code

    if (0 == snmp_get_do_logging()) {
        traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER,
                                               syslog_handler);
        traph->authtypes = TRAP_AUTH_LOG;
        snmp_enable_syslog();
    } else {
        traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER,
                                               print_handler);
        traph->authtypes = TRAP_AUTH_LOG;
    }

(lines 954-963).
This has the effect of defaulting to using the "syslog_handler" (which
ignores the
format1/format2 directives), rather than the "print_handler" (which
does use them).

I'm attaching a patch which seems to fix this problem,
though it would merit further study before we can apply it to the code.

Dave
Index: apps/snmptrapd.c
===================================================================
--- apps/snmptrapd.c	(revision 18394)
+++ apps/snmptrapd.c	(working copy)
@@ -1078,40 +1078,6 @@
 
     SOCK_STARTUP;
 
-    /*
-     * I'm being lazy here, and not checking the
-     * return value from these registration calls.
-     * Don't try this at home, children!
-     */
-    if (0 == snmp_get_do_logging()) {
-        traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER,
-                                               syslog_handler);
-        traph->authtypes = TRAP_AUTH_LOG;
-        snmp_enable_syslog();
-    } else {
-        traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER,
-                                               print_handler);
-        traph->authtypes = TRAP_AUTH_LOG;
-    }
-
-    if (Event) {
-        traph = netsnmp_add_traphandler(event_handler, risingAlarm,
-                                        OID_LENGTH(risingAlarm));
-        traph->authtypes = TRAP_AUTH_LOG;
-
-        traph = netsnmp_add_traphandler(event_handler, fallingAlarm,
-                                        OID_LENGTH(fallingAlarm));
-        traph->authtypes = TRAP_AUTH_LOG;
-
-        traph = netsnmp_add_traphandler(event_handler, unavailableAlarm,
-                                        OID_LENGTH(unavailableAlarm));
-        traph->authtypes = TRAP_AUTH_LOG;
-	/* XXX - might be worth setting some "magic data"
-	 * in the traphandler structure that 'event_handler'
-	 * can use to avoid checking the trap OID values.
-	 */
-    }
-
 #if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(NETSNMP_SNMPTRAPD_DISABLE_AGENTX)
     /*
      * we're an agentx subagent? 
@@ -1231,17 +1197,45 @@
         netsnmp_running = 0;
     }
 
+
     /*
      * if no logging options on command line or in conf files, use syslog
      */
     if (0 == snmp_get_do_logging()) {
+        traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER,
+                                               syslog_handler);
+        traph->authtypes = TRAP_AUTH_LOG;
 #ifdef WIN32
         snmp_enable_syslog_ident(app_name_long, Facility);
 #else
         snmp_enable_syslog_ident(app_name, Facility);
 #endif        
+    } else {
+        traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER,
+                                               print_handler);
+        traph->authtypes = TRAP_AUTH_LOG;
     }
 
+
+    if (Event) {
+        traph = netsnmp_add_traphandler(event_handler, risingAlarm,
+                                        OID_LENGTH(risingAlarm));
+        traph->authtypes = TRAP_AUTH_LOG;
+
+        traph = netsnmp_add_traphandler(event_handler, fallingAlarm,
+                                        OID_LENGTH(fallingAlarm));
+        traph->authtypes = TRAP_AUTH_LOG;
+
+        traph = netsnmp_add_traphandler(event_handler, unavailableAlarm,
+                                        OID_LENGTH(unavailableAlarm));
+        traph->authtypes = TRAP_AUTH_LOG;
+	/* XXX - might be worth setting some "magic data"
+	 * in the traphandler structure that 'event_handler'
+	 * can use to avoid checking the trap OID values.
+	 */
+    }
+
+
 #ifndef WIN32
     /*
      * fork the process to the background if we are not printing to stderr 
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to