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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user