Note that there are some explanatory texts on larger screens.

plurals
  1. POusing net-snmp:can not regularly read and update data from a file
    primarykey
    data
    text
    <pre><code>/* * Note: this file originally auto-generated by mib2c using * $ mib2c.create-dataset.conf */ #include &lt;net-snmp/net-snmp-config.h&gt; #include &lt;net-snmp/net-snmp-includes.h&gt; #include &lt;net-snmp/agent/net-snmp-agent-includes.h&gt; #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"); table_set-&gt;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); 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/xx/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",&amp;data[0],&amp;data[1])) == 1) { } if(feof(fin) == 0) { fillTableWithValues(table_set,index,data[0],data[1]); } index++; } return; } void init_poolTable(void) { initialize_table_poolTable(); } int poolTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { 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, &amp;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, &amp;AValue, sizeof(AValue)); int BValue = Value2; netsnmp_set_row_column(row,COLUMN_POOLINOCTETS, ASN_COUNTER, &amp;BValue, sizeof(BValue)); 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 *************************************************************/ </code></pre> <p>Above is my code for ‘table’.</p> <p>I am compiling it as a “subagent” which is getting data from a file.</p> <p>But my issue is it is taking the data from first time only.</p> <p>The file “data.txt” is changing its values frequently but with snmpwalk I am only getting the same data every time. How can I get the updated data ? Where am I making a mistake? If it is possible with a <code>for(;;)</code>loop, then where should I add it? Please help me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload