/* * (Mostly auto-generated function) * * The *_create_row routine is called by the table handler to create a new row * for a given index. This is the first stage of the row creation process. The * *_set_reserve_* functions can be used to prevent the row from being inserted * into the table even if the row passes any preliminary checks set here. * * Returns a newly allocated kamailioSIPRegUserLookupTable_context structure (a * row in the table) if the indexes are legal. NULL will be returned otherwise. * * The function has been modified from its original form, in that it will store * the number of messages 'in' to the system, and the number of messages 'out' * of the system, that had a status code matching this rows status code, at the * time this row was created. * * This value will be used in the future to calculate the delta between now and * the time this row has been read. * */ kamailioSIPStatusCodesTable_context * kamailioSIPStatusCodesTable_create_row( netsnmp_index* hdr) { stat_var *in_status_code; stat_var *out_status_code; kamailioSIPStatusCodesTable_context * ctx = SNMP_MALLOC_TYPEDEF(kamailioSIPStatusCodesTable_context); if(!ctx) return NULL; /* The *_extract_index funtion already validates the indices, so we * don't need to do any further evaluations here. */ if(kamailioSIPStatusCodesTable_extract_index( ctx, hdr )) { if (NULL != ctx->index.oids) free(ctx->index.oids); free(ctx); return NULL; } /* The indices were already set up in the extract_index function * above. */ ctx->kamailioSIPStatusCodeIns = 0; ctx->kamailioSIPStatusCodeOuts = 0; ctx->kamailioSIPStatusCodeRowStatus = 0; /* Retrieve the index for the status code, and then assign the starting * values. The starting values will be used to calculate deltas during * the next snmpget/snmpwalk/snmptable/etc. */ int codeIndex = ctx->kamailioSIPStatusCodeValue; ctx->startingInStatusCodeValue = 0; ctx->startingOutStatusCodeValue = 0; in_status_code = get_stat_var_from_num_code(codeIndex, 0); out_status_code = get_stat_var_from_num_code(codeIndex, 1); if (in_status_code != NULL) { ctx->startingInStatusCodeValue = get_stat_val(in_status_code); } if (out_status_code != NULL) { ctx->startingOutStatusCodeValue = get_stat_val(out_status_code); } return ctx; }
/* Take care of the statistics associated with numerical codes and replies */ static inline void update_sl_reply_stat(int code) { stat_var *numerical_stat; /* If stats aren't enabled, just skip over this. */ if (!sl_enable_stats) return; /* OpenSIPS already kept track of the total number of 1xx, 2xx, replies. * There may be setups that still expect these variables to exist, so we * don't touch them */ if (code < 200 ) { update_stat( tx_1xx_rpls , 1); } else if (code<300) { update_stat( tx_2xx_rpls , 1); } else if (code<400) { update_stat( tx_3xx_rpls , 1); } else if (code<500) { update_stat( tx_4xx_rpls , 1); } else if (code<600) { update_stat( tx_5xx_rpls , 1); } else { update_stat( tx_6xx_rpls , 1); } update_stat( sent_rpls , 1); numerical_stat = get_stat_var_from_num_code(code, 1); if (numerical_stat != NULL) update_stat(numerical_stat, 1); }
/* * This function is called to handle SNMP GET requests. * * The row which this function is called with, will store a message code. The * function will retrieve the 'number of messages in' and 'number of messages * out' statistic for this particular message code from the statistics * framework. * * The function will then subtract from this value the value it was initialized * with when the row was first created. In this sense, the row shows how many * ins and how many outs have been received (With respect to the message code) * since this row was created. */ int openserSIPStatusCodesTable_get_value( netsnmp_request_info *request, netsnmp_index *item, netsnmp_table_request_info *table_info ) { stat_var *the_stat; netsnmp_variable_list *var = request->requestvb; openserSIPStatusCodesTable_context *context = (openserSIPStatusCodesTable_context *)item; /* Retrieve the statusCodeIdx so we can calculate deltas between current * values and previous values. */ int statusCodeIdx = context->openserSIPStatusCodeValue; switch(table_info->colnum) { case COLUMN_OPENSERSIPSTATUSCODEINS: context->openserSIPStatusCodeIns = 0; the_stat = get_stat_var_from_num_code(statusCodeIdx, 0); if (the_stat != NULL) { /* Calculate the Delta */ context->openserSIPStatusCodeIns = *(long *)the_stat->u.val - context->startingInStatusCodeValue; } snmp_set_var_typed_value(var, ASN_COUNTER, (unsigned char*) &context->openserSIPStatusCodeIns, sizeof(context->openserSIPStatusCodeIns)); break; case COLUMN_OPENSERSIPSTATUSCODEOUTS: context->openserSIPStatusCodeOuts = 0; the_stat = get_stat_var_from_num_code(statusCodeIdx, 1); if (the_stat != NULL) { /* Calculate the Delta */ context->openserSIPStatusCodeOuts = *(long *)the_stat->u.val - context->startingOutStatusCodeValue; } snmp_set_var_typed_value(var, ASN_COUNTER, (unsigned char*) &context->openserSIPStatusCodeOuts, sizeof(context->openserSIPStatusCodeOuts) ); break; case COLUMN_OPENSERSIPSTATUSCODEROWSTATUS: /** RowStatus = ASN_INTEGER */ snmp_set_var_typed_value(var, ASN_INTEGER, (unsigned char*) &context->openserSIPStatusCodeRowStatus, sizeof(context->openserSIPStatusCodeRowStatus) ); break; default: /** We shouldn't get here */ snmp_log(LOG_ERR, "unknown column in " "openserSIPStatusCodesTable_get_value\n"); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; }