[2013/06/10 07:09:30] #net-snmp <grummund> Hi all, does anyone have or know of example code showing usage of netsnmp_add_loghandler() function please?
[2013/06/10 07:14:17] #net-snmp <grummund> or indeed any documentation?
[2013/06/10 07:16:36] #net-snmp <rstory-work> it's used internally in ./snmplib/snmp_logging.c...
[2013/06/10 07:23:35] #net-snmp <grummund> hmm, so it is.
[2013/06/10 07:24:23] #net-snmp <grummund> maybe i have the wrong function... what actually i'm trying to do is direct any internal net-snmp messages through my own log function.
[2013/06/10 07:25:12] #net-snmp <grummund> ACTION assumes snmp_enable_calllog() has something to do with that.
[2013/06/10 07:25:44] #net-snmp <rstory-work> as long as 'internal net-snmp messages' means log messages, you're in the right place. if it means 'snmp PDUs/packets', then you're way off..
[2013/06/10 07:26:08] #net-snmp <grummund> yep just log messages
[2013/06/10 07:26:40] #net-snmp <grummund> i'm writing a sub-agent and currently the sub-agent logging goes to stderr
[2013/06/10 07:29:31] #net-snmp <rstory-work> where do you want it to go? there are several functions in that file that will send logs to a file, syslog, etc
[2013/06/10 07:30:03] #net-snmp <rstory-work> snmp_enable_filelog, snmp_enable_syslog, etc
[2013/06/10 07:30:08] #net-snmp <grummund> the app that the agent is integrated to has its own logging mechanism
[2013/06/10 07:30:42] #net-snmp <grummund> if i can provide a callback for net-snmp to call that would be ideal
[2013/06/10 07:30:48] #net-snmp <rstory-work> ah, yes, then you'll need to write your own handler..
[2013/06/10 07:31:19] #net-snmp <grummund> looking at this for example usage - https://community.cablelabs.com/svn/OCAPRI/trunk/ri/RI_Platform/src/snmp/agent.c
[2013/06/10 08:23:14] #net-snmp <grummund> Yay. it works using snmp_enable_calllog() and netsnmp_add_loghandler().
[2013/06/10 08:31:59] #net-snmp <fenestro> sweet
[2013/06/10 09:32:06] #net-snmp <grummund> argh. thought i had snmp_select_info() working ok but it seems not to be
[2013/06/10 09:32:43] #net-snmp <grummund> normally the sub-agent will "auto reconnect" with snmp if the connection dies
[2013/06/10 09:32:58] #net-snmp <grummund> but when using select() this seems to break the process
[2013/06/10 09:49:25] #net-snmp <fenestro> do you have timeouts working properly?
[2013/06/10 09:50:24] #net-snmp <fenestro> e.g., it's relatively common to assume that the timeout hasn't passed if select doesn't return 0, but if you have a file descriptor that is always ready that will never happen
[2013/06/10 09:52:36] #net-snmp <grummund> i was using it without a timeout (i.e. blocking) and i think that's the problem
[2013/06/10 09:53:04] #net-snmp <grummund> since netsnmp sets a 15s alarm but it never gest actioned
[2013/06/10 09:54:36] #net-snmp <fenestro> yes, you need to respect the timeout that net-snmp asks for
[2013/06/10 09:56:05] #net-snmp <grummund> does this means that agent_check_and_process() should be called regardless of the return value from select() ?
[2013/06/10 09:56:51] #net-snmp <fenestro> ah, I don't use agent_check_and_process()
[2013/06/10 09:57:09] #net-snmp <fenestro> here is what I have, which has the bug that I mentioned about assuming that ==0 was a timeout
[2013/06/10 09:57:12] #net-snmp <fenestro> https://gist.github.com/fenner/5750382
[2013/06/10 09:57:46] #net-snmp <fenestro> if you're using snmp_select_info I think you should use snmp_read() and snmp_timeout(), not agent_check_and_process
[2013/06/10 09:58:24] #net-snmp <fenestro> and now that I'm looking at that code I wonder about run_alarms() too
[2013/06/10 09:58:46] #net-snmp <rstory-work> yes, you'll need to call run_alarms too..
[2013/06/10 09:59:25] #net-snmp <rstory-work> grummund: is there a particular reason you aren't using agent_check_and_process?
[2013/06/10 09:59:37] #net-snmp <fenestro> grummund is, I'm not
[2013/06/10 10:00:11] #net-snmp <grummund> rstory-work: i am using agent_check_and_process() but the suggestion is i should not be.
[2013/06/10 10:01:45] #net-snmp <rstory-work> it does the select stuff and handles alarms.. i recommend using it instaed of snmp_select_info and calling select yourself..
[2013/06/10 10:02:14] #net-snmp <rstory-work> or at least look at how it works to make sure you are doing the same stuff if you don't want to use it..
[2013/06/10 10:02:59] #net-snmp <fenestro> yeah, my gist is basically agent_check_and_process plus netsnmp_external_event processing
[2013/06/10 10:04:18] #net-snmp <rstory-work> yep, if you've got other fds to watch, the external event stuff is what you need..
[2013/06/10 10:04:21] #net-snmp <grummund> rstory-work: yeah but i need snmp_select_info() because the application is single threaded and has anoth FD to wait on.
[2013/06/10 10:04:46] #net-snmp <rstory-work> grummund: check out the external event stuff to register that fd and get a callback for it..
[2013/06/10 10:05:29] #net-snmp <fenestro> rstory-work: that doesn't simplify things any since agent_check_and_process doesn't do the external event stuff
[2013/06/10 10:05:43] #net-snmp <fenestro> (it should, we agreed, I just haven't gotten around to writing and submitting a patch)
[2013/06/10 10:07:51] #net-snmp <rstory-work> d'oh!
[2013/06/10 10:13:08] #net-snmp <rstory-work> ok then.. grummund, use netsnmp_get_next_alarm_time to get the right timeout value for your select call..
[2013/06/10 10:13:42] #net-snmp <grummund> does snmp_select_info() not do this already?
[2013/06/10 10:13:54] #net-snmp <fenestro> snmp_select_info() does this, you just have to set tv to a large value going in (see my gist)
[2013/06/10 10:14:30] #net-snmp <grummund> timeout.tv_sec = LONG_MAX;
[2013/06/10 10:14:30] #net-snmp <grummund> timeout.tv_usec = 0;
[2013/06/10 10:14:35] #net-snmp <grummund> that is what i have
[2013/06/10 10:14:57] #net-snmp <fenestro> (maybe that's a bug in snmp_select_info, that it still does a min() even if you pass in block=1)
[2013/06/10 10:15:53] #net-snmp <grummund> i was using block=1 but that clearly did not work, now using block=0.
[2013/06/10 10:43:00] #net-snmp <grummund_> not sure if my last paste got through but i won't repeat it ;)