[TriLUG] Re: Debian Sarge '-t' to snmptrapd not work

Brian Weaver cmdrclueless at gmail.com
Fri May 5 15:16:43 EDT 2006


I found the solution. I'm posting it just in case anyone else is
annoyed by the logging.

The simple fix is to use the deprecated options '-s' and not '-Ls' or '-LS'.

The complicated fix is to apply the following patches and rebuild. I'm
just pointing the patches because it took me so long to track down.
I'm pretty darn sure that the net-snmp team has fixed this already as
best I can tell from looking at their sources in CVS on
sourceforge.net.

-Brian

Use the patches at your own risk ;-)

--- net-snmp-5.1.2.orig/apps/snmptrapd.c     2004-06-22 18:57:32.000000000 -0400
+++ net-snmp-5.1.2/apps/snmptrapd.c    2006-05-05 14:51:49.053685182 -0400
@@ -715,11 +715,20 @@
             break;

         case 'L':
-      if  (snmp_log_options( optarg, argc, argv ) < 0 ) {
-                usage();
-                exit(1);
-            }
-            Log++;
+      {
+          int which;
+          if ((which = snmp_log_options( optarg, argc, argv )) < 0 ) {
+       usage();
+       exit(1);
+   }
+
+   if(which & 1)
+       Syslog++;
+   else if(which & 4)
+       Print++;
+   else
+       Log++;
+      }
             break;

         case 'P':
--- net-snmp-5.1.2.orig/snmplib/snmp_logging.c  2004-03-30
20:06:08.000000000 -0500
+++ net-snmp-5.1.2/snmplib/snmp_logging.c       2006-05-05
14:47:22.992761061 -0400
@@ -261,6 +261,14 @@
     int             inc_optind = 0;
     netsnmp_log_handler *logh;

+    /* Which facility is enabled
+     * SYSLOG = 0x0001
+     * FILE   = 0x0002
+     * ERROR  = 0x0004
+     * OUTPUT = 0x0008
+     */
+    int             which = 0;
+
     optarg++;
     if (!*cp)
         cp = &missing_opt;
@@ -309,6 +317,7 @@
             logh->pri_max = pri_max;
             logh->token   = strdup("stderr");
        }
+       which = 4;
         break;

     /*
@@ -327,6 +336,7 @@
             logh->token   = strdup("stdout");
             logh->imagic  = 1;     /* stdout, not stderr */
        }
+       which = 8;
         break;

     /*
@@ -349,6 +359,7 @@
             logh->pri_max = pri_max;
             logh->token   = strdup(optarg);
        }
+       which = 2;
         break;

     /*
@@ -374,13 +385,14 @@
             logh->token   = NULL;
             logh->magic   = (void *)facility;
        }
+       which = 1;
         break;

     default:
         fprintf(stderr, "Unknown logging option passed to -L: %c.\n", *cp);
         return -1;
     }
-    return 0;
+    return which;
 }

 void


On 5/5/06, Brian Weaver <cmdrclueless at gmail.com> wrote:
> Hi all,
>
> I've been having a problem with the snmptrapd agent on my Debian
> stable (sarge) box. I *think* I might know the reason for my problem,
> but I'm wondering if anyone else can reproduce it. If my thoughts are
> correct, it's going to require a source patch and rebuild to get it
> working correctly. I'm also going to discuss it with the net-snmp
> development team, but their site is unreachable from my computer at
> the moment.
>
> At issue is the logging of traps to syslog. According to the man pages
> I should be able to add the '-t' option to the command line of
> snmptrapd to prevent the traps from being passed to syslog. This
> *should* make snmptrapd only run trap handlers from the conf file.
> Unfortunately, it doesn't seem to work at all.
>
> I downloaded the debian stable source and browsed through it. Based on
> the code I cannot find any logical reason why it's not working
> correctly. My current thoughts, it's a problem with dynamic linking.
> The variable that is checked is defined and allocated in the binary
> snmptrapd. The logging is in a shared library that has an undefined
> reference for the global 'SyslogTrap'. In theory the linker *should*
> fix up the references and things should work correctly. The '-t' flag
> increments the variable and a non-zero value prevents the logging of
> the trap to syslog.
>
> So why the code looks correct, it doesn't seem to function correctly.
> If anyone else could let me know if the '-t' option works for you I
> would appreciate it.
>
> Thanks
>
> -Brian
>
> --
>
> /* insert witty comment here */
>


--

/* insert witty comment here */



More information about the TriLUG mailing list