if (it != trapfunc_map.end()) {
//send trap message
- if (it->second(trapmsg.message) == SNMP_ERR_NOERROR)
- {
+ if (it->second(trapmsg.message) == SNMP_ERR_NOERROR) {
//set trap last date to current time
trap_last_date = time(NULL);
trapfunc_map[trapmessage::INFO_LOG] = &trap_info;
trapfunc_map[trapmessage::DEBUG_LOG] = &trap_debug;
- //init member variables
+ //init member varable
mib_collect_last_time = boost::posix_time::ptime(boost::posix_time::min_date_time);
start_date = 0;
request_last_date = 0;
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
- //set initialize flag true
+ //socket startup
+ SOCK_STARTUP;
+
+ //init l7vsAgent
+ int ret = init_agent("l7vsAgent");
+ if (ret) {
+ std::string msg("init_agent failed.");
+ Logger::putLogFatal(LOG_CAT_L7VSD_SNMPAGENT, 3, msg, __FILE__, __LINE__);
+ //set error code
+ err.setter(true, msg);
+ return;
+ }
+
+ init_snmp("l7vsAgent");
+
+ //here we initialize all the tables we're planning on supporting
+ initialize_virtual_service_table(err);
+
+ if (err) {
+ std::string msg("initialize_virtual_service_table failed.");
+ Logger::putLogFatal(LOG_CAT_L7VSD_SNMPAGENT, 4, msg, __FILE__, __LINE__);
+ //set error code
+ err.setter(true, msg);
+ return;
+ }
+
+ initialize_real_server_table(err);
+
+ if (err) {
+ std::string msg("initialize_real_server_table failed.");
+ Logger::putLogFatal(LOG_CAT_L7VSD_SNMPAGENT, 5, msg, __FILE__, __LINE__);
+ //set error code
+ err.setter(true, msg);
+ return;
+ }
+
+
+ //set initializ flag true
initialized = true;
/*-------- DEBUG LOG --------*/
{
boost::mutex::scoped_lock lock(trap_msg_queue_condition_mutex);
- //drop the message when the trap message queue is too large
- if( trap_msg_queue.size() < trap_queue_max_size.get())
- {
+ //drap the message when the trap message queue is too large
+ if ( trap_msg_queue.size() < trap_queue_max_size.get()) {
//push the message into trap message queue
trap_msg_queue.push_back(trapmessage);
/*-------- DEBUG LOG --------*/
Logger::putLogDebug(LOG_CAT_L7VSD_SNMPAGENT, 32, debugstr.str(), __FILE__, __LINE__);
}
/*------ DEBUG LOG END ------*/
- }
- else{
+ } else {
/*-------- DEBUG LOG --------*/
if (LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SNMPAGENT)) {
std::string debugstr = "function : snmpagent_impl::push_trapmessage : trap message queue is overflow.";
trap_msg_queue_condition.notify_one();
}
- }
- catch (const std::exception &e) {
+ } catch (const std::exception &e) {
std::stringstream msg;
msg << "Push trap message failed : " << e.what() << ".";
}
try {
- //socket startup
- SOCK_STARTUP;
-
- //init l7vsAgent
- int ret = init_agent("l7vsAgent");
- if (ret) {
- std::string msg("init_agent failed.");
- Logger::putLogFatal(LOG_CAT_L7VSD_SNMPAGENT, 3, msg, __FILE__, __LINE__);
- //set error code
- err.setter(true, msg);
- return;
- }
-
- init_snmp("l7vsAgent");
-
//regist snmp get item' handle
init_snmp_handles(err);
enabled = FALSE;
if (!start_flag) {
- std::string str = "snmp function has already stopped.";
+ std::string str = "snmp function has already stoped.";
Logger::putLogInfo(LOG_CAT_L7VSD_SNMPAGENT, 2, str, __FILE__, __LINE__);
return;
}
start_flag = false;
+ unregister_handler();
+
try {
trap_thread.interrupt();
process_mib_thread.join();
trap_thread.join();
- snmp_shutdown("l7vsAgent");
- shutdown_agent();
- SOCK_CLEANUP;
-
std::string str = "snmp function stop.";
Logger::putLogInfo(LOG_CAT_L7VSD_SNMPAGENT, 3, str, __FILE__, __LINE__);
*
* @retrun void
*/
- void snmpagent_impl::enable() {
+ void snmpagent_impl::enable()
+ {
Logger logger(LOG_CAT_L7VSD_SNMPAGENT, 38, "snmpagent_impl::enable", __FILE__, __LINE__);
//set snmp function enable flag
msg << "snmp function start failed.";
Logger::putLogError(LOG_CAT_L7VSD_SNMPAGENT, 7, msg.str(), __FILE__, __LINE__);
}
- }
- else {
+ } else {
std::string str = "snmp function has already started.";
Logger::putLogInfo(LOG_CAT_L7VSD_SNMPAGENT, 4, str, __FILE__, __LINE__);
}
*
* @retrun void
*/
- void snmpagent_impl::disable() {
+ void snmpagent_impl::disable()
+ {
Logger logger(LOG_CAT_L7VSD_SNMPAGENT, 39, "snmpagent_impl::disable", __FILE__, __LINE__);
//set snmp function enable flag
enabled = FALSE;
if (start_flag == true) {
stop();
- }
- else {
- std::string str = "snmp function has already stopped.";
+ } else {
+ std::string str = "snmp function has already stoped.";
Logger::putLogInfo(LOG_CAT_L7VSD_SNMPAGENT, 5, str, __FILE__, __LINE__);
}
}
* set log trap enable
* @retrun void
*/
- void snmpagent_impl::logtrap_enable() {
+ void snmpagent_impl::logtrap_enable()
+ {
Logger logger(LOG_CAT_L7VSD_SNMPAGENT, 40, "snmpagent_impl::logtrap_enable", __FILE__, __LINE__);
logtrap_enabled = TRUE;
* set log trap disable
* @retrun void
*/
- void snmpagent_impl::logtrap_disable() {
+ void snmpagent_impl::logtrap_disable()
+ {
Logger logger(LOG_CAT_L7VSD_SNMPAGENT, 41, "snmpagent_impl::logtrap_disable", __FILE__, __LINE__);
logtrap_enabled = FALSE;
/*------ DEBUG LOG END ------*/
http_stats &httpstats = static_cast<http_stats&>(base_stats);
- //clear http statistics
+ //clear http statstics
httpstats.http_requests = 0ULL;
httpstats.http_get_requests = 0ULL;
httpstats.http_post_requests = 0ULL;
}
/*!
- * set vsd information.
+ * set vsd infomation.
*
* @param[in] vsd is vsd pointer.
* @retrun void
}
/*!
- * get snmp information.
+ * get snmp infomation.
*
- * @retrun snmp_info is snmp information.
+ * @retrun snmp_info is snmp infomation.
*/
snmp_info snmpagent_impl::get_snmp_info()
{
if (start_flag == true) {
stop();
}
-
+
+ //shutdown l7vsAgent
+ snmp_shutdown("l7vsAgent");
+ shutdown_master_agent();
+ shutdown_agent();
+ SOCK_CLEANUP;
}
/*!
static const oid snmptrap_oid[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
netsnmp_table_data_set *vs_table;
netsnmp_table_data_set *rs_table;
-
+netsnmp_handler_registration *vs_table_size_handler = NULL;
+netsnmp_handler_registration *vs_table_handler = NULL;
+netsnmp_handler_registration *rs_table_handler = NULL;
+netsnmp_handler_registration *replication_handler = NULL;
/*!
- * initialize snmp scalar and table data set handles.
+ * register snmp scaler and table data set handler.
*
* @param[in] error_code& is trap error code
* @retrun void
oid l7vsVsNumber_oid[] = { 1, 3, 6, 1, 4, 1, 32132, 1, 1, 1, 1 };
oid l7vsReplicationMode_oid[] = { 1, 3, 6, 1, 4, 1, 32132, 1, 1, 1, 4 };
+ oid l7vsVsTable_oid[] = { 1, 3, 6, 1, 4, 1, 32132, 1, 1, 1, 2 };
+ oid l7vsRsTable_oid[] = { 1, 3, 6, 1, 4, 1, 32132, 1, 1, 1, 3 };
DEBUGMSGTL(("ultramonkey_l7", "init_snmp_handles\n"));
- int ret = netsnmp_register_scalar(netsnmp_create_handler_registration
- ("l7vsVsNumber", handle_get_vstable_count,
- l7vsVsNumber_oid,
- OID_LENGTH(l7vsVsNumber_oid),
- HANDLER_CAN_RONLY));
+ vs_table_size_handler = netsnmp_create_handler_registration
+ ("l7vsVsNumber", handle_get_vstable_count,
+ l7vsVsNumber_oid,
+ OID_LENGTH(l7vsVsNumber_oid),
+ HANDLER_CAN_RONLY);
+
+ int ret = netsnmp_register_scalar(vs_table_size_handler);
if ( ret ) {
std::string msg("netsnmp_register_scalar failed.");
- Logger::putLogFatal(LOG_CAT_L7VSD_SNMPAGENT, 4, msg, __FILE__, __LINE__);
+ Logger::putLogError(LOG_CAT_L7VSD_SNMPAGENT, 68, msg, __FILE__, __LINE__);
//set error code
err.setter(true, msg);
return;
}
- ret = netsnmp_register_scalar(netsnmp_create_handler_registration
- ("l7vsReplicationMode",
- handle_get_rep_state,
- l7vsReplicationMode_oid,
- OID_LENGTH(l7vsReplicationMode_oid),
- HANDLER_CAN_RONLY));
+ replication_handler = netsnmp_create_handler_registration
+ ("l7vsReplicationMode",
+ handle_get_rep_state,
+ l7vsReplicationMode_oid,
+ OID_LENGTH(l7vsReplicationMode_oid),
+ HANDLER_CAN_RONLY);
+
+ ret = netsnmp_register_scalar(replication_handler);
if (ret) {
std::string msg("netsnmp_register_scalar failed.");
- Logger::putLogFatal(LOG_CAT_L7VSD_SNMPAGENT, 5, msg, __FILE__, __LINE__);
+ Logger::putLogError(LOG_CAT_L7VSD_SNMPAGENT, 69, msg, __FILE__, __LINE__);
//set error code
err.setter(true, msg);
return;
}
+
+ /*
+ * registering the table with the master agent
+ */
/*
- * here we initialize all the tables we're planning on supporting
+ * note: if you don't need a subhandler to deal with any aspects
+ * of the request, change handle_get_vstable to "NULL"
*/
- initialize_virtual_service_table(err);
+ if (vs_table) {
+ vs_table_handler = netsnmp_create_handler_registration
+ ("l7vsVsTable", handle_get_vstable,
+ l7vsVsTable_oid,
+ OID_LENGTH(l7vsVsTable_oid),
+ HANDLER_CAN_RWRITE);
+ int ret = netsnmp_register_table_data_set(vs_table_handler, vs_table, NULL);
- if (ret) return;
+ if (ret) {
+ std::string msg("netsnmp create l7vsVsTable data set failed.");
+ Logger::putLogError(LOG_CAT_L7VSD_SNMPAGENT, 24, msg, __FILE__, __LINE__);
+ //set error code
+ err.setter(true, msg);
+ return;
+ }
+ }
- initialize_real_server_table(err);
+ /*
+ * registering the table with the master agent
+ */
+ /*
+ * note: if you don't need a subhandler to deal with any aspects
+ * of the request, change handle_get_rstable to "NULL"
+ */
+ if (rs_table) {
+ rs_table_handler = netsnmp_create_handler_registration
+ ("l7vsRsTable", handle_get_rstable,
+ l7vsRsTable_oid,
+ OID_LENGTH(l7vsRsTable_oid),
+ HANDLER_CAN_RWRITE);
+ int ret = netsnmp_register_table_data_set(rs_table_handler, rs_table, NULL);
- if (ret) return;
+ if (ret) {
+ std::string msg("netsnmp create l7vsRsTable data set failed.");
+ Logger::putLogError(LOG_CAT_L7VSD_SNMPAGENT, 26, msg, __FILE__, __LINE__);
+ //set error code
+ err.setter(true, msg);
+ return;
+ }
+ }
}
/*!
switch (reqinfo->mode) {
case MODE_GET: {
- //get virtual service size
+ //get virtual serveice size
int table_size = l7vs::mibdata::get_instance().get_vs_table_size();
//set value
{
Logger logger(LOG_CAT_L7VSD_SNMPAGENT, 79, "snmpfunc::initialize_virtual_service_table", __FILE__, __LINE__);
- oid l7vsVsTable_oid[] = { 1, 3, 6, 1, 4, 1, 32132, 1, 1, 1, 2 };
-
/*
* create the table structure itself
*/
COLUMN_L7VSVSRSNUMBER,
ASN_INTEGER, 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 handle_get_vstable to "NULL"
- */
- int ret = netsnmp_register_table_data_set(netsnmp_create_handler_registration
- ("l7vsVsTable", handle_get_vstable,
- l7vsVsTable_oid,
- OID_LENGTH(l7vsVsTable_oid),
- HANDLER_CAN_RWRITE), vs_table, NULL);
-
- if (ret) {
- std::string msg("netsnmp create l7vsVsTable data set failed.");
- Logger::putLogError(LOG_CAT_L7VSD_SNMPAGENT, 24, msg, __FILE__, __LINE__);
- //set error code
- err.setter(true, msg);
- return;
- }
}
/*!
{
Logger logger(LOG_CAT_L7VSD_SNMPAGENT, 80, "snmpfunc::initialize_real_server_table", __FILE__, __LINE__);
- oid l7vsRsTable_oid[] = { 1, 3, 6, 1, 4, 1, 32132, 1, 1, 1, 3 };
-
/*
* create the table structure itself
*/
ASN_INTEGER, 0, NULL, 0,
COLUMN_L7VSRSINACTIVECONN,
ASN_INTEGER, 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 handle_get_rstable to "NULL"
- */
- int ret = netsnmp_register_table_data_set(netsnmp_create_handler_registration
- ("l7vsRsTable", handle_get_rstable,
- l7vsRsTable_oid,
- OID_LENGTH(l7vsRsTable_oid),
- HANDLER_CAN_RWRITE), rs_table, NULL);
+/*!
+ * unregister snmp handler.
+ *
+ */
+void unregister_handler()
+{
+ // unregister snmp handler
+ if (rs_table_handler && vs_table_handler && vs_table_size_handler && replication_handler) {
+ //fix memory leak for function netsnmp_register_table_data_set() start
+ //get table registration information
+ netsnmp_table_registration_info *rs_table_registration_info = netsnmp_find_table_registration_info(rs_table_handler);
+ netsnmp_table_registration_info *vs_table_registration_info = netsnmp_find_table_registration_info(vs_table_handler);
+
+ if (rs_table_registration_info) {
+ SNMP_FREE(rs_table_registration_info->indexes);
+ SNMP_FREE(rs_table_registration_info->valid_columns);
+ SNMP_FREE(rs_table_registration_info);
+ }
+ if (vs_table_registration_info) {
+ SNMP_FREE(vs_table_registration_info->indexes);
+ SNMP_FREE(vs_table_registration_info->valid_columns);
+ SNMP_FREE(vs_table_registration_info);
+ }
+ //fix memory leak for function netsnmp_register_table_data_set() end
- if (ret) {
- std::string msg("netsnmp create l7vsRsTable data set failed.");
- Logger::putLogError(LOG_CAT_L7VSD_SNMPAGENT, 26, msg, __FILE__, __LINE__);
- //set error code
- err.setter(true, msg);
- return;
+ netsnmp_unregister_handler(rs_table_handler);
+ netsnmp_unregister_handler(vs_table_handler);
+ netsnmp_unregister_handler(vs_table_size_handler);
+ netsnmp_unregister_handler(replication_handler);
}
-
}
/*!
}
break;
case MODE_GETNEXT:
- break;
+ break;
default:
/*
* we should never get here, so this is a really bad error
}
break;
case MODE_GETNEXT:
- break;
+ break;
default:
/*
* we should never get here, so this is a really bad error