Hello all,
Below is my code for 'table'.I am compiling it as a "subagent".
Which is getting data from a file.
But my issue is it is taking the data from first time only....
The file "data.txt" is changing its values frequently...
But with snmpwalk I can get the only same data all the time..
How can I get this updating data ? where I am doing mistake?
If it is possible with for(;;)loop where should I add it?
Please help me.
Thanks & Regards,
Jatin
/*
* Note: this file originally auto-generated by mib2c using
* $ mib2c.create-dataset.conf
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "poolTable.h"
/** Initialize the poolTable table by defining its contents and how it's
structured */
int initialize_table_poolTable(void)
{
const oid poolTable_oid[] = {1,3,6,1,4,1,21068,4,1};
netsnmp_table_data_set *table_set;
/* create the table structure itself */
table_set = netsnmp_create_table_data_set("poolTable");
/* comment this out or delete if you don't support creation of new rows
*/
table_set->allow_creation = 1;
/********************* Adding indexes************************/
DEBUGMSGTL(("initialize_table_poolTable","adding indexes to table
poolTable\n"));
netsnmp_table_set_add_indexes(table_set,ASN_INTEGER,/*
index:poolIndex*/0);
DEBUGMSGTL(("initialize_table_poolTable","adding column types to table
poolTable\n"));
netsnmp_table_set_multi_add_default_row(table_set,COLUMN_POOLINDEX,
ASN_INTEGER, 0,
NULL, 0,COLUMN_POOLINOCTETS,
ASN_COUNTER, 0,
NULL, 0,0);
/* registering the table with the master agent */
/* note: if you don't need a subhandler to deal with any aspects
of the request, change poolTable_handler to "NULL" */
netsnmp_register_table_data_set(
netsnmp_create_handler_registration("poolTable",
poolTable_handler,poolTable_oid,
OID_LENGTH(poolTable_oid),
HANDLER_CAN_RWRITE),
table_set, NULL);
int index=1; long data[2];
FILE *fin;
fin=fopen("/home/jatin/data.txt","r");
if(!fin)
{
snmp_log(LOG_ERR,"fopen failed in locating file\n");
return -1;
}
while(!feof(fin))
{
while((fscanf(fin,"%ld %ld",&data[0],&data[1])) == 1)
{
}
if(feof(fin) == 0)
{
fillTableWithValues(table_set,index,data[0],data[1]);
}
index++;
}
return;
}
/** Initializes the poolTable module */
void init_poolTable(void)
{
/* here we initialize all the tables we're planning on supporting */
initialize_table_poolTable();
}
/** handles requests for the poolTable table, if anything else needs to be
done */
int poolTable_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
/* perform anything here that you need to do. The requests have
already been processed by the master table_dataset handler, butthis
gives you
chance to act on the request in some other wayif need be. */
return SNMP_ERR_NOERROR;
}
void fillTableWithValues(netsnmp_table_data_set *table_set,int i,int
Value1,int Value2)
{
netsnmp_table_row *row;
row = netsnmp_create_table_data_row();
int index;
index=i;
netsnmp_table_row_add_index(row, ASN_INTEGER, &index, sizeof(index));
//setting a value to an integer column of my table
int AValue = Value1;
netsnmp_set_row_column(row, COLUMN_POOLINDEX, ASN_INTEGER, &AValue,
sizeof(AValue));
//netsnmp_mark_row_column_writable(row, COLUMN_POOLINDEX, 1);
// make writable via SETs
//setting a value to a string column of my table
int BValue = Value2;
netsnmp_set_row_column(row,COLUMN_POOLINOCTETS, ASN_COUNTER, &BValue,
sizeof(BValue));
//netsnmp_mark_row_column_writable(row,COLUMN_POOLINOCTETS, 1);
// make writable viSETs
netsnmp_table_dataset_add_row(table_set, row);
netsnmp_register_auto_data_table(table_set, NULL);
}//end FillDaPathTableUp()
/********************************************************
Data.txt
*************************************************************
1 567
2 456
3 578
4 688
5 790
6 378
*************************************************************/
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders