On Monday 25 June 2007 19:22:45 Juuso Alasuutari wrote:
> Next up in my small monitor app project is to learn how to get snmp data
> from devices at constant intervals. I expanded the example application
> (http://www.net-snmp.org/wiki/index.php/TUT:Simple_Application) into
> something that can be described with a little pseudocode:
>
>
> init_snmp( "foo" )
>
> while {
>   for each device, do {
>     ss[device] <- snmp_open( session[device] )
>     pdu[device] <- snmp_pdu_create( SNMP_MSG_GET )
>     read_objid( oid[device], temp_oid, len )
>     snmp_add_null_var( pdu[device], temp_oid, len )
>   }
>
>   for each device, do {
>     status = snmp_synch_response ( ss[device], pdu[device], response )
>     if (status == OK) {
>       do stuff with response
>     }
>     snmp_free_pdu( response )
>     response <- NULL
>     free( ss[device] )
>     ss[device] <- NULL
>   }
>
>   for each device, do {
>     snmp_close ( ss[device] )
>   }
>
>   sleep (n_seconds)
> }
>
>
> It seems to work OK, but then again when I left it running on a server it
> had quietly exited after maybe 20 minutes. Although I armed it with
> debugging printfs I didn't see any specific error in the log, it had simply
> quit. But my most important question at this point is if this whole
> approach is appropriate for my needs or if I need to study some helpful
> manual.

I solved this problem by moving some parts of the code outside the loop. I 
noticed that the client always exited when it had looped exactly 1021 
requests. I don't know where that number is from. Here's the pseudocode 
representation of what seems to work:


init_snmp( "foo" )

for each device, do {
  ss[device] <- snmp_open( session[device] )
}

while( something ) {
  for each device, do {
    pdu[device] <- snmp_pdu_create( SNMP_MSG_GET )
    read_objid( oid[device], temp_oid, len )
    snmp_add_null_var( pdu[device], temp_oid, len )
  }

  for each device, do {
    status = snmp_synch_response ( ss[device], pdu[device], response )
    if (status == OK) {
      do stuff with response
    }
    if (response) {
      snmp_free_pdu( response )
      response <- NULL
    }
  }

  sleep (n_seconds)
}

for each device, do {
  snmp_close ( ss[device] )
}


Juuso

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to