Dave, attached is my code.
The rationale behind the code is to set index value at every beginning of
column loop. When loop goes back to the beginning of next column, the index
is reset to 1 and count again.
The whole log file for snmpwalk is 718MB, too much to attach (open it in
gedit takes > 5 minutes). I'm looking for a web site I can upload
the log file now (will inform you in next email). In brief, the result is
"for all objects for one column, their values are the same - the latest one
in log file".
On Tue, Apr 12, 2011 at 9:40 AM, Dave Shield <[email protected]>wrote:
> On 12 April 2011 14:28, Zimmer Hu <[email protected]> wrote:
> >> You still haven't provided the output from "snmpwalk" that I asked for.
> >
> > Here is snmpwalk output (only partial, too long as a whole).
>
> No - please post the *WHOLE* of the output.
> (Probably as an attachment would be best).
> Or at least make it available on a website somewhere,
> and post a link to it.
>
> I cannot hope to help you track down what is going wrong
> if I'm constantly working with incomplete information!
>
>
> > I reset Index
> > counter to 1 in loop_free_at_end, and the snmpwalk just returns the
> latest
> > syslog record in snmpwalk command (the "stCnt: 1" is the debug record).
>
> What happens if you do *not* reset the index counter here?
>
> The purpose of the 'free_loop_context_at_end" hook
> (which is what I presume you are referring to here) is to release
> any resources that you have allocated during the get_first/next cycle.
> It's probably not sensible to try and do anything else.
>
> Perhaps you should post the full code of your MIB module.
> so that we can see exactly what you are doing, and what might
> be going wrong.
>
>
> Dave
>
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.iterate.conf 17821 2009-11-11 09:00:00Z dts12 $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "syslogMsgTable.h"
/** Initializes the syslogMsgTable module */
void
init_syslogMsgTable(void)
{
/* here we initialize all the tables we're planning on supporting */
initialize_table_syslogMsgTable();
}
/** Initialize the syslogMsgTable table by defining its contents and how it's structured */
void
initialize_table_syslogMsgTable(void)
{
static oid syslogMsgTable_oid[] = { 1,3,6,1,2,1,192,1,2 };
size_t syslogMsgTable_oid_len = OID_LENGTH(syslogMsgTable_oid);
netsnmp_handler_registration *reg;
netsnmp_iterator_info *iinfo;
netsnmp_table_registration_info *table_info;
reg = netsnmp_create_handler_registration(
"syslogMsgTable", syslogMsgTable_handler,
syslogMsgTable_oid, syslogMsgTable_oid_len,
HANDLER_CAN_RONLY
);
DEBUGMSGTL(("syslogTable/load","I'm in initialize_Table\n"));
table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED, 0); /* index: syslogMsgIndex */
table_info->min_column = COLUMN_SYSLOGMSGFACILITY;
table_info->max_column = COLUMN_SYSLOGMSGMSG;
iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
iinfo->get_first_data_point = syslogMsgTable_get_first_data_point;
iinfo->get_next_data_point = syslogMsgTable_get_next_data_point;
iinfo->make_data_context = syslogMsgTable_make_data_context;
//iinfo->free_data_context = syslogMsgTable_data_free;
iinfo->free_loop_context_at_end = syslogMsgTable_loop_free;
iinfo->table_reginfo = table_info;
netsnmp_register_table_iterator( reg, iinfo );
/* Initialise the contents of the table here */
return;
}
/* Typical data structure for a row entry */
struct syslogMsgTable_entry {
/* Index values */
u_long syslogMsgIndex;
/* Column values */
long syslogMsgFacility;
long syslogMsgSeverity;
u_long syslogMsgVersion;
char syslogMsgTimeStamp[NNN];
size_t syslogMsgTimeStamp_len;
char syslogMsgHostName[NNN];
size_t syslogMsgHostName_len;
char syslogMsgAppName[NNN];
size_t syslogMsgAppName_len;
char syslogMsgProcID[NNN];
size_t syslogMsgProcID_len;
char syslogMsgMsgID[NNN];
size_t syslogMsgMsgID_len;
u_long syslogMsgSDParams;
char syslogMsgMsg[NNN];
size_t syslogMsgMsg_len;
/* Illustrate using a simple linked list */
int valid;
struct syslogMsgTable_entry *next;
};
struct syslogMsgTable_entry *syslogMsgTable_head;
/* create a new row in the (unsorted) table */
struct syslogMsgTable_entry *
syslogMsgTable_createEntry( u_long syslogMsgIndex )
{
struct syslogMsgTable_entry *entry;
entry = SNMP_MALLOC_TYPEDEF(struct syslogMsgTable_entry);
if (!entry)
return NULL;
entry->syslogMsgIndex = syslogMsgIndex;
entry->next = syslogMsgTable_head;
syslogMsgTable_head = entry;
return entry;
}
/* remove a row from the table */
void
syslogMsgTable_removeEntry( struct syslogMsgTable_entry *entry ) {
struct syslogMsgTable_entry *ptr, *prev;
if (!entry)
return; /* Nothing to remove */
for ( ptr = syslogMsgTable_head, prev = NULL;
ptr != NULL;
prev = ptr, ptr = ptr->next ) {
if ( ptr == entry )
break;
}
if ( !ptr )
return; /* Can't find it */
if ( prev == NULL )
syslogMsgTable_head = ptr->next;
else
prev->next = ptr->next;
SNMP_FREE( entry ); /* XXX - release any other internal resources */
}
/** handles requests for the syslogMsgTable table */
int
syslogMsgTable_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;
// struct syslogMsgTable_entry *table_entry;
syslogMsgTable_loop_context *table_loopctx;
syslogMsgTable_data_context *table_entry;
// long *retval;
// size_t retval_len = 0;
static int accesstimes = 0;
DEBUGMSGTL(("syslogTable/load","I'm in Table_handler, accessed %d times.\n",accesstimes++));
switch (reqinfo->mode) {
/*
* Read-support (also covers GetNext requests)
*/
case MODE_GET:
for (request=requests; request; request=request->next) {
// table_entry = (struct syslogMsgTable_entry *) \
netsnmp_extract_iterator_context(request);
table_entry = (syslogMsgTable_data_context *) \
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_SYSLOGMSGFACILITY:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//// retval =
//// get_syslogMsgFacility(void *data_context, size_t *ret_len);
//// snmp_set_var_typed_value(var, ASN_INTEGER, \
(const u_char *) retval, \
retval_len);
//DEBUGMSGTL(("syslogTable/load"," ====>>>>> I'm in syslogMsgTable_handler: COLUMN_SYSLOGMSG FACILITY\n"));
snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
table_entry->syslogMsgFacility);
break;
case COLUMN_SYSLOGMSGSEVERITY:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//DEBUGMSGTL(("syslogTable/load"," ====>>>>> I'm in syslogMsgTable_handler: COLUMN_SYSLOGMSG SEVERITY\n"));
snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
table_entry->syslogMsgSeverity);
break;
case COLUMN_SYSLOGMSGVERSION:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//DEBUGMSGTL(("syslogTable/load"," ====>>>>> I'm in syslogMsgTable_handler: COLUMN_SYSLOGMSG VERSION\n"));
snmp_set_var_typed_integer( request->requestvb, ASN_UNSIGNED,
table_entry->syslogMsgVersion);
break;
case COLUMN_SYSLOGMSGTIMESTAMP:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//printTS(table_entry->syslogMsgTimeStamp); // ????
//DEBUGMSGTL(("syslogTable/load"," ====>>>>> I'm in syslogMsgTable_handler: COLUMN_SYSLOGMSG TIMESTAMP\n"));
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
(u_char*)table_entry->syslogMsgTimeStamp,
strlen(table_entry->syslogMsgTimeStamp));
//table_entry->syslogMsgTimeStamp_len);
break;
case COLUMN_SYSLOGMSGHOSTNAME:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//DEBUGMSGTL(("syslogTable/load"," ====>>>>> I'm in syslogMsgTable_handler: COLUMN_SYSLOGMSG HOSTNAME%s\n", table_entry->syslogMsgHostName));
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
(u_char*)table_entry->syslogMsgHostName,
strlen(table_entry->syslogMsgHostName));
//table_entry->syslogMsgHostName_len);
break;
case COLUMN_SYSLOGMSGAPPNAME:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//printf(" ---------->>>> table_entry->syslogMsgTimeAppName: %s\n", table_entry->syslogMsgAppName);
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
(u_char*)table_entry->syslogMsgAppName,
strlen(table_entry->syslogMsgAppName));
//table_entry->syslogMsgAppName_len);
break;
case COLUMN_SYSLOGMSGPROCID:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//printf(" ---------->>>> table_entry->syslogMsgProcID: %s\n", table_entry->syslogMsgProcID);
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
(u_char*)table_entry->syslogMsgProcID,
strlen(table_entry->syslogMsgProcID));
break;
case COLUMN_SYSLOGMSGMSGID:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//printf(" ---------->>>> table_entry->syslogMsgMsgID: %s\n", table_entry->syslogMsgMsgID);
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
(u_char*)table_entry->syslogMsgMsgID,
strlen(table_entry->syslogMsgMsgID));
break;
case COLUMN_SYSLOGMSGSDPARAMS:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//printf(" ---------->>>> table_entry->syslogMsgSDParams: %ld\n", table_entry->syslogMsgSDParams);
snmp_set_var_typed_integer( request->requestvb, ASN_UNSIGNED,
table_entry->syslogMsgSDParams);
break;
case COLUMN_SYSLOGMSGMSG:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//printf(" ---------->>>> table_entry->syslogMsgMsg: %s\n", table_entry->syslogMsgMsg);
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
(u_char*)table_entry->syslogMsgMsg,
strlen(table_entry->syslogMsgMsg));
break;
default:
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHOBJECT);
break;
}
}
break;
}
return SNMP_ERR_NOERROR;
}
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.access_functions.conf 11358 2004-10-14 12:57:34Z dts12 $
*/
#include <stdio.h>
#include <stdlib.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "syslogMsgTable_access.h"
#include "syslogMsgTable_enums.h"
static u_long stCnt = 1;
/** returns the first data point within the syslogMsgTable table data.
Set the my_loop_context variable to the first data point structure
of your choice (from which you can find the next one). This could
be anything from the first node in a linked list, to an integer
pointer containing the beginning of an array variable.
Set the my_data_context variable to something to be returned to
you later that will provide you with the data to return in a given
row. This could be the same pointer as what my_loop_context is
set to, or something different.
The put_index_data variable contains a list of snmp variable
bindings, one for each index in your table. Set the values of
each appropriately according to the data matching the first row
and return the put_index_data variable at the end of the function.
*/
netsnmp_variable_list *
syslogMsgTable_get_first_data_point(void **my_loop_context, void **my_data_context,
netsnmp_variable_list *put_index_data,
netsnmp_iterator_info *mydata)
{
syslogMsgTable_loop_context *loopctx;
syslogMsgTable_data_context *datactx;
// netsnmp_variable_list *vptr;
loopctx = SNMP_MALLOC_TYPEDEF(syslogMsgTable_loop_context);
if (!loopctx) {
printf("Error: get_first_data_point: has no space to allocate loopctx\n");
return NULL;
}
*my_loop_context = loopctx;
/*
datactx = SNMP_MALLOC_TYPEDEF(syslogMsgTable_data_context);
if (!datactx) {
printf("get_first_data_point: has no space to allocate datactx\n");
return NULL;
}
*my_data_context = datactx;
*/
filep = fopen("/var/log/syslog.my","r");
if (!filep) {
//free(loopctx);
DEBUGMSGTL(("syslogTable/load","I'm in syslogTable_get_first_data_point ---- return NULL\n"));
return NULL;
}
DEBUGMSGTL(("syslogTable/load","I'm in syslogTable_get_first_data_point\n"));
return syslogMsgTable_get_next_data_point(my_loop_context,
my_data_context,
put_index_data,
mydata);
}
/** functionally the same as syslogMsgTable_get_first_data_point, but
my_loop_context has already been set to a previous value and should
be updated to the next in the list. For example, if it was a
linked list, you might want to cast it to your local data type and
then return my_loop_context->next. The my_data_context pointer
should be set to something you need later and the indexes in
put_index_data updated again. */
netsnmp_variable_list *
syslogMsgTable_get_next_data_point(void **my_loop_context, void **my_data_context,
netsnmp_variable_list *put_index_data,
netsnmp_iterator_info *mydata)
{
syslogMsgTable_loop_context *loopctx = (syslogMsgTable_loop_context *)*my_loop_context;
syslogMsgTable_data_context *datactx = (syslogMsgTable_data_context *)*my_data_context;
netsnmp_variable_list *idx = put_index_data;
char tempString[1024];
char * tempStr;
uint32_t uiLen;
uint32_t uiCnt, uiSDCnt, uiTemp;
uint32_t uiFacSec, uiVersion;
char strTimeStamp[64];
char strHostName[64];
char strAppName[64];
char strProcID[32];
char strMsgID[32];
char strSDParams[128];
char * strMsg;
char strMonth[4];
char strDay[3];
char strTime[36];
uint32_t uiPos;
if (!loopctx)
return NULL;
DEBUGMSGTL(("syslogTable/load","I'm in syslogTable_get_second_point\n"));
if(filep) {
// if haven't reached the end of buffer
//if (!loopctx->cPtr) {
// read into a big buffer at once. If no more data to read, then return immediately.
if (!fgets(cBuffer, sizeof(cBuffer), filep)) //???
{
DEBUGMSGTL(("syslogTable/load","I'm in syslogTable_get_second_point at EOF... return NULL \n"));
fclose(filep); // remove commmentation after debug passed
filep = NULL; // remove commentation after...
return NULL;
}
//printf(">cBuffer read in: %s \n\n", cBuffer);
// adjust log file pointer: rewind to position of last newline character
//uiPos = strlen(cBuffer);
//fseek(filep, uiPos, SEEK_CUR);
// move pointer inside buffer
//loopctx->cPtr = cBuffer;
// section a line and analyze by string match
//tempPos = strtok(loopctx->cPtr, "\n");
//uiLen = uiPos - 1; //tempPos - loopctx->cPtr;
uiCnt = uiSDCnt = 0;
uiLen = strlen(cBuffer);
// scan syslog header
strncpy(tempString, cBuffer, uiLen);
tempString[uiLen-1] = '\0'; // overwrite '\n' at the end of line
//printf(">tempString uiLen: %d (%s) \n", uiLen, tempString);
uiCnt = sscanf(tempString, "<%u>%u %s %s %s %s %s %s", \
&uiFacSec, \
&uiVersion, \
strTimeStamp, \
strHostName, \
strAppName, \
strProcID, \
strMsgID, \
strSDParams);
//printf(">String dissembled at first sscanf: %d, %d: %s, %s, %s, %s, %s, %s\n", \
uiFacSec, \
uiVersion, \
strTimeStamp, \
strHostName, \
strAppName, \
strProcID, \
strMsgID, \
strSDParams);
if (uiCnt == 8 ) // match successfully - It is a RFC5424 syslog message
{
loopctx->syslogMsgFacility = uiFacSec/8;
loopctx->syslogMsgSeverity = uiFacSec % 8;
loopctx->syslogMsgVersion = uiVersion;
strcpy(loopctx->syslogMsgTimeStamp, strTimeStamp);
strcpy(loopctx->syslogMsgHostName, strHostName);
strcpy(loopctx->syslogMsgAppName, strAppName);
strcpy(loopctx->syslogMsgProcID, strProcID);
strcpy(loopctx->syslogMsgMsgID, strMsgID);
if (strcmp(strSDParams, "-") != 0) // "-" means nothing.
{
tempStr = tempString;
for (uiTemp = 0, uiSDCnt = 0; uiTemp != 0; ) {
uiTemp = sscanf(tempStr, "[%*s]");
if (uiTemp == EOF || uiTemp == 0)
break;
uiSDCnt++;
tempStr = strchr(tempStr, ']');
}
}
loopctx->syslogMsgSDParams = uiSDCnt;
// read the rest as log message
strMsg = strtok(tempString, " ");
for (uiTemp = 0; uiTemp < 8; uiTemp++) // skip enough space ???
strMsg = strtok(NULL, " ");
strcpy(loopctx->syslogMsgMsg, strMsg);
}
else // unmatch - It is a customized log message
{
uiCnt = sscanf(tempString, "%s %s %s %s %s:", \
strMonth, \
strDay, \
strTime, \
strHostName, \
strAppName);
//printf(" >> String dissembled uiCnt(%d): (%s), (%s), (%s), (%s), (%s)\n", uiCnt, strMonth, strDay, strTime, strHostName, strAppName);
if (uiCnt < 5)
{
printf("Warning: Not a standard RFC5424 syslog string, bypassed it.\n");
return NULL;
}
else
{
loopctx->syslogMsgFacility = 0;
loopctx->syslogMsgSeverity = 0;
loopctx->syslogMsgVersion = 0;
// construct TimeStamp
loopctx->syslogMsgTimeStamp[0] = 0x7; loopctx->syslogMsgTimeStamp[1] = 0xd0; // Assumption year 2000
loopctx->syslogMsgTimeStamp[2] = '\0';
strcat(loopctx->syslogMsgTimeStamp, HexStringOfMonth(loopctx, strMonth));
strcat(loopctx->syslogMsgTimeStamp, HexStringOfDay(loopctx, strDay));
strcat(loopctx->syslogMsgTimeStamp, HexStringOfTime(loopctx, strTime));
//printTS(loopctx->syslogMsgTimeStamp); //???
// read HostName and AppName
strcpy(loopctx->syslogMsgHostName, strHostName);
strcpy(loopctx->syslogMsgAppName, strAppName);
// read the rest as log message
strMsg = tempString + strlen(strMonth) + strlen(strDay) + strlen(strTime) \
+ strlen(strHostName) + strlen(strAppName) + 6; // 6 additional spaces plus colon
strcpy(loopctx->syslogMsgMsg, strMsg);
printf(" ->>> loopctx->HostName, ->AppName, ->MsgMsg are:\n\t %s,\n\t %s,\n\t %s\n", \
loopctx->syslogMsgHostName, \
loopctx->syslogMsgAppName, \
loopctx->syslogMsgMsg);
}
} // customized log message
//} // if(!loopctx->cPtr)
//loopctx->iLineNo++;
loopctx->syslogMsgIndex = stCnt++;
//printf(" --->> loopctx->syslogMsgIndex: %d\n", loopctx->syslogMsgIndex);
snmp_set_var_typed_value(idx, ASN_UNSIGNED, (u_char *)&(loopctx->syslogMsgIndex), sizeof(loopctx->syslogMsgIndex));
idx = idx->next_variable;
*my_data_context = (void *)loopctx;
*my_loop_context = (void *)loopctx; //->next;
return put_index_data;
} // while(!loopctx->filep)
/* we're out of data */
my_loop_context = NULL;
return NULL;
}
/** Create a data_context for non-existent rows that SETs are performed on.
* return a void * pointer which will be passed to subsequent get_XXX
* and set_XXX functions for data retrival and modification during
* this SET request.
*
* The indexes are encoded (in order) into the index_data pointer,
* and the column object which triggered the row creation is available
* via the column parameter, if it would be helpful to use that information.
*/
void *
syslogMsgTable_create_data_context(netsnmp_variable_list *index_data, int column) {
syslogMsgTable_data_context *datactx = SNMP_MALLOC_TYPEDEF(syslogMsgTable_data_context);
if (!datactx)
return NULL;
DEBUGMSGTL(("syslogTable/load","I'm in _create_data_context\n"));
datactx->syslogMsgIndex = *(index_data->val.integer);
return datactx;
}
void*
syslogMsgTable_make_data_context(void* psm_loop_context, netsnmp_iterator_info *mydata)
{
syslogMsgTable_loop_context *loopctx = psm_loop_context;
syslogMsgTable_data_context *datactx = SNMP_MALLOC_TYPEDEF(syslogMsgTable_data_context);
if (!datactx)
return NULL;
DEBUGMSGTL(("syslogTable/load",">>>>>>>>>>>>>>>>>>>>>>>I'm in _MakeDataContext\n"));
datactx->syslogMsgFacility = loopctx->syslogMsgFacility;
datactx->syslogMsgSeverity = loopctx->syslogMsgSeverity;
datactx->syslogMsgVersion = loopctx->syslogMsgVersion;
strcpy(datactx->syslogMsgTimeStamp, loopctx->syslogMsgTimeStamp);
strcpy(datactx->syslogMsgHostName, loopctx->syslogMsgHostName);
strcpy(datactx->syslogMsgAppName, loopctx->syslogMsgAppName);
strcpy(datactx->syslogMsgProcID, loopctx->syslogMsgProcID);
strcpy(datactx->syslogMsgMsgID, loopctx->syslogMsgMsgID);
datactx->syslogMsgSDParams = loopctx->syslogMsgSDParams;
strcpy(datactx->syslogMsgMsg, loopctx->syslogMsgMsg);
datactx->syslogMsgIndex = loopctx->syslogMsgIndex;
datactx->iLineNo = loopctx->iLineNo;
return datactx;
}
void
syslogMsgTable_data_free(void *datactx, netsnmp_iterator_info *iinfo)
{
/*
printf("syslogMsgTable_data_free: free datactx\n");
if(!datactx)
free(datactx);
*/
}
void
syslogMsgTable_loop_free(void *loopctx, netsnmp_iterator_info *iinfo)
{
/*
syslogMsgTable_loop_context *plpctx = loopctx;
printf("syslogMsgTable_loop_free: free loopctx\n");
if(!loopctx) {
printf("syslogMsgTable_loop_free =======>>>>>> commits free loopctx\n");
//plpctx = plpctx->next;
free(loopctx);
//loopctx = plpctx;
}
*/
stCnt = 1;
printf("syslogMsgTable_loop_free =======>>>>>> stCnt: %d\n", stCnt);
}
/** If the implemented set_* functions don't operate directly on the
real-live data (which is actually recommended), then this function
can be used to take a given my_data_context pointer and "commit" it
to whereever the modified data needs to be put back to. For
example, if this was a routing table you could publish the modified
routes back into the kernel at this point.
new_or_del will be set to 1 if new, or -1 if it should be deleted
or 0 if it is just a modification of an existing row.
If you free the data yourself, make sure to *my_data_context = NULL */
int
syslogMsgTable_commit_row(void **my_data_context, int new_or_del)
{
/** Add any necessary commit code here */
/* */
/* return no errors. And there shouldn't be any!!! Ever!!! You
should have checked the values long before this. */
return SNMP_ERR_NOERROR;
}
/* return hex string of Month, as required by RFC5424 standard */
char * HexStringOfMonth(syslogMsgTable_loop_context *pctx, char * strMonth)
{
if(!strcmp(strMonth, "Jan")) strRet[0] = 0x1;
else if(!strcmp(strMonth, "Feb")) strRet[0] = 0x2;
else if(!strcmp(strMonth, "Mar")) strRet[0] = 0x3;
else if(!strcmp(strMonth, "Apr")) strRet[0] = 0x4;
else if(!strcmp(strMonth, "May")) strRet[0] = 0x5;
else if(!strcmp(strMonth, "Jun")) strRet[0] = 0x6;
else if(!strcmp(strMonth, "Jul")) strRet[0] = 0x7;
else if(!strcmp(strMonth, "Aug")) strRet[0] = 0x8;
else if(!strcmp(strMonth, "Sep")) strRet[0] = 0x9;
else if(!strcmp(strMonth, "Oct")) strRet[0] = 0xa;
else if(!strcmp(strMonth, "Nov")) strRet[0] = 0xb;
else if(!strcmp(strMonth, "Dec")) strRet[0] = 0xc;
else
{
DEBUGMSGTL(("syslogTable/load","illegal month string detected, strMonth = %s.\n",strMonth));
return NULL;
}
strRet[1] = '\0';
return strRet;
}
/* Hex String for Day */
char * HexStringOfDay(syslogMsgTable_loop_context *pctx, char * strDay)
{
strRet[0] = atoi(strDay);
strRet[1] = '\0';
return strRet;
}
/*****************************************************************************************************
*
* Input Parameter: strTime == "08:42:54"
* Behavior: Make up the missing data field
* Return Value: Hex String for Time: Hour(1d):Minute(1d):Second(1d).miniSecond(3d),(1a)(1d)(1d)
* Display Hint String: "1d:1d:1d.3d,1a1d:1d"
*/
char * HexStringOfTime(syslogMsgTable_loop_context *pctx, char * strTime)
{
int uiHour, uiMinute, uiSecond;
int iCnt;
iCnt = sscanf(strTime, "%d:%d:%d", &uiHour, &uiMinute, &uiSecond);
iCnt = sprintf(strRet, "%c%c%c%c%c%c%c%c%c", uiHour, uiMinute, uiSecond, '0', '0', '0', '+', '0', '0');
//printf(" >>>> HexStringOfTime::strTimeStamp: %s \n", strRet);
return strRet;
}
void printTS(char * strTimeStamp)
{
int i;
printf("\n >>> PrintTS::TimeStamp(len=%d): ", strlen(strTimeStamp));
for(i = 0; i < strlen(strTimeStamp); i++)
{
printf("%-#1hx ", (unsigned int)*(strTimeStamp + i));
}
printf("\n");
return;
}
/* User-defined data access functions (per column) for data in table syslogMsgTable */
/*
* NOTE:
* - these get_ routines MUST return data that will not be freed (ie,
* use static variables or persistent data). It will be copied, if
* needed, immediately after the get_ routine has been called.
* - these SET routines must copy the incoming data and can not take
* ownership of the memory passed in by the val pointer.
*/
/** return a data pointer to the data for the syslogMsgFacility column and set
ret_len to its proper size in bytes. */
long *get_syslogMsgFacility(void *data_context, size_t *ret_len) {
syslogMsgTable_data_context *datainfo = data_context;
*ret_len = sizeof(SyslogFacility);
return (long *) &datainfo->syslogMsgFacility;
}
/** return a data pointer to the data for the syslogMsgSeverity column and set
ret_len to its proper size in bytes. */
long *get_syslogMsgSeverity(void *data_context, size_t *ret_len) {
syslogMsgTable_data_context *datainfo = data_context;
*ret_len = sizeof(datainfo->syslogMsgSeverity);
return (long *) &datainfo->syslogMsgSeverity;
}
/** return a data pointer to the data for the syslogMsgVersion column and set
ret_len to its proper size in bytes. */
u_long *get_syslogMsgVersion(void *data_context, size_t *ret_len) {
syslogMsgTable_data_context *datainfo = data_context;
*ret_len = sizeof(datainfo->syslogMsgVersion);
return (u_long *) &datainfo->syslogMsgVersion;
}
/** return a data pointer to the data for the syslogMsgTimeStamp column and set
ret_len to its proper size in bytes. */
char *get_syslogMsgTimeStamp(void *data_context, size_t *ret_len) {
syslogMsgTable_data_context *datainfo = data_context;
*ret_len = strlen(datainfo->syslogMsgTimeStamp);
return (char *) &datainfo->syslogMsgTimeStamp;
}
/** return a data pointer to the data for the syslogMsgHostName column and set
ret_len to its proper size in bytes. */
char *get_syslogMsgHostName(void *data_context, size_t *ret_len) {
syslogMsgTable_data_context *datainfo = data_context;
*ret_len = strlen(datainfo->syslogMsgHostName);
return (char *) &datainfo->syslogMsgHostName;
}
/** return a data pointer to the data for the syslogMsgAppName column and set
ret_len to its proper size in bytes. */
char *get_syslogMsgAppName(void *data_context, size_t *ret_len) {
syslogMsgTable_data_context *datainfo = data_context;
*ret_len = strlen(datainfo->syslogMsgAppName);
return (char *) &datainfo->syslogMsgAppName;
}
/** return a data pointer to the data for the syslogMsgProcID column and set
ret_len to its proper size in bytes. */
char *get_syslogMsgProcID(void *data_context, size_t *ret_len) {
syslogMsgTable_data_context *datainfo = data_context;
*ret_len = strlen(datainfo->syslogMsgProcID);
return (char *) &datainfo->syslogMsgProcID;
}
/** return a data pointer to the data for the syslogMsgMsgID column and set
ret_len to its proper size in bytes. */
char *get_syslogMsgMsgID(void *data_context, size_t *ret_len) {
syslogMsgTable_data_context *datainfo = data_context;
*ret_len = strlen(datainfo->syslogMsgMsgID);
return (char *) &datainfo->syslogMsgMsgID;
}
/** return a data pointer to the data for the syslogMsgSDParams column and set
ret_len to its proper size in bytes. */
u_long *get_syslogMsgSDParams(void *data_context, size_t *ret_len) {
syslogMsgTable_data_context *datainfo = data_context;
*ret_len = sizeof(datainfo->syslogMsgSDParams);
return (u_long *) &datainfo->syslogMsgSDParams;
}
/** return a data pointer to the data for the syslogMsgMsg column and set
ret_len to its proper size in bytes. */
char *get_syslogMsgMsg(void *data_context, size_t *ret_len) {
syslogMsgTable_data_context *datainfo = data_context;
*ret_len = strlen(datainfo->syslogMsgMsg);
return (char *) &datainfo->syslogMsgMsg;
}
------------------------------------------------------------------------------
Forrester Wave Report - Recovery time is now measured in hours and minutes
not days. Key insights are discussed in the 2010 Forrester Wave Report as
part of an in-depth evaluation of disaster recovery service providers.
Forrester found the best-in-class provider in terms of services and vision.
Read this report now! http://p.sf.net/sfu/ibm-webcastpromo
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders