本文整理汇总了C++中snmp_log函数的典型用法代码示例。如果您正苦于以下问题:C++ snmp_log函数的具体用法?C++ snmp_log怎么用?C++ snmp_log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snmp_log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _mfd_ipv4InterfaceTable_get_values
int
_mfd_ipv4InterfaceTable_get_values(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *agtreq_info,
netsnmp_request_info *requests)
{
ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
netsnmp_container_table_row_extract(requests);
netsnmp_table_request_info *tri;
u_char *old_string;
void (*dataFreeHook) (void *);
int rc;
DEBUGMSGTL(("internal:ipv4InterfaceTable:_mfd_ipv4InterfaceTable_get_values", "called\n"));
netsnmp_assert(NULL != rowreq_ctx);
for (; requests; requests = requests->next) {
/*
* save old pointer, so we can free it if replaced
*/
old_string = requests->requestvb->val.string;
dataFreeHook = requests->requestvb->dataFreeHook;
if (NULL == requests->requestvb->val.string) {
requests->requestvb->val.string = requests->requestvb->buf;
requests->requestvb->val_len =
sizeof(requests->requestvb->buf);
} else if (requests->requestvb->buf ==
requests->requestvb->val.string) {
if (requests->requestvb->val_len !=
sizeof(requests->requestvb->buf))
requests->requestvb->val_len =
sizeof(requests->requestvb->buf);
}
/*
* get column data
*/
tri = netsnmp_extract_table_info(requests);
if (NULL == tri)
continue;
rc = _ipv4InterfaceTable_get_column(rowreq_ctx,
requests->requestvb,
tri->colnum);
if (rc) {
if (MFD_SKIP == rc) {
requests->requestvb->type = SNMP_NOSUCHINSTANCE;
rc = SNMP_ERR_NOERROR;
}
} else if (NULL == requests->requestvb->val.string) {
snmp_log(LOG_ERR, "NULL varbind data pointer!\n");
rc = SNMP_ERR_GENERR;
}
if (rc)
netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));
/*
* if the buffer wasn't used previously for the old data (i.e. it
* was allcoated memory) and the get routine replaced the pointer,
* we need to free the previous pointer.
*/
if (old_string && (old_string != requests->requestvb->buf) &&
(requests->requestvb->val.string != old_string)) {
if (dataFreeHook)
(*dataFreeHook) (old_string);
else
free(old_string);
}
} /* for results */
return SNMP_ERR_NOERROR;
} /* _mfd_ipv4InterfaceTable_get_values */
示例2: cltproTable_container_load
/**
* load initial data
*
* TODO:350:M: Implement cltproTable data load
* This function will also be called by the cache helper to load
* the container again (after the container free function has been
* called to free the previous contents).
*
* @param container container to which items should be inserted
*
* @retval MFD_SUCCESS : success.
* @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
* @retval MFD_ERROR : other error.
*
* This function is called to load the index(es) (and data, optionally)
* for the every row in the data set.
*
* @remark
* While loading the data, the only important thing is the indexes.
* If access to your data is cheap/fast (e.g. you have a pointer to a
* structure in memory), it would make sense to update the data here.
* If, however, the accessing the data invovles more work (e.g. parsing
* some other existing data, or peforming calculations to derive the data),
* then you can limit yourself to setting the indexes and saving any
* information you will need later. Then use the saved information in
* cltproTable_row_prep() for populating data.
*
* @note
* If you need consistency between rows (like you want statistics
* for each row to be from the same time frame), you should set all
* data here.
*
*/
int
cltproTable_container_load(netsnmp_container *container)
{
cltproTable_rowreq_ctx *rowreq_ctx;
long cltproTid;
st_dbsCltConf row;
DEBUGMSGTL(("verbose:cltproTable:cltproTable_container_load","called\n"));
//printf("-->cltproTable_container_load()\n");
for( cltproTid=1; cltproTid<=MAX_CLT_AMOUNT_LIMIT; cltproTid++ )
{
/* 从数据库获取数据*/
if( CMM_SUCCESS != dbsGetCltconf(dbsdev, cltproTid, &row) )
{
dbs_sys_log(dbsdev, DBS_LOG_ERR, "cltproTable_container_load dbsGetCltconf failed");
return MFD_RESOURCE_UNAVAILABLE;
}
rowreq_ctx = cltproTable_allocate_rowreq_ctx(NULL);
if (NULL == rowreq_ctx)
{
snmp_log(LOG_ERR, "memory allocation failed\n");
return MFD_RESOURCE_UNAVAILABLE;
}
if(MFD_SUCCESS != cltproTable_indexes_set(rowreq_ctx, cltproTid))
{
snmp_log(LOG_ERR,"error setting index while loading " "cltproTable data.\n");
cltproTable_release_rowreq_ctx(rowreq_ctx);
continue;
}
rowreq_ctx->data.cltproIndex = row.id;
rowreq_ctx->data.cltproBase = row.col_base;
rowreq_ctx->data.cltproMacLimit = row.col_macLimit;
rowreq_ctx->data.cltproCuRate = row.col_curate;
rowreq_ctx->data.cltproCdRate = row.col_cdrate;
rowreq_ctx->data.cltproLoagTime = row.col_loagTime;
rowreq_ctx->data.cltproReagTime = row.col_reagTime;
rowreq_ctx->data.cltproIgmpPri = row.col_igmpPri;
rowreq_ctx->data.cltproUnicastPri = row.col_unicastPri;
rowreq_ctx->data.cltproAvsPri = row.col_avsPri;
rowreq_ctx->data.cltproMcastPri = row.col_mcastPri;
rowreq_ctx->data.cltproTbaPriSts = row.col_tbaPriSts?TRUTHVALUE_TRUE:TRUTHVALUE_FALSE;
rowreq_ctx->data.cltproCosPriSts = row.col_cosPriSts?TRUTHVALUE_TRUE:TRUTHVALUE_FALSE;
rowreq_ctx->data.cltproCos0pri = row.col_cos0pri;
rowreq_ctx->data.cltproCos1pri = row.col_cos1pri;
rowreq_ctx->data.cltproCos2pri = row.col_cos2pri;
rowreq_ctx->data.cltproCos3pri = row.col_cos3pri;
rowreq_ctx->data.cltproCos4pri = row.col_cos4pri;
rowreq_ctx->data.cltproCos5pri = row.col_cos5pri;
rowreq_ctx->data.cltproCos6pri = row.col_cos6pri;
rowreq_ctx->data.cltproCos7pri = row.col_cos7pri;
rowreq_ctx->data.cltproTosPriSts = row.col_tosPriSts?TRUTHVALUE_TRUE:TRUTHVALUE_FALSE;
rowreq_ctx->data.cltproTos0pri = row.col_tos0pri;
rowreq_ctx->data.cltproTos1pri = row.col_tos1pri;
rowreq_ctx->data.cltproTos2pri = row.col_tos2pri;
rowreq_ctx->data.cltproTos3pri = row.col_tos3pri;
rowreq_ctx->data.cltproTos4pri = row.col_tos4pri;
rowreq_ctx->data.cltproTos5pri = row.col_tos5pri;
rowreq_ctx->data.cltproTos6pri = row.col_tos6pri;
rowreq_ctx->data.cltproTos7pri = row.col_tos7pri;
rowreq_ctx->data.cltproCommit = TRUTHVALUE_FALSE;
rowreq_ctx->data.cltproRowStatus = row.col_row_sts?TRUTHVALUE_TRUE:TRUTHVALUE_FALSE;
CONTAINER_INSERT(container, rowreq_ctx);
}
//.........这里部分代码省略.........
示例3: netsnmp_instance_num_file_handler
//.........这里部分代码省略.........
&it);
fclose(nfi->filep);
nfi->filep = NULL;
if (rc != 1) {
netsnmp_set_request_error(reqinfo, requests,
SNMP_NOSUCHINSTANCE);
return SNMP_ERR_NOERROR;
}
snmp_set_var_typed_value(requests->requestvb, nfi->type,
(u_char *) &it, sizeof(it));
break;
/*
* SET requests. Should only get here if registered RWRITE
*/
#ifndef NETSNMP_NO_WRITE_SUPPORT
case MODE_SET_RESERVE1:
netsnmp_assert(NULL == nfi->filep);
if (requests->requestvb->type != nfi->type)
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_WRONGTYPE);
break;
case MODE_SET_RESERVE2:
netsnmp_assert(NULL == nfi->filep);
nfi->filep = fopen(nfi->file_name, "w+");
if (NULL == nfi->filep) {
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_NOTWRITABLE);
return SNMP_ERR_NOERROR;
}
/*
* store old info for undo later
*/
if (fscanf(nfi->filep, (nfi->type == ASN_INTEGER) ? "%ld" : "%lu",
&it) != 1) {
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
return SNMP_ERR_NOERROR;
}
it_save = netsnmp_memdup(&it, sizeof(u_long));
if (it_save == NULL) {
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
return SNMP_ERR_NOERROR;
}
netsnmp_request_add_list_data(requests,
netsnmp_create_data_list
(INSTANCE_HANDLER_NAME, it_save,
&free_wrapper));
break;
case MODE_SET_ACTION:
/*
* update current
*/
DEBUGMSGTL(("helper:instance", "updated %s -> %ld\n", nfi->file_name,
*(requests->requestvb->val.integer)));
it = *(requests->requestvb->val.integer);
rewind(nfi->filep); /* rewind to make sure we are at the beginning */
rc = fprintf(nfi->filep, (nfi->type == ASN_INTEGER) ? "%ld" : "%lu",
it);
if (rc < 0) {
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_GENERR);
return SNMP_ERR_NOERROR;
}
break;
case MODE_SET_UNDO:
it =
*((u_int *) netsnmp_request_get_list_data(requests,
INSTANCE_HANDLER_NAME));
rc = fprintf(nfi->filep, (nfi->type == ASN_INTEGER) ? "%ld" : "%lu",
it);
if (rc < 0)
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_UNDOFAILED);
/* FALL THROUGH */
case MODE_SET_COMMIT:
case MODE_SET_FREE:
if (NULL != nfi->filep) {
fclose(nfi->filep);
nfi->filep = NULL;
}
break;
#endif /* NETSNMP_NO_WRITE_SUPPORT */
default:
snmp_log(LOG_ERR,
"netsnmp_instance_num_file_handler: illegal mode\n");
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
return SNMP_ERR_NOERROR;
}
if (handler->next && handler->next->access_method)
return netsnmp_call_next_handler(handler, reginfo, reqinfo,
requests);
return SNMP_ERR_NOERROR;
}
示例4: initialize_table_saHpiSensorThdUpMinorTable
/************************************************************
*
* Initialize the saHpiSensorThdUpMinorTable table by defining its contents and how it's structured
*/
void
initialize_table_saHpiSensorThdUpMinorTable(void)
{
netsnmp_table_registration_info *table_info;
DEBUGMSGTL ((AGENT, "initialize_table_saHpiSensorThdUpMinorTable, called\n"));
if (my_handler) {
snmp_log(LOG_ERR, "initialize_table_saHpiSensorThdUpMinorTable_handler called again\n");
return;
}
memset(&cb, 0x00, sizeof(cb));
/** create the table structure itself */
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
/* if your table is read only, it's easiest to change the
HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */
my_handler = netsnmp_create_handler_registration("saHpiSensorThdUpMinorTable",
netsnmp_table_array_helper_handler,
saHpiSensorThdUpMinorTable_oid,
saHpiSensorThdUpMinorTable_oid_len,
HANDLER_CAN_RWRITE);
if (!my_handler || !table_info) {
snmp_log(LOG_ERR, "malloc failed in "
"initialize_table_saHpiSensorThdUpMinorTable_handler\n");
return; /** mallocs failed */
}
/***************************************************
* Setting up the table's definition
*/
/*
* TODO: add any external indexes here.
*/
/** TODO: add code for external index(s)! */
/*
* internal indexes
*/
/** index: saHpiDomainId */
netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED);
/** index: saHpiResourceId */
netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED);
/** index: saHpiResourceIsHistorical */
netsnmp_table_helper_add_index(table_info, ASN_INTEGER);
/** index: saHpiSensorNum */
netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED);
table_info->min_column = saHpiSensorThdUpMinorTable_COL_MIN;
table_info->max_column = saHpiSensorThdUpMinorTable_COL_MAX;
/***************************************************
* registering the table with the master agent
*/
cb.get_value = saHpiSensorThdUpMinorTable_get_value;
cb.container = netsnmp_container_find("saHpiSensorThdUpMinorTable_primary:"
"saHpiSensorThdUpMinorTable:"
"table_container");
netsnmp_container_add_index(cb.container,
netsnmp_container_find("saHpiSensorThdUpMinorTable_secondary:"
"saHpiSensorThdUpMinorTable:"
"table_container"));
cb.container->next->compare = saHpiSensorThdUpMinorTable_cmp;
cb.can_set = 1;
cb.create_row = (UserRowMethod*)saHpiSensorThdUpMinorTable_create_row;
cb.duplicate_row = (UserRowMethod*)saHpiSensorThdUpMinorTable_duplicate_row;
cb.delete_row = (UserRowMethod*)saHpiSensorThdUpMinorTable_delete_row;
cb.row_copy = (Netsnmp_User_Row_Operation *)saHpiSensorThdUpMinorTable_row_copy;
cb.can_activate = (Netsnmp_User_Row_Action *)saHpiSensorThdUpMinorTable_can_activate;
cb.can_deactivate = (Netsnmp_User_Row_Action *)saHpiSensorThdUpMinorTable_can_deactivate;
cb.can_delete = (Netsnmp_User_Row_Action *)saHpiSensorThdUpMinorTable_can_delete;
cb.set_reserve1 = saHpiSensorThdUpMinorTable_set_reserve1;
cb.set_reserve2 = saHpiSensorThdUpMinorTable_set_reserve2;
cb.set_action = saHpiSensorThdUpMinorTable_set_action;
cb.set_commit = saHpiSensorThdUpMinorTable_set_commit;
cb.set_free = saHpiSensorThdUpMinorTable_set_free;
cb.set_undo = saHpiSensorThdUpMinorTable_set_undo;
DEBUGMSGTL(("initialize_table_saHpiSensorThdUpMinorTable",
"Registering table saHpiSensorThdUpMinorTable "
"as a table array\n"));
netsnmp_table_container_register(my_handler, table_info, &cb,
cb.container, 1);
}
示例5: netsnmp_table_iterator_helper_handler
/* implements the table_iterator helper */
int
netsnmp_table_iterator_helper_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
netsnmp_table_registration_info *tbl_info;
netsnmp_table_request_info *table_info = NULL;
oid coloid[MAX_OID_LEN];
size_t coloid_len;
int ret = SNMP_ERR_NOERROR;
static oid myname[MAX_OID_LEN];
size_t myname_len;
int oldmode = 0;
netsnmp_iterator_info *iinfo;
int notdone;
int hintok = 0;
netsnmp_request_info *request, *reqtmp = NULL;
netsnmp_variable_list *index_search = NULL;
netsnmp_variable_list *free_this_index_search = NULL;
void *callback_loop_context = NULL, *last_loop_context;
void *callback_data_context = NULL;
ti_cache_info *ti_info = NULL;
int request_count = 0;
netsnmp_oid_stash_node **cinfo = NULL;
netsnmp_variable_list *old_indexes = NULL, *vb;
netsnmp_table_registration_info *table_reg_info = NULL;
int i;
netsnmp_data_list *ldata = NULL;
iinfo = (netsnmp_iterator_info *) handler->myvoid;
if (!iinfo || !reginfo || !reqinfo)
return SNMP_ERR_GENERR;
tbl_info = iinfo->table_reginfo;
/*
* copy in the table registration oid for later use
*/
coloid_len = reginfo->rootoid_len + 2;
memcpy(coloid, reginfo->rootoid, reginfo->rootoid_len * sizeof(oid));
coloid[reginfo->rootoid_len] = 1; /* table.entry node */
/*
* illegally got here if these functions aren't defined
*/
if (iinfo->get_first_data_point == NULL ||
iinfo->get_next_data_point == NULL) {
snmp_log(LOG_ERR,
"table_iterator helper called without data accessor functions\n");
return SNMP_ERR_GENERR;
}
/* preliminary analysis */
switch (reqinfo->mode) {
case MODE_GET_STASH:
cinfo = netsnmp_extract_stash_cache(reqinfo);
table_reg_info = netsnmp_find_table_registration_info(reginfo);
/* XXX: move this malloc to stash_cache handler? */
reqtmp = SNMP_MALLOC_TYPEDEF(netsnmp_request_info);
if (reqtmp == NULL)
return SNMP_ERR_GENERR;
reqtmp->subtree = requests->subtree;
table_info = netsnmp_extract_table_info(requests);
netsnmp_request_add_list_data(reqtmp,
netsnmp_create_data_list
(TABLE_HANDLER_NAME,
(void *) table_info, NULL));
/* remember the indexes that were originally parsed. */
old_indexes = table_info->indexes;
break;
case MODE_GETNEXT:
for(request = requests ; request; request = request->next) {
if (request->processed)
continue;
table_info = netsnmp_extract_table_info(request);
if (table_info == NULL) {
/*
* Cleanup
*/
if (free_this_index_search)
snmp_free_varbind(free_this_index_search);
return SNMP_ERR_GENERR;
}
if (table_info->colnum < tbl_info->min_column - 1) {
/* XXX: optimize better than this */
/* for now, just increase to colnum-1 */
/* we need to jump to the lowest result of the min_column
and take it, comparing to nothing from the request */
table_info->colnum = tbl_info->min_column - 1;
} else if (table_info->colnum > tbl_info->max_column) {
request->processed = TABLE_ITERATOR_NOTAGAIN;
}
ti_info =
netsnmp_request_get_list_data(request, TI_REQUEST_CACHE);
//.........这里部分代码省略.........
示例6: saHpiWatchdogTable_get_value
//.........这里部分代码省略.........
switch(table_info->colnum) {
case COLUMN_SAHPIWATCHDOGNUM:
/** SaHpiInstrumentId = ASN_UNSIGNED */
snmp_set_var_typed_value(var, ASN_UNSIGNED,
(char*)&context->saHpiWatchdogNum,
sizeof(context->saHpiWatchdogNum) );
break;
case COLUMN_SAHPIWATCHDOGLOG:
/** TruthValue = ASN_INTEGER */
snmp_set_var_typed_value(var, ASN_INTEGER,
(char*)&context->saHpiWatchdogLog,
sizeof(context->saHpiWatchdogLog) );
break;
case COLUMN_SAHPIWATCHDOGRUNNING:
/** TruthValue = ASN_INTEGER */
snmp_set_var_typed_value(var, ASN_INTEGER,
(char*)&context->saHpiWatchdogRunning,
sizeof(context->saHpiWatchdogRunning) );
break;
case COLUMN_SAHPIWATCHDOGTIMERUSE:
/** SaHpiWatchdogTimerUse = ASN_INTEGER */
snmp_set_var_typed_value(var, ASN_INTEGER,
(char*)&context->saHpiWatchdogTimerUse,
sizeof(context->saHpiWatchdogTimerUse) );
break;
case COLUMN_SAHPIWATCHDOGTIMERACTION:
/** INTEGER = ASN_INTEGER */
snmp_set_var_typed_value(var, ASN_INTEGER,
(char*)&context->saHpiWatchdogTimerAction,
sizeof(context->saHpiWatchdogTimerAction) );
break;
case COLUMN_SAHPIWATCHDOGPRETIMERINTERRUPT:
/** SaHpiWatchdogPreTimerAction = ASN_INTEGER */
snmp_set_var_typed_value(var, ASN_INTEGER,
(char*)&context->saHpiWatchdogPretimerInterrupt,
sizeof(context->saHpiWatchdogPretimerInterrupt) );
break;
case COLUMN_SAHPIWATCHDOGPRETIMEOUTINTERVAL:
/** UNSIGNED32 = ASN_UNSIGNED */
snmp_set_var_typed_value(var, ASN_UNSIGNED,
(char*)&context->saHpiWatchdogPreTimeoutInterval,
sizeof(context->saHpiWatchdogPreTimeoutInterval) );
break;
case COLUMN_SAHPIWATCHDOGTIMERUSEEXPFLAGS:
/** OCTETSTR = ASN_OCTET_STR */
snmp_set_var_typed_value(var, ASN_OCTET_STR,
(char*)&context->saHpiWatchdogTimerUseExpFlags,
context->saHpiWatchdogTimerUseExpFlags_len );
break;
case COLUMN_SAHPIWATCHDOGTIMERINITIALCOUNT:
/** UNSIGNED32 = ASN_UNSIGNED */
snmp_set_var_typed_value(var, ASN_UNSIGNED,
(char*)&context->saHpiWatchdogTimerInitialCount,
sizeof(context->saHpiWatchdogTimerInitialCount) );
break;
case COLUMN_SAHPIWATCHDOGTIMERPRESENTCOUNT:
/** UNSIGNED32 = ASN_UNSIGNED */
snmp_set_var_typed_value(var, ASN_UNSIGNED,
(char*)&context->saHpiWatchdogTimerPresentCount,
sizeof(context->saHpiWatchdogTimerPresentCount) );
break;
case COLUMN_SAHPIWATCHDOGTIMERRESET:
/** TruthValue = ASN_INTEGER */
snmp_set_var_typed_value(var, ASN_INTEGER,
(char*)&context->saHpiWatchdogTimerReset,
sizeof(context->saHpiWatchdogTimerReset) );
break;
case COLUMN_SAHPIWATCHDOGOEM:
/** UNSIGNED32 = ASN_UNSIGNED */
snmp_set_var_typed_value(var, ASN_UNSIGNED,
(char*)&context->saHpiWatchdogOem,
sizeof(context->saHpiWatchdogOem) );
break;
case COLUMN_SAHPIWATCHDOGRDR:
/** RowPointer = ASN_OBJECT_ID */
snmp_set_var_typed_value(var, ASN_OBJECT_ID,
(char*)&context->saHpiWatchdogRDR,
context->saHpiWatchdogRDR_len );
break;
default: /** We shouldn't get here */
snmp_log(LOG_ERR, "unknown column in "
"saHpiWatchdogTable_get_value\n");
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
示例7: saHpiWatchdogTable_set_reserve1
//.........这里部分代码省略.........
void saHpiWatchdogTable_set_reserve1( netsnmp_request_group *rg )
{
saHpiWatchdogTable_context *row_ctx =
(saHpiWatchdogTable_context *)rg->existing_row;
saHpiWatchdogTable_context *undo_ctx =
(saHpiWatchdogTable_context *)rg->undo_info;
netsnmp_variable_list *var;
netsnmp_request_group_item *current;
int rc;
/*
* TODO: loop through columns, check syntax and lengths. For
* columns which have no dependencies, you could also move
* the value/range checking here to attempt to catch error
* cases as early as possible.
*/
for( current = rg->list; current; current = current->next ) {
var = current->ri->requestvb;
rc = SNMP_ERR_NOERROR;
switch(current->tri->colnum) {
case COLUMN_SAHPIWATCHDOGLOG:
/** TruthValue = ASN_INTEGER */
rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
sizeof(row_ctx->saHpiWatchdogLog));
break;
case COLUMN_SAHPIWATCHDOGRUNNING:
/** TruthValue = ASN_INTEGER */
rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
sizeof(row_ctx->saHpiWatchdogRunning));
break;
case COLUMN_SAHPIWATCHDOGTIMERUSE:
/** SaHpiWatchdogTimerUse = ASN_INTEGER */
rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
sizeof(row_ctx->saHpiWatchdogTimerUse));
break;
case COLUMN_SAHPIWATCHDOGTIMERACTION:
/** INTEGER = ASN_INTEGER */
rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
sizeof(row_ctx->saHpiWatchdogTimerAction));
break;
case COLUMN_SAHPIWATCHDOGPRETIMERINTERRUPT:
/** SaHpiWatchdogPreTimerAction = ASN_INTEGER */
rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
sizeof(row_ctx->saHpiWatchdogPretimerInterrupt));
break;
case COLUMN_SAHPIWATCHDOGPRETIMEOUTINTERVAL:
/** UNSIGNED32 = ASN_UNSIGNED */
rc = netsnmp_check_vb_type_and_size(var, ASN_UNSIGNED,
sizeof(row_ctx->saHpiWatchdogPreTimeoutInterval));
break;
case COLUMN_SAHPIWATCHDOGTIMERUSEEXPFLAGS:
/** OCTETSTR = ASN_OCTET_STR */
rc = netsnmp_check_vb_type_and_size(var, ASN_OCTET_STR,
sizeof(row_ctx->saHpiWatchdogTimerUseExpFlags));
break;
case COLUMN_SAHPIWATCHDOGTIMERINITIALCOUNT:
/** UNSIGNED32 = ASN_UNSIGNED */
rc = netsnmp_check_vb_type_and_size(var, ASN_UNSIGNED,
sizeof(row_ctx->saHpiWatchdogTimerInitialCount));
break;
case COLUMN_SAHPIWATCHDOGTIMERPRESENTCOUNT:
/** UNSIGNED32 = ASN_UNSIGNED */
rc = netsnmp_check_vb_type_and_size(var, ASN_UNSIGNED,
sizeof(row_ctx->saHpiWatchdogTimerPresentCount));
break;
case COLUMN_SAHPIWATCHDOGTIMERRESET:
/** TruthValue = ASN_INTEGER */
rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
sizeof(row_ctx->saHpiWatchdogTimerReset));
break;
default: /** We shouldn't get here */
rc = SNMP_ERR_GENERR;
snmp_log(LOG_ERR, "unknown column in "
"saHpiWatchdogTable_set_reserve1\n");
}
if (rc)
netsnmp_set_mode_request_error(MODE_SET_BEGIN, current->ri, rc );
rg->status = SNMP_MAX( rg->status, current->ri->status );
}
/*
* done with all the columns. Could check row related
* requirements here.
*/
}
示例8: parse_setEvent
void
parse_setEvent( const char *token, char *line )
{
char ename[MTE_STR1_LEN+1];
char buf[SPRINT_MAX_LEN];
oid name_buf[MAX_OID_LEN];
size_t name_buf_len;
long value;
int wild = 1;
struct mteEvent *entry;
char *cp;
DEBUGMSGTL(("disman:event:conf", "Parsing setEvent config... "));
memset( ename, 0, sizeof(ename));
cp = copy_nword(line, ename, MTE_STR1_LEN);
if (!cp || ename[0] == '\0') {
config_perror("syntax error: no event name");
return;
}
if (cp && *cp=='-' && *(cp+1)=='I') {
wild = 0; /* an instance assignment */
cp = skip_token( cp );
}
/*
* Parse the SET assignment in the form "OID = value"
*/
cp = copy_nword(cp, buf, SPRINT_MAX_LEN);
if ( buf[0] == '\0' ) {
config_perror("syntax error: no set OID");
return;
}
name_buf_len = MAX_OID_LEN;
if (!snmp_parse_oid(buf, name_buf, &name_buf_len)) {
snmp_log(LOG_ERR, "setEvent OID: %s\n", buf);
config_perror("unknown set OID");
return;
}
if (cp && *cp == '=') {
cp = skip_token( cp ); /* skip the '=' assignment character */
}
value = strtol( cp, NULL, 0);
/*
* If the entry has parsed successfully, then create,
* populate and activate the new event entry.
*/
entry = _find_typed_mteEvent_entry("snmpd.conf", ename, MTE_EVENT_SET);
if (!entry) {
return;
}
memcpy( entry->mteSetOID, name_buf, name_buf_len*sizeof(oid));
entry->mteSetOID_len = name_buf_len;
entry->mteSetValue = value;
if (wild)
entry->flags |= MTE_SET_FLAG_OBJWILD;
entry->mteEventActions |= MTE_EVENT_SET;
entry->flags |= MTE_EVENT_FLAG_ENABLED |
MTE_EVENT_FLAG_ACTIVE |
MTE_EVENT_FLAG_FIXED |
MTE_EVENT_FLAG_VALID;
return;
}
示例9: netsnmp_mem_arch_load
/*
* Load the latest memory usage statistics
*/
int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) {
struct pst_static pst;
struct pst_dynamic psd;
netsnmp_memory_info *mem;
long total_swap = 0;
long free_swap = 0;
long size = 0;
/*
* Retrieve the memory information from the underlying O/S...
*/
if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1) {
snmp_log(LOG_ERR, "memory_hpux: pstat_getstatic failed!\n");
return -1;
}
if (pstat_getdynamic(&psd, sizeof(psd), (size_t) 1, 0) == -1) {
snmp_log(LOG_ERR, "memory_hpux: pstat_getdynamic failed!\n");
return -1;
}
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 1 );
if (!mem) {
snmp_log_perror("No Memory info entry");
} else {
if (!mem->descr)
mem->descr = strdup( "Physical memory" );
mem->units = pst.page_size;
mem->size = pst.physical_memory;
mem->free = psd.psd_free;
mem->other = -1;
}
get_swapinfo(&total_swap, &free_swap, &size);
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 1 );
if (!mem) {
snmp_log_perror("No Swap info entry");
} else {
if (!mem->descr)
mem->descr = strdup( "Swap space (total)" );
mem->units = size;
mem->size = total_swap;
mem->free = free_swap;
mem->other = -1;
}
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_STEXT, 1 );
if (!mem) {
snmp_log_perror("No Swap text entry");
} else {
if (!mem->descr)
mem->descr = strdup( "Swapped text pages" );
mem->units = pst.page_size;
mem->size = psd.psd_vmtxt;
mem->free = psd.psd_avmtxt;
mem->other = -1;
}
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_RTEXT, 1 );
if (!mem) {
snmp_log_perror("No real text entry");
} else {
if (!mem->descr)
mem->descr = strdup( "Real text pages" );
mem->units = pst.page_size;
mem->size = psd.psd_rmtxt;
mem->free = psd.psd_armtxt;
mem->other = -1;
}
/*
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_MISC, 1 );
if (!mem) {
snmp_log_perror("No Buffer, etc info entry");
} else {
mem->units = 1024;
mem->size = -1;
mem->free = (pst.page_size/1024)*psd.psd_free + swap.free_swap;
mem->other = -1;
}
*/
return 0;
}
示例10: pcapFilterTable_handler
/** handles requests for the pcapFilterTable table */
int pcapFilterTable_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;
netsnmp_variable_list *var = NULL;
struct filter *filter = NULL;
for (request = requests; request; request = request->next)
{
if (request->processed) continue;
if (NULL == (filter = (struct filter*) netsnmp_extract_iterator_context (request)))
{
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
continue;
}
if (NULL == (table_info = netsnmp_extract_table_info (request)))
{
continue;
}
/* // Sanity checking.
if (*table_info->indexes->val.integer != *index)
{
snmp_log (LOG_ERR, "pcapFilterTable_handler(): very odd mismatch of indicies (%ld, %ld).\n",
*table_info->indexes->val.integer, *index);
continue;
}
*/
var = request->requestvb; // caching for brevity.
if (MODE_GET != reqinfo->mode)
{
snmp_log (LOG_ERR, "pcapFilterTable_handler(), unsupported mode '%d'\n", reqinfo->mode);
continue;
}
// fprintf (stderr, "snmp GET for %s, %d\n", filter->name, table_info->colnum);
struct device *device = filter->parent_device; // For brevity.
switch (table_info->colnum)
{
case COLUMN_IFDESCR:
netsnmp_set_var_string (var, device->dev_name);
break;
case COLUMN_FLTDESCR:
netsnmp_set_var_string (var, filter->name);
break;
case COLUMN_FLTBPF:
netsnmp_set_var_string (var, filter->bpf_text);
break;
case COLUMN_FLTPACKETS:
netsnmp_set_var_counter64 (var, &(filter->packets));
break;
case COLUMN_FLTBYTES:
netsnmp_set_var_counter64 (var, &(filter->bytes));
break;
case COLUMN_FLTTERMINAL:
netsnmp_set_var_gauge (var, filter->terminal);
break;
default:
netsnmp_set_request_error (reqinfo, request, SNMP_NOSUCHOBJECT);
break;
}
}
return SNMP_ERR_NOERROR;
}
示例11: parse_notificationEvent
void
parse_notificationEvent( const char *token, char *line )
{
char ename[MTE_STR1_LEN+1];
char buf[SPRINT_MAX_LEN];
oid name_buf[MAX_OID_LEN];
size_t name_buf_len;
struct mteEvent *entry;
struct mteObject *object;
int wild = 1;
int idx = 0;
char *cp;
#ifndef NETSNMP_DISABLE_MIB_LOADING
struct tree *tp;
#endif
struct varbind_list *var;
DEBUGMSGTL(("disman:event:conf", "Parsing notificationEvent config\n"));
/*
* The event name could be used directly to index the mteObjectsTable.
* But it's quite possible that the same name could also be used to
* set up a mteTriggerTable entry (with trigger-specific objects).
*
* To avoid such a clash, we'll add a prefix ("_E").
*/
memset(ename, 0, sizeof(ename));
ename[0] = '_';
ename[1] = 'E';
cp = copy_nword(line, ename+2, MTE_STR1_LEN-2);
if (!cp || ename[2] == '\0') {
config_perror("syntax error: no event name");
return;
}
/*
* Parse the notification OID field ...
*/
cp = copy_nword(cp, buf, SPRINT_MAX_LEN);
if ( buf[0] == '\0' ) {
config_perror("syntax error: no notification OID");
return;
}
name_buf_len = MAX_OID_LEN;
if (!snmp_parse_oid(buf, name_buf, &name_buf_len)) {
snmp_log(LOG_ERR, "notificationEvent OID: %s\n", buf);
config_perror("unknown notification OID");
return;
}
/*
* ... and the relevant object/instances.
*/
if ( cp && *cp=='-' && *(cp+1)=='m' ) {
#ifdef NETSNMP_DISABLE_MIB_LOADING
config_perror("Can't use -m if MIB loading is disabled");
return;
#else
/*
* Use the MIB definition to add the standard
* notification payload to the mteObjectsTable.
*/
cp = skip_token( cp );
tp = get_tree( name_buf, name_buf_len, get_tree_head());
if (!tp) {
config_perror("Can't locate notification payload info");
return;
}
for (var = tp->varbinds; var; var=var->next) {
idx++;
object = mteObjects_addOID( "snmpd.conf", ename, idx,
var->vblabel, wild );
idx = object->mteOIndex;
}
#endif
}
while (cp) {
if ( *cp == '-' ) {
switch (*(cp+1)) {
case 'm':
config_perror("-m option must come first");
return;
case 'i': /* exact instance */
case 'w': /* "not-wild" (backward compatability) */
wild = 0;
break;
case 'o': /* wildcarded object */
wild = 1;
break;
default:
config_perror("unrecognised option");
return;
}
cp = skip_token( cp );
if (!cp) {
config_perror("missing parameter");
return;
}
}
idx++;
//.........这里部分代码省略.........
示例12: proxy_got_response
int
proxy_got_response(int operation, netsnmp_session * sess, int reqid,
netsnmp_pdu *pdu, void *cb_data)
{
netsnmp_delegated_cache *cache = (netsnmp_delegated_cache *) cb_data;
netsnmp_request_info *requests, *request;
netsnmp_variable_list *vars, *var;
struct simple_proxy *sp;
oid myname[MAX_OID_LEN];
size_t myname_len = MAX_OID_LEN;
cache = netsnmp_handler_check_cache(cache);
if (!cache) {
DEBUGMSGTL(("proxy", "a proxy request was no longer valid.\n"));
return SNMP_ERR_NOERROR;
}
requests = cache->requests;
sp = (struct simple_proxy *) cache->localinfo;
if (!sp) {
DEBUGMSGTL(("proxy", "a proxy request was no longer valid.\n"));
return SNMP_ERR_NOERROR;
}
switch (operation) {
case NETSNMP_CALLBACK_OP_TIMED_OUT:
/*
* WWWXXX: don't leave requests delayed if operation is
* something like TIMEOUT
*/
DEBUGMSGTL(("proxy", "got timed out... requests = %08p\n", requests));
netsnmp_handler_mark_requests_as_delegated(requests,
REQUEST_IS_NOT_DELEGATED);
netsnmp_set_request_error(cache->reqinfo, requests, /* XXXWWW: should be index = 0 */
SNMP_ERR_GENERR);
netsnmp_free_delegated_cache(cache);
return 0;
case NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE:
vars = pdu->variables;
/*
* update the original request varbinds with the results
*/
for (var = vars, request = requests;
request && var;
request = request->next, var = var->next_variable) {
snmp_set_var_typed_value(request->requestvb, var->type,
var->val.string, var->val_len);
DEBUGMSGTL(("proxy", "got response... "));
DEBUGMSGOID(("proxy", var->name, var->name_length));
DEBUGMSG(("proxy", "\n"));
request->delegated = 0;
/*
* copy the oid it belongs to
*/
if (sp->base_len &&
(var->name_length < sp->base_len ||
snmp_oid_compare(var->name, sp->base_len, sp->base,
sp->base_len) != 0)) {
DEBUGMSGTL(("proxy", "out of registered range... "));
DEBUGMSGOID(("proxy", var->name, sp->base_len));
DEBUGMSG(("proxy", " (%d) != ", sp->base_len));
DEBUGMSGOID(("proxy", sp->base, sp->base_len));
DEBUGMSG(("proxy", "\n"));
continue;
} else if (!sp->base_len &&
(var->name_length < sp->name_len ||
snmp_oid_compare(var->name, sp->name_len, sp->name,
sp->name_len) != 0)) {
DEBUGMSGTL(("proxy", "out of registered base range...\n"));
/*
* or not if its out of our search range
*/
continue;
} else {
if (sp->base_len) {
/*
* XXX: oid size maxed?
*/
memcpy(myname, sp->name, sizeof(oid) * sp->name_len);
myname_len =
sp->name_len + var->name_length - sp->base_len;
if (myname_len > MAX_OID_LEN) {
snmp_log(LOG_WARNING,
"proxy OID return length too long.\n");
netsnmp_set_request_error(cache->reqinfo, requests,
SNMP_ERR_GENERR);
if (pdu)
snmp_free_pdu(pdu);
netsnmp_free_delegated_cache(cache);
//.........这里部分代码省略.........
示例13: proxy_handler
int
proxy_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
netsnmp_pdu *pdu;
struct simple_proxy *sp;
oid *ourname;
size_t ourlength;
netsnmp_request_info *request = requests;
DEBUGMSGTL(("proxy", "proxy handler starting, mode = %d\n",
reqinfo->mode));
switch (reqinfo->mode) {
case MODE_GET:
case MODE_GETNEXT:
case MODE_GETBULK: /* WWWXXX */
pdu = snmp_pdu_create(reqinfo->mode);
break;
case MODE_SET_COMMIT:
pdu = snmp_pdu_create(SNMP_MSG_SET);
break;
default:
snmp_log(LOG_WARNING, "unsupported mode for proxy called\n");
return SNMP_ERR_NOERROR;
}
sp = (struct simple_proxy *) handler->myvoid;
if (!pdu || !sp) {
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
return SNMP_ERR_NOERROR;
}
while (request) {
ourname = request->requestvb->name;
ourlength = request->requestvb->name_length;
if (sp->base_len > 0) {
if ((ourlength - sp->name_len + sp->base_len) > MAX_OID_LEN) {
/*
* too large
*/
snmp_log(LOG_ERR,
"proxy oid request length is too long\n");
return SNMP_ERR_NOERROR;
}
/*
* suffix appended?
*/
DEBUGMSGTL(("proxy", "length=%d, base_len=%d, name_len=%d\n",
ourlength, sp->base_len, sp->name_len));
if (ourlength > (int) sp->name_len)
memcpy(&(sp->base[sp->base_len]), &(ourname[sp->name_len]),
sizeof(oid) * (ourlength - sp->name_len));
ourlength = ourlength - sp->name_len + sp->base_len;
ourname = sp->base;
}
snmp_pdu_add_variable(pdu, ourname, ourlength,
request->requestvb->type,
request->requestvb->val.string,
request->requestvb->val_len);
request->delegated = 1;
request = request->next;
}
/*
* send the request out
*/
DEBUGMSGTL(("proxy", "sending pdu\n"));
snmp_async_send(sp->sess, pdu, proxy_got_response,
netsnmp_create_delegated_cache(handler, reginfo,
reqinfo, requests,
(void *) sp));
return SNMP_ERR_NOERROR;
}
示例14: _ipv4InterfaceTable_check_column
/*
* @internal
* Check the syntax for a particular column
*/
NETSNMP_STATIC_INLINE int
_ipv4InterfaceTable_check_column(ipv4InterfaceTable_rowreq_ctx *
rowreq_ctx, netsnmp_variable_list * var,
int column)
{
int rc = SNMPERR_SUCCESS;
DEBUGMSGTL(("internal:ipv4InterfaceTable:_ipv4InterfaceTable_check_column", "called for %d\n", column));
netsnmp_assert(NULL != rowreq_ctx);
switch (column) {
/*
* (INDEX) ipv4InterfaceIfIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H
*/
case COLUMN_IPV4INTERFACEIFINDEX:
rc = SNMP_ERR_NOTWRITABLE; /* can not change index of active row */
break;
/*
* ipv4InterfaceReasmMaxSize(2)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/R/d/h
*/
case COLUMN_IPV4INTERFACEREASMMAXSIZE:
rc = SNMP_ERR_NOTWRITABLE;
break;
/*
* ipv4InterfaceEnableStatus(3)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
*/
case COLUMN_IPV4INTERFACEENABLESTATUS:
rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
sizeof(rowreq_ctx->data.
ipv4InterfaceEnableStatus));
/*
* check that the value is one of defined enums
*/
if ((SNMPERR_SUCCESS == rc)
&& (*var->val.integer != IPV4INTERFACEENABLESTATUS_UP)
&& (*var->val.integer != IPV4INTERFACEENABLESTATUS_DOWN)
) {
rc = SNMP_ERR_WRONGVALUE;
}
if (SNMPERR_SUCCESS != rc) {
DEBUGMSGTL(("ipv4InterfaceTable:_ipv4InterfaceTable_check_column:ipv4InterfaceEnableStatus", "varbind validation failed (eg bad type or size)\n"));
} else {
rc = ipv4InterfaceEnableStatus_check_value(rowreq_ctx,
*((u_long *) var->
val.string));
if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
&& (MFD_NOT_VALID_NOW != rc)) {
snmp_log(LOG_ERR,
"bad rc %d from ipv4InterfaceEnableStatus_check_value\n",
rc);
rc = SNMP_ERR_GENERR;
}
}
break;
/*
* ipv4InterfaceRetransmitTime(4)/UNSIGNED32/ASN_UNSIGNED/u_long(u_long)//l/A/w/e/r/D/h
*/
case COLUMN_IPV4INTERFACERETRANSMITTIME:
rc = SNMP_ERR_NOTWRITABLE;
break;
default: /** We shouldn't get here */
rc = SNMP_ERR_GENERR;
snmp_log(LOG_ERR,
"unknown column %d in _ipv4InterfaceTable_check_column\n",
column);
}
return rc;
} /* _ipv4InterfaceTable_check_column */
示例15: main
int
main (int argc, char **argv)
{
int agentx_subagent = AGENT_TRUE;
int c;
int rc = 0;
SaErrorT rv = SA_OK;
SaHpiVersionT hpiVer;
SaHpiSessionIdT sessionid;
SaHpiDomainInfoT domain_info;
SaHpiBoolT run_threaded = TRUE;
pid_t child;
char * env;
/* change this if you want to be a SNMP master agent */
debug_register_tokens (AGENT);
snmp_enable_stderrlog ();
snmp_set_do_debugging (1);
while ((c = getopt (argc, argv, "fdsCx:h?")) != EOF) {
switch (c) {
case 'f':
do_fork = AGENT_TRUE;
break;
case 'd':
debug_register_tokens (AGENT);
snmp_enable_stderrlog ();
snmp_set_do_debugging (1);
break;
case 's':
do_syslog = AGENT_FALSE;
break;
case 'C':
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
NETSNMP_DS_LIB_DONT_READ_CONFIGS,
1);
break;
case 'x':
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_X_SOCKET,
optarg);
break;
case 'h':
default:
usage(argv[0]);
exit(1);
break;
}
}
if (do_syslog == AGENT_TRUE) {
snmp_enable_calllog ();
snmp_enable_syslog_ident (AGENT, LOG_DAEMON);
}
snmp_log (LOG_INFO, "Starting %s\n", version);
/* we're an agentx subagent? */
if (agentx_subagent) {
/* make us a agentx client. */
rc = netsnmp_ds_set_boolean (NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_ROLE, 1);
}
/* initialize the agent library */
rc = init_agent (AGENT);
if (rc != 0) {
snmp_log (LOG_ERR, "Could not initialize connection to SNMP daemon. \n"
"Perhaps you are running %s as non-root?\n", argv[0]);
exit (rc);
}
/* Read configuration information here, before we initialize */
snmpd_register_config_handler (TRAPS_TOKEN,
hpiSubagent_parse_config_traps,
NULL,
"hpiSubagent on/off switch for sending events upon startup");
snmpd_register_config_handler (MAX_EVENT_TOKEN,
hpiSubagent_parse_config_max_event,
NULL,
"hpiSubagent MAX number of rows for Events.");
init_snmp (AGENT);
/*
* Initialize HPI library
*/
hpiVer = saHpiVersionGet();
DEBUGMSGTL ((AGENT, "Hpi Version %d Implemented.\n", hpiVer));
//.........这里部分代码省略.........