TSG-1531 tfe 代码整理, 将多插件公用的基础代码移动到 tfe init 阶段
1.将 kafka 的初始化从 pangu init 阶段移动到 tfe init 阶段 2.将 device id 的获取从 pangu init 阶段移动到 tfe init 阶段 3.将 kafka 的配置项从 pangu.conf 移动到 tfe.conf 4.将 maat 的配置项从 pangu.conf 移动到 tfe.conf
This commit is contained in:
@@ -758,4 +758,4 @@ struct tfe_plugin doh_spec = {
|
||||
.on_session_begin = doh_on_begin,
|
||||
.on_session_data = doh_on_data,
|
||||
.on_session_end = doh_on_end};
|
||||
TFE_PLUGIN_REGISTER(doh, doh_spec)
|
||||
TFE_PLUGIN_REGISTER(DOH, doh_spec)
|
||||
@@ -276,80 +276,22 @@ static void add_dns_info_to_log(cJSON *common_obj, dns_info_t *dns_info)
|
||||
cJSON_AddNumberToObject(common_obj, "doh_sub", dns_sec);
|
||||
}
|
||||
|
||||
static const char *tfe_device_id_create(const char *profile, const char *section, void *local_logger)
|
||||
{
|
||||
int ret = -1;
|
||||
size_t device_id_size = 0;
|
||||
char *tsg_sn_file = NULL, *device_id;
|
||||
const char *device_def_id = "DFT2201925000001";
|
||||
cJSON *json = NULL, *item = NULL;
|
||||
char device_id_filepath[TFE_STRING_MAX] = {0};
|
||||
|
||||
ret = MESA_load_profile_string_def(profile, section, "device_id_filepath", device_id_filepath, sizeof(device_id_filepath), NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger, "Doh log init failed, no device_path in profile %s section %s.", profile, section);
|
||||
goto finish;
|
||||
}
|
||||
tsg_sn_file = tfe_read_file(device_id_filepath, &device_id_size);
|
||||
if (tsg_sn_file == NULL)
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger, "Doh log init failed, %s not existed.", tsg_sn_file);
|
||||
goto finish;
|
||||
}
|
||||
json = cJSON_Parse(tsg_sn_file);
|
||||
if (json == NULL)
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger, "invalid device parameter: file = %s", tsg_sn_file);
|
||||
goto finish;
|
||||
}
|
||||
item = cJSON_GetObjectItem(json, "sn");
|
||||
if (unlikely(!item || !cJSON_IsString(item)))
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger, "Invalid device parameter: %s invalid json format", tsg_sn_file);
|
||||
}
|
||||
device_id = tfe_strdup(item->valuestring);
|
||||
|
||||
cJSON_Delete(json);
|
||||
return device_id;
|
||||
finish:
|
||||
return device_def_id;
|
||||
}
|
||||
|
||||
int doh_kafka_init(const char *profile, struct doh_conf *conf)
|
||||
{
|
||||
char nic_name[64] = {0};
|
||||
char brokerlist[TFE_STRING_MAX] = {0};
|
||||
char topic_name[TFE_STRING_MAX] = {0};
|
||||
const char *section = "kafka";
|
||||
|
||||
MESA_load_profile_int_def(profile, section, "ENTRANCE_ID", &(conf->entry_id), 0);
|
||||
MESA_load_profile_int_def(profile, section, "en_sendlog", &conf->en_sendlog, 1);
|
||||
MESA_load_profile_string_def(profile, section, "NIC_NAME", nic_name, sizeof(nic_name), "eth0");
|
||||
MESA_load_profile_string_def(profile, section, "KAFKA_BROKERLIST", brokerlist, sizeof(brokerlist), "");
|
||||
MESA_load_profile_string_def(profile, section, "KAFKA_TOPIC", topic_name, sizeof(topic_name), "POLICY-DOH-LOG");
|
||||
|
||||
TFE_LOG_INFO(conf->local_logger, "Doh sendlog : %s", conf->en_sendlog ? "ENABLE" : "DISABLE");
|
||||
if (!conf->en_sendlog)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
conf->device_id = tfe_device_id_create(profile, section, conf->local_logger);
|
||||
if (!strlen(brokerlist))
|
||||
conf->device_id = (const char *)tfe_bussiness_resouce_get(DEVICE_ID);
|
||||
conf->kafka_logger = (tfe_kafka_logger_t *)tfe_bussiness_resouce_get(KAFKA_LOGGER);
|
||||
if (conf->kafka_logger && !conf->kafka_logger->enable)
|
||||
{
|
||||
TFE_LOG_ERROR(conf->local_logger, "Doh log init failed, no brokerlist in profile %s section %s.", profile, section);
|
||||
TFE_LOG_ERROR(conf->local_logger, "Doh sendlog ENABLE, but tfe kafka logger DISABLED.");
|
||||
return -1;
|
||||
}
|
||||
conf->kafka_logger = tfe_kafka_logger_create(conf->en_sendlog, nic_name, brokerlist, topic_name, conf->local_logger);
|
||||
if (conf->kafka_logger == NULL)
|
||||
{
|
||||
TFE_LOG_ERROR(conf->local_logger, "Doh kafka init failed, error to create kafka logger.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
TFE_LOG_INFO(conf->local_logger, "Doh device id : %s", conf->device_id);
|
||||
TFE_LOG_INFO(conf->local_logger, "Doh kafka topic : %s", topic_name);
|
||||
TFE_LOG_INFO(conf->local_logger, "Doh kafka brokerlist : %s", brokerlist);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <tfe_kafka_logger.h>
|
||||
#include <cache_evbase_client.h>
|
||||
#include <tfe_utils.h>
|
||||
#include <tfe_resource.h>
|
||||
|
||||
#include "pangu_logger.h"
|
||||
|
||||
@@ -14,13 +15,8 @@ struct json_spec
|
||||
struct pangu_logger
|
||||
{
|
||||
int entry_id;
|
||||
|
||||
unsigned int en_sendlog;
|
||||
unsigned int en_sendlog_meta;
|
||||
unsigned int en_sendlog_body;
|
||||
|
||||
const char *device_id;
|
||||
void* global_logger;
|
||||
void* local_logger;
|
||||
|
||||
unsigned long long send_cnt;
|
||||
@@ -45,101 +41,29 @@ enum _log_action //Bigger action number is prior.
|
||||
__LG_ACTION_MAX
|
||||
};
|
||||
|
||||
static const char* tfe_device_id_create(const char* profile, const char* section, void* local_logger)
|
||||
{
|
||||
int ret=-1;
|
||||
size_t device_id_size=0;
|
||||
char *tsg_sn_file=NULL, *device_id;
|
||||
const char *device_def_id = "DFT2201925000001";
|
||||
cJSON *json=NULL,*item=NULL;
|
||||
char device_id_filepath[TFE_STRING_MAX] = { 0 };
|
||||
|
||||
ret = MESA_load_profile_string_def(profile, section, "device_id_filepath",device_id_filepath,sizeof(device_id_filepath), NULL);
|
||||
if(ret<0)
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger,"Pangu log init failed, no device_path in profile %s section %s.", profile, section);
|
||||
goto finish;
|
||||
}
|
||||
tsg_sn_file = tfe_read_file(device_id_filepath, &device_id_size);
|
||||
if(tsg_sn_file==NULL)
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger,"Pangu log init failed, %s not existed.", tsg_sn_file);
|
||||
goto finish;
|
||||
}
|
||||
json=cJSON_Parse(tsg_sn_file);
|
||||
if(json==NULL)
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger, "invalid device parameter: file = %s", tsg_sn_file);
|
||||
goto finish;
|
||||
}
|
||||
item=cJSON_GetObjectItem(json, "sn");
|
||||
if(unlikely(!item || !cJSON_IsString(item)))
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger, "Invalid device parameter: %s invalid json format", tsg_sn_file);
|
||||
}
|
||||
device_id = tfe_strdup(item->valuestring);
|
||||
|
||||
cJSON_Delete(json);
|
||||
return device_id;
|
||||
finish:
|
||||
return device_def_id;
|
||||
}
|
||||
|
||||
struct pangu_logger* pangu_log_handle_create(const char* profile, const char* section, void* local_logger)
|
||||
{
|
||||
int ret=-1;
|
||||
char nic_name[64]={0};
|
||||
char brokerlist[TFE_STRING_MAX] = { 0 };
|
||||
char topic_name[TFE_STRING_MAX] = { 0 };
|
||||
struct tango_cache_parameter *log_file_upload_para=NULL;
|
||||
|
||||
struct pangu_logger* instance=ALLOC(struct pangu_logger,1);
|
||||
instance->local_logger=local_logger;
|
||||
|
||||
TFE_LOG_INFO(local_logger,"Pangu log is inititating from %s section %s.", profile, section);
|
||||
|
||||
MESA_load_profile_int_def(profile, section, "ENTRANCE_ID",&(instance->entry_id),0);
|
||||
MESA_load_profile_uint_def(profile, section, "en_sendlog", &instance->en_sendlog, 1);
|
||||
MESA_load_profile_uint_def(profile, section, "en_sendlog_meta", &instance->en_sendlog_meta, 1);
|
||||
MESA_load_profile_uint_def(profile, section, "en_sendlog_body", &instance->en_sendlog_body, 1);
|
||||
|
||||
if (!instance->en_sendlog)
|
||||
{
|
||||
instance->en_sendlog_body = 0;
|
||||
instance->en_sendlog_meta = 0;
|
||||
}
|
||||
|
||||
TFE_LOG_INFO(local_logger, "Pangu sendlog : %s", instance->en_sendlog ? "ENABLE" : "DISABLE");
|
||||
TFE_LOG_INFO(local_logger, "Pangu sendlog meta : %s", instance->en_sendlog_meta ? "ENABLE" : "DISABLE");
|
||||
TFE_LOG_INFO(local_logger, "Pangu sendlog body : %s", instance->en_sendlog_body ? "ENABLE" : "DISABLE");
|
||||
TFE_LOG_INFO(local_logger, "Pangu sendlog : %s", instance->en_sendlog ? "ENABLE" : "DISABLE");
|
||||
|
||||
if (!instance->en_sendlog)
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
MESA_load_profile_string_def(profile, section, "NIC_NAME",nic_name,sizeof(nic_name),"eth0");
|
||||
MESA_load_profile_int_def(profile, section, "ENTRANCE_ID",&(instance->entry_id),0);
|
||||
|
||||
instance->device_id = tfe_device_id_create(profile, section, local_logger);
|
||||
TFE_LOG_INFO(local_logger, "Pangu device id : %s", instance->device_id);
|
||||
|
||||
ret=MESA_load_profile_string_def(profile, section,"KAFKA_BROKERLIST", brokerlist, sizeof(brokerlist), NULL);
|
||||
if(ret<0)
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger,"Pangu log init failed, no brokerlist in profile %s section %s.", profile, section);
|
||||
goto error_out;
|
||||
}
|
||||
MESA_load_profile_string_def(profile, section,"KAFKA_TOPIC", topic_name, sizeof(topic_name), "POLICY-EVENT-LOG");
|
||||
|
||||
TFE_LOG_INFO(local_logger, "Pangu kafka brokerlist : %s", brokerlist);
|
||||
TFE_LOG_INFO(local_logger, "Pangu kafka topic : %s", topic_name);
|
||||
|
||||
instance->kafka_logger = tfe_kafka_logger_create(instance->en_sendlog, nic_name, brokerlist, topic_name, local_logger);
|
||||
if (instance->kafka_logger == NULL)
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger,"Pangu log init failed, error to create kafka logger.");
|
||||
goto error_out;
|
||||
}
|
||||
instance->device_id = (const char *)tfe_bussiness_resouce_get(DEVICE_ID);
|
||||
instance->kafka_logger = (tfe_kafka_logger_t *)tfe_bussiness_resouce_get(KAFKA_LOGGER);
|
||||
if (instance->kafka_logger && !instance->kafka_logger->enable)
|
||||
{
|
||||
TFE_LOG_ERROR(local_logger, "Pangu sendlog ENABLE, but tfe kafka logger DISABLED.");
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
log_file_upload_para=cache_evbase_parameter_new(profile, section, local_logger);
|
||||
instance->log_file_upload_instance=cache_evbase_instance_new(log_file_upload_para, local_logger);
|
||||
|
||||
@@ -497,7 +497,7 @@ int traffic_mirror_init(struct tfe_proxy * proxy)
|
||||
|
||||
/* MAAT Feather, the configuration is same with pangu-http */
|
||||
instance->maat_feather = maat_feather_create_with_override(
|
||||
"traffic-mirror", "./conf/pangu/pangu_pxy.conf",
|
||||
"traffic-mirror", "./conf/tfe/tfe.conf",
|
||||
"maat", "traffic_mirror", instance->nr_threads, instance->logger);
|
||||
|
||||
if (unlikely(!instance->maat_feather))
|
||||
|
||||
Reference in New Issue
Block a user