Hi Dave, sorry for answering so late, I'd to do something else. I'm still
having the same problem.I tried to use mib2c.container.conf file but mib2c
wasn't able to found it,so I continue using interate.conf. I have some
questions.
1)After using mib2c my .c file only contains create/remove entries
functions. As far as I understand, I need to implement a fetch entrie, to
avoid duplicate row entries..correct???
2) Besides including data reading functions (i'm using text files), do I
need to do anything else?? I did not do anything to the handler,
get_first_data_point and get_next_data_point functions, I left them as mib2
generated them.
3) Could you explain (or send me an info link) of how my table handler is
called by the system?? I don't see where my table list is called on it.
4) I used gdb...but didn't help me a lot, it only confirmed a segmentation
fault. I'm not compiling the whole project, only adding my so files using
dlmod command. Can I still use dbg using this method or do I need to compile
the whole deamon including my handlers??? Do I have to include a command
while generating the library to add some debugging messages???
I'm attaching again my .c and .h files...thanks
Alejandro
On Wed, Apr 16, 2008 at 1:34 PM, Dave Shield <[EMAIL PROTECTED]>
wrote:
> On 16/04/2008, Alejandro Islas <[EMAIL PROTECTED]> wrote:
> > I'm kind of new to linux programming so could you please recommend
> > me a debugger
>
> See http://www.net-snmp.org/wiki/index.php?title=Debugger
>
>
> > I used the mib2c.iterate.conf mib2c file to generate the code.
> > Is this the best configuration file to used as a first approach
> > to coding mibs tables?
>
> That should be fine, yes.
> I tend to prefer the mib2c.container.conf template myself,
> but there's a large amount of overlap between the two.
>
>
> > Should I used mfd file?
>
> Not if you want me to help you! :-)
>
>
> > My main goal is to keep my code as simple as possible
>
> The aim of the MfD framework is to hide as much of the
> processing as possible. It uses a separate routine for
> returning the value of each MIB object (for GET/GETNEXT
> requests), and another routine(s?) for SET processing.
>
> Personally, I'm not convinced that the code framework is
> any easier to work with than the iterator/container templates.
> But this is almost certainly due in part to lack of familiarity
> with this structure. Robert swears by it (while I swear at it!)
>
> I wouldn't want my prejudices to put you off investigating this
> framework if you think it might be easier for you. But you
> might need to start asking for assistance on the IRC channel.
> I'm not sure how much Robert reads the coders list (he certainly
> doesn't tend to read the users list), and it's not a framework
> that I'm prepared to support.
>
>
> Dave
>
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.iterate.conf,v 5.14 2004/10/14 12:57:33 dts12 Exp $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
#include "MonThreadsTable.h"
pthread_t idHilo;
/** Initializes the MonThreadsTable module */
void
init_MonThreadsTable(void)
{
int error;
/* here we initialize all the tables we're planning on supporting */
initialize_table_MonThreadsTable();
/* Creamos el thread para llenar tablas escalares.*/
error = pthread_create( &idHilo, NULL, setProcMonThread, NULL );
/* Comprobamos el error al arrancar el thread */
if ( error != 0 )
DEBUGMSGTL(("MonThreadsTable","No puedo crear thread setProcMon\n" ));
else
DEBUGMSGTL(("MonThreadsTable", "Proceso setProcMon creado\n"));
}
/** Initialize the MonThreadsTable table by defining its contents and how it's structured */
void
initialize_table_MonThreadsTable(void)
{
static oid MonThreadsTable_oid[] = {1,3,6,1,4,1,17723,2,1,1,19,1};
size_t MonThreadsTable_oid_len = OID_LENGTH(MonThreadsTable_oid);
netsnmp_handler_registration *reg;
netsnmp_iterator_info *iinfo;
netsnmp_table_registration_info *table_info;
reg = netsnmp_create_handler_registration(
"MonThreadsTable", MonThreadsTable_handler,
MonThreadsTable_oid, MonThreadsTable_oid_len,
HANDLER_CAN_RONLY
);
table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
netsnmp_table_helper_add_indexes(table_info,
ASN_INTEGER, /* index: IdThread */
0);
table_info->min_column = 1;
table_info->max_column = 4;
iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
iinfo->get_first_data_point = MonThreadsTable_get_first_data_point;
iinfo->get_next_data_point = MonThreadsTable_get_next_data_point;
iinfo->table_reginfo = table_info;
netsnmp_register_table_iterator( reg, iinfo );
/* Initialise the contents of the table here */
}
void AnalizeProcMon(char *buffer,int len_buffer)
{
MonThreadsTable_entry data;
MonThreadsTable_entry *ptr;
ptr=NULL;
sscanf(buffer,"%ld %ld %ld %ld",&data.IdThread,
&data.ProcTime,&data.MaxProcTime,&data.ExecNumber);
ptr=MonThreadsTable_fetchEntry(&data);
if(ptr==NULL)
ptr=MonThreadsTable_createEntry(data.IdThread);
if(ptr!=NULL)
{
ptr->ProcTime=data.ProcTime;
ptr->MaxProcTime=data.MaxProcTime;
ptr->ExecNumber=data.ExecNumber;
}
}
void *setProcMonThread(void *parameter)
{
FILE *fp;
int sizeBuffer;
sizeBuffer = 100;
int len_buffer=0;
char buffer[sizeBuffer];
while( 1 )
{
// Obteniendo flujo de datos
fp = fopen( "/usr/monitorMSC/procesosSNMP.dat", "r" );
if ( fp == NULL )
return NULL;
memset(buffer,0x0,sizeBuffer);
while( feof( fp ) == 0 )
{
buffer[len_buffer]=fgetc(fp);
len_buffer++;
if(buffer[len_buffer-1]=='\n')
{
//DEBUGMSGTL(("softelMonitor", "Trama ProcMon\n"));
//DEBUGMSGTL(("softelMonitor", buffer));
AnalizeProcMon(buffer,len_buffer-1);
len_buffer=0;
memset(buffer,0x0,sizeBuffer);
}
}
fclose(fp);
sleep(5);
}
}// FIN setProcMonThread()
MonThreadsTable_entry *MonThreadsTable_head=NULL;
/* create a new row in the (unsorted) table */
MonThreadsTable_entry *MonThreadsTable_createEntry(long IdThread)
{
MonThreadsTable_entry *entry;
entry=(MonThreadsTable_entry *)malloc(sizeof(MonThreadsTable_entry));
if (!entry)
return NULL;
entry->IdThread = IdThread;
entry->next = MonThreadsTable_head;
MonThreadsTable_head = entry;
return entry;
}
/*fetch a row from the table*/
MonThreadsTable_entry *MonThreadsTable_fetchEntry(MonThreadsTable_entry *entry)
{
MonThreadsTable_entry *ptr,*prev;
if (!entry)
return NULL;
for ( ptr = MonThreadsTable_head, prev=NULL;ptr!=NULL;prev=ptr,ptr = ptr->next)
{
if ( ptr->IdThread == entry->IdThread )
return ptr;
}
return NULL;
}
/* remove a row from the table */
void MonThreadsTable_removeEntry(MonThreadsTable_entry *entry ) {
MonThreadsTable_entry *ptr, *prev;
if (!entry)
return; /* Nothing to remove */
for ( ptr = MonThreadsTable_head, prev = NULL;
ptr != NULL;
prev = ptr, ptr = ptr->next ) {
if ( ptr == entry )
break;
}
if ( !ptr )
return; /* Can't find it */
if ( prev == NULL )
MonThreadsTable_head = ptr->next;
else
prev->next = ptr->next;
SNMP_FREE( entry ); /* XXX - release any other internal resources */
}
/* Example iterator hook routines - using 'get_next' to do most of the work */
netsnmp_variable_list *
MonThreadsTable_get_first_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list *put_index_data,
netsnmp_iterator_info *mydata)
{
*my_loop_context = MonThreadsTable_head;
return MonThreadsTable_get_next_data_point(my_loop_context, my_data_context,
put_index_data, mydata );
}
netsnmp_variable_list *MonThreadsTable_get_next_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list *put_index_data,
netsnmp_iterator_info *mydata)
{
MonThreadsTable_entry *entry = (MonThreadsTable_entry *)*my_loop_context;
netsnmp_variable_list *idx = put_index_data;
if ( entry ) {
snmp_set_var_value( idx, (u_char*)&entry->IdThread, sizeof(entry->IdThread) );
idx = idx->next_variable;
*my_data_context = (void *)entry;
*my_loop_context = (void *)entry->next;
} else {
return NULL;
}
return idx;
}
/** handles requests for the MonThreadsTable table */
int
MonThreadsTable_handler(
netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
netsnmp_request_info *request;
netsnmp_table_request_info *table_info;
MonThreadsTable_entry *table_entry;
switch (reqinfo->mode) {
/*
* Read-support (also covers GetNext requests)
*/
case MODE_GET:
for (request=requests; request; request=request->next) {
table_entry = (MonThreadsTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info( request);
switch (table_info->colnum) {
case COLUMN_IDTHREAD:
snmp_set_var_typed_value( request->requestvb, ASN_INTEGER,
(u_char*)&table_entry->IdThread,
sizeof(table_entry->IdThread));
break;
case COLUMN_PROCTIME:
snmp_set_var_typed_value( request->requestvb, ASN_UNSIGNED,
(u_char*)&table_entry->ProcTime,
sizeof(table_entry->ProcTime));
break;
case COLUMN_MAXPROCTIME:
snmp_set_var_typed_value( request->requestvb, ASN_UNSIGNED,
(u_char*)&table_entry->MaxProcTime,
sizeof(table_entry->MaxProcTime));
break;
case COLUMN_EXECNUMBER:
snmp_set_var_typed_value( request->requestvb, ASN_UNSIGNED,
(u_char*)&table_entry->ExecNumber,
sizeof(table_entry->ExecNumber));
break;
}
}
break;
}
return SNMP_ERR_NOERROR;
}
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.iterate.conf,v 5.14 2004/10/14 12:57:33 dts12 Exp $
*/
#ifndef MONTHREADSTABLE_H
#define MONTHREADSTABLE_H
/* function declarations */
void init_MonThreadsTable(void);
void initialize_table_MonThreadsTable(void);
Netsnmp_Node_Handler MonThreadsTable_handler;
Netsnmp_First_Data_Point MonThreadsTable_get_first_data_point;
Netsnmp_Next_Data_Point MonThreadsTable_get_next_data_point;
/* column number definitions for table MonThreadsTable */
#define COLUMN_IDTHREAD 1
#define COLUMN_PROCTIME 2
#define COLUMN_MAXPROCTIME 3
#define COLUMN_EXECNUMBER 4
/* Typical data structure for a row entry */
typedef struct MonThreadsTable_entry_s
{
/* Index values */
long IdThread;
/* Column values */
u_long ProcTime;
u_long MaxProcTime;
u_long ExecNumber;
/* Illustrate using a simple linked list */
int valid;
struct MonThreadsTable_entry_s *next;
}MonThreadsTable_entry;
void *setProcMonThread(void *parameter) ;
MonThreadsTable_entry *MonThreadsTable_createEntry(long IdThread);
MonThreadsTable_entry *MonThreadsTable_fetchEntry(MonThreadsTable_entry *entry);
#endif /* MONTHREADSTABLE_H */
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders