Hello,

I tried even a specific OID.

I am using snmpwalk on localhost with .1.3.6. I hope this should generate
some requests that could be passed to the handler function.

On the agent side I am getting

Connection from UDP: [127.0.0.1]:-32767

On the snmpwalk side I am getting request timeout.


M.

On Thu, August 9, 2007 5:42 pm, Graeme Wilson wrote:
> Hi,
>
>
> Hmm, ok.
> All I can really suggest is that you try doing some debug - maybe
> instead of registering a generic OID, try registering a specific OID for a
> test and then try doing a get on that. How are you running the agent and
> how are you performing the get?
>
> Maybe some others on here could help you turning the Debug on for more
> trace messages. I'll keep thinking and get back to you with any other
> suggestions.
>
> Cheers
> G
>
>
>
>
>
>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>> Sent: 09 August 2007 16:09
>> To: Graeme Wilson
>> Cc: net-snmp-users@lists.sourceforge.net
>> Subject: RE: Newbie question: writing a simple agent
>>
>>
>> Hello Graeme,
>>
>>
>> thanks for your prompt reply.
>>
>> netsnmp_register_handler( reg ) is "hidden" in
>>
>> printf("returned=%d\n", netsnmp_register_handler(reg));
>>
>> I tried it before without printf and it was doing the same thing.
>>
>>
>> I have no other handlers and no other agents started.
>>
>>
>> I considered switching snmp logging with LOG_DEBUG
>> level/priority but I did not find any function how to set the level.
>>
>> Is there anything else I could try?
>>
>>
>> Thanks.
>>
>>
>> Milan
>>
>>
>> On Thu, August 9, 2007 4:53 pm, Graeme Wilson wrote:
>>
>>> Hi Milan,
>>>
>>>
>>>
>>> From a quick look at your code it looks like you've missed
>>>
>> a crucial
>>> line to register the handler:
>>>
>>> netsnmp_register_handler( reg );
>>>
>>> Which you need to do after your line:
>>> reg = netsnmp_handler_registration_create(...)
>>>
>>> Also, one important point (I forgot to mention previously),
>>>
>> if there
>>> are any other handlers which register for specific OIDs (e.g.
>>> .1.3.6.1.2.1.1.4.0) - these will be called instead of your generic
>>> handler.
>>>
>>> Hope that helps.
>>> Graeme
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>> -----Original Message-----
>>>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>>>> Sent: 09 August 2007 15:43
>>>> To: Graeme Wilson
>>>> Cc: net-snmp-users@lists.sourceforge.net
>>>> Subject: RE: Newbie question: writing a simple agent
>>>>
>>>>
>>>>
>>>> Hello Graeme,
>>>>
>>>>
>>>>
>>>> sorry for bothering you again.
>>>>
>>>> I have tried to merge your code with MFD code. I am
>>>>
>> obviously doing
>>>> something wrong. When I run snmpwalk on the agent I can see that
>>>> agent_check_and_process(1) in the main loop finishes but
>> the handler
>>>> does not get called.
>>>>
>>>> I get error message from the agent:
>>>>
>>>>
>>>>
>>>> Connection from UDP: [127.0.0.1]:-32767
>>>>
>>>>
>>>>
>>>> I assume this means this request was not handled by the agent.
>>>>
>>>>
>>>>
>>>> I do not know if netsnmp_register_handler(reg) is successful, it
>>>> returns 0. I was googling but I did not find meaning of this value.
>>>>
>>>> Did I miss something in my main()? I am attaching short code.
>>>>
>>>>
>>>>
>>>> Thank you and please do net get angry with me for so many mails.
>>>>
>>>>
>>>>
>>>> Milan
>>>>
>>>>
>>>>
>>>> ----
>>>>
>>>>
>>>>
>>>>
>>>> #include "agent.h"
>>>> #include "agent_error.h"
>>>>
>>>>
>>>>
>>>> static int keep_running;
>>>>
>>>> void stop_server(UNUSED int a) { keep_running = 0; }
>>>>
>>>>
>>>> /* Ippc function which will be called for all OIDs below
>>>>
>> the root one
>>>> registered above */ int IppcOidHandler(UNUSED netsnmp_mib_handler
>>>> *handler, UNUSED netsnmp_handler_registration *reginfo, UNUSED
>>>> netsnmp_agent_request_info *reqinfo, netsnmp_request_info
>> *requests)
>>
>>>> { int ret = SNMP_ERR_NOERROR;
>>>>
>>>>
>>>> printf("Received SNMP request"); for (unsigned i = 0; i <
>>>> requests->range_end_len; i++) { printf("%d.",
>>>> (int)requests->range_end[i]);
>>>> }
>>>> printf("\n");
>>>>
>>>> switch(reqinfo->mode) { case MODE_GET: /* Call some other code to
>>>> process the 'requests' argument */ //ret = myData->getData( requests
>>>> ); break; case
>>>> MODE_GETNEXT: /* Call some other code to process the 'requests'
>>>> argument */ //ret = myData->getNextData( requests );
>> break; default:
>>>> /* we should never get here in my code */ //iRet =
>>>>
>> SNMP_ERR_GENERR;
>>
>>>> break; } return 1; //ret; }
>>>>
>>>>
>>>> int main (UNUSED int argc, UNUSED char **argv) {
>> netsnmp_mib_handler
>>>> *handler; netsnmp_handler_registration *reg;
>>>>
>>>>
>>>> static oid root_oid[] =  { 1, 3, 6 };
>>>>
>>>> snmp_enable_stderrlog();
>>>>
>>>> SOCK_STARTUP;
>>>>
>>>>
>>>>
>>>> init_agent("ippc agent");
>>>>
>>>> init_snmp("ippc agent");
>>>>
>>>> init_master_agent();  /* open the port to listen on (defaults to
>>>> udp:161) */
>>>>
>>>>
>>>>
>>>> keep_running = 1; signal(SIGTERM, stop_server); signal(SIGINT,
>>>> stop_server);
>>>>
>>>> handler = netsnmp_create_handler("IppcOIDHandler",
>> &IppcOidHandler );
>>
>>>>
>>>>
>>>> if (handler) { reg = netsnmp_handler_registration_create(
>>>> "IppcHandler",  handler, root_oid, OID_LENGTH(root_oid), 0);
>>>>
>>>>
>>>>
>>>> printf("returned=%d\n", netsnmp_register_handler(reg)); } else {
>>>> exit(1); }
>>>>
>>>>
>>>>
>>>> while(keep_running) { agent_check_and_process(1); /* 0 ==
>> don't block
>>>> */  printf("mainloop\n"); }
>>>>
>>>>
>>>>
>>>> /* at shutdown time */
>>>> netsnmp_unregister_handler(reg); snmp_shutdown("ippc agent");
>>>> SOCK_CLEANUP;
>>>>
>>>>
>>>>
>>>> return 0; }
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> ----
>>>>
>>>>
>>>>
>>>>
>>>> On Wed, August 8, 2007 4:10 pm, Graeme Wilson wrote:
>>>>
>>>>
>>>>> Hi Milan,
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> No worries about the questions.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> For my subagent (binary/executable) I doctored an existing
>>>>>
>>>>>
>>>> 'main' that
>>>>
>>>>
>>>>> I had from when I'd created a subagent with mib2c - its
>>>>>
>>>>>
>>>> just like your
>>>>> example below: - init_agent - etc etc - register your handler here
>>>>>  - loop (agent_check_and_process)
>>>>> - etc etc
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Cheers
>>>>> Graeme
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: [EMAIL PROTECTED]
>>>>>>
>> [mailto:[EMAIL PROTECTED]
>>
>>>>>> Sent: 08 August 2007 14:47
>>>>>> To: Graeme Wilson
>>>>>> Cc: net-snmp-users@lists.sourceforge.net
>>>>>> Subject: RE: Newbie question: writing a simple agent
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Hello Graeme,
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> I went through your code and it seems it is exactly what I
>>>>>> need.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I am just confused about one thing: how does it plug into
>>>>>> snmpd?
>>>>>>
>>>>>>
>>>>>>
>>>>>> I understand that I need to do in agent main() registration
>>>>>> (and
>>>>>> un-registration at agent finish)  but what do I actually
>> generate?
>>>>>>
>>>>>> Should I create a binary like in MFD example and loop using
>>>>>> agent_check_and_process() or snmp_select_info() or
>> should I create
>>>>>> some kind of .so that does mere regsitration and finishes?
>>>>>>
>>>>>> In the former case the scenario is
>>>>>> - init_agent
>>>>>> - init_snmp
>>>>>> - init_master_agent();
>>>>>> - register handler
>>>>>> - loop
>>>>>> - un-register handler
>>>>>> - snmp_shutdown
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> or am I missing something?
>>>>>>
>>>>>> Sorry for asking you newbie trivial questions :-)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Milan
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, August 8, 2007 11:11 am, Graeme Wilson wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I have done something similar recently (I provide some
>>>>>>>
>>>>>>>
>>>> sample code
>>>>>>> below - but note that ultimately everything is still done
>>>>>>> within
>>>>>>>
>>>>>> the agent).
>>>>>>> My Agent simply registers the root OID of the MIB it will
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> handle and
>>>>>>> some other function knows all about the data and the
>>>> specific OIDs
>>>>>>> that the Agent handles. I just registered a generic
>>>> handler for the
>>>>>>> root oid and
>>>>>> then when it
>>>>>>> is called, the handler make appropriate calls to handle the
>>>>>> request.
>>>>>>> I guess in your case you could then request the data (if
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> any) from the
>>>>>>> process/thread that holds the Data and OIDS.
>>>>>>>
>>>>>>> Hope that helps.
>>>>>>> Graeme
>>>>>>> -------------
>>>>>>> /* In your main/initialise function */
>>>>>>> netsnmp_mib_handler* handler = netsnmp_create_handler(
>>>>>>> "GenericOIDHandler", &genericOidHandler );
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> netsnmp_handler_registration* reg =
>>>>>>> netsnmp_handler_registration_create( "GenericHandler",
>>>>>>> handler, root_oid, OID_LENGTH(root_oid), 0 );
>>>>>>>
>>>>>>> netsnmp_register_handler( reg );
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> /* Generic function which will be called for all OIDs below
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> the root
>>>>>>> one registered above */ int genericOidHandler(
>>>> netsnmp_mib_handler
>>>>>>> *handler, netsnmp_handler_registration *reginfo,
>>>>>>> netsnmp_agent_request_info *reqinfo, netsnmp_request_info
>>>>>> *requests )
>>>>>>
>>>>>>
>>>>>>
>>>>>>> { int ret = SNMP_ERR_NOERROR;
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> switch(reqinfo->mode) { case MODE_GET: /* Call some
>> other code to
>>>>>>> process the 'requests' argument */ ret = myData->getData(
>>>> requests
>>>>>>> ); break; case MODE_GETNEXT: /* Call some other code to
>>>>>>>
>>>>>>>
>>>> process the
>>>>>>> 'requests'
>>>>>>> argument */ ret = myData->getNextData( requests ); break;
>>>> default:
>>>>
>>>>
>>>>>>> /* we should never get here in my code */ iRet =
>>>>>>>
>> SNMP_ERR_GENERR;
>>
>>>>>>> break; } return ret; }
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> -----Original Message-----
>>>>>>>> From: [EMAIL PROTECTED]
>>>>>>>> [mailto:[EMAIL PROTECTED] On
>>>>>>>>
>>>>>>>>
>>>> Behalf Of
>>>>
>>>>
>>>>>>>> [EMAIL PROTECTED]
>>>>>>>> Sent: 08 August 2007 06:51
>>>>>>>> To: Mike Ayers
>>>>>>>> Cc: net-snmp-users@lists.sourceforge.net
>>>>>>>> Subject: RE: Newbie question: writing a simple agent
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Hello Mike,
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> thanks for replying to my question.
>>>>>>>>
>>>>>>>> I understand that a standard approach is to register the
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>> agent for a
>>>>>>>> range of OISs and to let the agent to be OID aware while
>>>> the other
>>>>>>>> process should take care of the underlaying data.
>>>>>>>>
>>>>>>>> However, I was asked to write an agent that would NOT be
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>> OID-aware.
>>>>>>
>>>>>>
>>>>>>
>>>>>>>> All it would know it is responsible for a range of
>>>>>>>>
>> OIDs without
>>
>>>>>>>> knowing any details. It would forward complete OIDs to
>> the other
>>>>>>>> process that would take care about OID
>>>>>> disassembly/translation, data
>>>>>>>> manipulation etc.
>>>>>>>>
>>>>>>>> I am wondering if this is possible within the Net SNMP
>>>>>>>>
>>>>>>>>
>>>> API, at all.
>>>>
>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> If so, where should I start?
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Thanks.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Milan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tue, August 7, 2007 11:44 pm, Mike Ayers wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>>> From: [EMAIL PROTECTED]
>>>>>>>>>> [mailto:[EMAIL PROTECTED] On
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>> Behalf Of
>>>>>>
>>>>>>
>>>>>>
>>>>>>>>>> [EMAIL PROTECTED]
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> The agent itself will not be aware of individual OIDs
>>>>>>>>>>
>>>>>>>>>>
>>>> and their
>>>>>>>>>> meaning. This will be done by the other process that
>>>>>>>>>> also
>>>>>>>> holds the
>>>>>>>>>> actual data.
>>>>>>>>>
>>>>>>>>> This is a bit of a design problem as stated.  The
>>>>>>>>>
>> (sub)agent is
>>
>>>>>>>>> responsible for managing its OID range, and therefore
>> it is not
>>>>>>>>> possible to have a subagent completely unaware of the
>>>>>>>>> OIDs.
>>>>>>>>>
>>>>>>>>>
>>>>>>>> This does
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>> not, however, mean that the subagent needs to be aware of
>>>>>>>>>
>>>>>> the data
>>>>>>>>> underlying the MIB.
>>>>>>>>>
>>>>>>>>> A common paradigm is to have the subagent register for
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>> the range of
>>>>>>>>> values (table, MIB, whatever) that it will manage, and
>>>>>> have the OP
>>>>>>>>> (other
>>>>>>>>> process) manage the data within the range.  The agent
>> does OID
>>>>>>>>> assembly/disassembly (i.e. breaking OIDs into range part
>>>>>>>> and specific
>>>>>>>>> part), possibly reformat the specific part to make it
>>>>>>>>> more understandable to the OP (thus only the subagent need
>>>>>>>>> be
>>>>>>>> MIB aware).
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>> The OP returns the values for the requested data, then
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>> the subagent
>>>>>>>>> formats and assembles the response.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> HTH,
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Mike
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>
>>>>
>> ---------------------------------------------------------------------
>>
>>>>
>>>>>>
>>>>>>>> -
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>> ---  This SF.net email is sponsored by: Splunk Inc.
>>>>>>>>> Still grepping through log files to find problems?  Stop.
>>>>>>>>> Now Search log events and configuration files using AJAX
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>> and a browser.
>>>>>>>>> Download your FREE copy of Splunk now >>
>>>>>>>>>
>>>>>>>>>
>>>> http://get.splunk.com/
>>>>
>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> Net-snmp-users mailing list
>>>>>>>>> Net-snmp-users@lists.sourceforge.net
>>>>>>>>> Please see the following page to unsubscribe or change
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>> other options:
>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/net-snmp-use
>>>>>>>>> rs
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> -----------------------------------------------------------
>>>>>>>> ---
>>>>>>>> -----------
>>>>>>>> This SF.net email is sponsored by: Splunk Inc.
>>>>>>>> Still grepping through log files to find problems?  Stop.
>>>>>>>> Now Search log events and configuration files using AJAX and
>>>>>>>> a browser. Download your FREE copy of Splunk now >>
>>>>>>>> http://get.splunk.com/
>>>>>>>> _______________________________________________
>>>>>>>> Net-snmp-users mailing list
>>>>>>>> Net-snmp-users@lists.sourceforge.net
>>>>>>>> Please see the following page to unsubscribe or change
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>> other options:
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/net-snmp-users
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>
>> ---------------------------------------------------------------------
>>
>>>>
>>>>>> -
>>>>>>
>>>>>>
>>>>>>
>>>>>>> ---  This SF.net email is sponsored by: Splunk Inc.
>>>>>>> Still grepping through log files to find problems?  Stop.
>>>>>>> Now Search log events and configuration files using AJAX
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> and a browser.
>>>>>>> Download your FREE copy of Splunk now >>
>>>>>>>
>> http://get.splunk.com/
>>
>>>>>>> _______________________________________________
>>>>>>> Net-snmp-users mailing list
>>>>>>> Net-snmp-users@lists.sourceforge.net
>>>>>>> Please see the following page to unsubscribe or change
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> other options:
>>>>>>> https://lists.sourceforge.net/lists/listinfo/net-snmp-users
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>>
>
>



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to