Re: Traps/Informs

Gaurav Chaturvedi <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Hi Martin,

Its good that you got the solution now.

Following are the functions which can be used in your case as per the
requirement:

*print_objid*, *fprint_objid*, *snprint_objid

Synatx:

**void print_objid(const oid ***objid**, size_t* *objidlen**);
void fprint_objid(FILE ***fp**, const oid ***objid**, size_t* *objidlen**);
int snprint_objid(char ***buf**, size_t* *len**, const oid ***objid**,
size_t* *objidlen**);*

Thanks
Gaurav

On Thu, Jul 22, 2010 at 2:18 PM, Martin Townsend <
[email protected]> wrote:

>  On 21/07/2010 06:05, Gaurav Chaturvedi wrote:
>
> Hi Martin,
>
> Please use the following code after your mentioned part of code.
>
> You need to call "snmp_sess_select_info", "select" and "snmp_sess_read"
> after snmp_sess_read() function. These functions help in reading the data
> from socket and call the callback function.
>
> Also, there is no issue in using localhost in snmptrap/snmpinform commands.
>
> if (transport = netsnmp_tdomain_transport(port, 1, "udp")) {
>         ss = snmp_sess_add(&session, transport, NULL, NULL);
>     }
>
>     while (1) {
>         numfds = 0;
>         FD_ZERO(&fdset);
>         block = 1;    /* note: will be set by snmp_sess_select_info */
>         tvp = &timeout;
>
>         if (block) timerclear(tvp);
>
>         snmp_sess_select_info(ss,&numfds, &fdset, tvp, &block);
>
>         if (block == 1) {
>             tvp = NULL;
>         }
>
>
>         count = select(numfds, &fdset, 0, 0, tvp);
>
>             if (count > 0) {
>                 snmp_sess_read (ss,&fdset);
>             } else
>         ....
>         ....
>     } /* End of while */
>
>     if (ss) {
>         snmp_sess_close(ss);
>         ss = NULL;
>     }
>
>
> Thanks
> Gaurav Chaturvedi
>
> On Tue, Jul 20, 2010 at 10:13 PM, Martin Townsend <
> [email protected]> wrote:
>
>> Hi,
>>
>> I'm having problems processing traps in my management application, After
>> looking through the snmptrapd code I've added calls to
>> netsnmp_transport_open_server(app_name, "udp:162");
>> and then initialise a session with
>> snmp_sess_init
>> with the following initialisation
>>     session_p->peername = SNMP_DEFAULT_PEERNAME;  /* Original code had
>> NULL here */
>>     session_p->version = SNMP_DEFAULT_VERSION;
>>     session_p->community_len = SNMP_DEFAULT_COMMUNITY_LEN;
>>     session_p->retries = SNMP_DEFAULT_RETRIES;
>>     session_p->timeout = SNMP_DEFAULT_TIMEOUT;
>>     session_p->callback = snmp_input;
>>     session_p->callback_magic = (void *) transport_trap_server_p;
>>     session_p->authenticator = NULL;
>>     session_p->isAuthoritative = SNMP_SESS_UNKNOWNAUTH;
>>
>> which sets up the callback snmp_input.
>> then snmp_add to add the session to the opened transport server.
>>
>> In snmp_input I have a printf to make sure that the routine is getting
>> called that will output the operation_id value.
>>
>> Then using snmptrap or snmpinform send the trap, e.g.
>> snmpinform -v2c -c public localhost ""
>> PO-RECTIFIER-TEST-MIB::alarmMajorHighBattVoltTrapPO PO-RECTIFIER-TEST-M
>> IB::alarmMajorHighBattVoltPO.0 i 1
>> snmpinform: Timeout
>>
>> with no success.
>>
>> Is it ok to use snmpinform/trap with localhost and will the code above
>> receive the trap PDU on localhost?
>> My application runs as a process that waits for commands to arrive over
>> a socket so it will be blocked, would this cause problems?
>> Any other ideas/things to try out?
>>
>> Many Thanks in advance,
>> Martin.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by Sprint
>> What will you do first with EVO, the first 4G phone?
>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>> _______________________________________________
>> 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
>>
>
>
> Thank you Gaurav, using the single session api I now have a separate
> pthread to handle the traps.  Just in case anyone else tries this be warned
> that you must store the opaque session pointer returned from snmp_sess_add
> (or maybe pass it via the callback_magic field) as it is different to the
> one passed to the snmp_input callback routine of the session structure.   In
> the snmp_input routine I was trying to use snmp_sess_send to send the INFORM
> reply message using the session pointer that was passed as an input
> parameter which caused a seg fault.  After stepping through the code I could
> see that the opaque session pointer is acutally a struct session_list * as
> returned by snmp_sess_add_ex.
>
> PS does anyone know if there's a routine that takes an OID and returns the
> name/description from the MIB?
>
> Cheers,
> Martin.
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> 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
>
>

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first

_______________________________________________
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.