TSG-1723 日志中填写“设备编号”字段
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <MESA/MESA_prof_load.h>
|
||||
#include <tfe_kafka_logger.h>
|
||||
#include <cache_evbase_client.h>
|
||||
#include <tfe_utils.h>
|
||||
|
||||
#include "pangu_logger.h"
|
||||
|
||||
@@ -18,6 +19,7 @@ struct pangu_logger
|
||||
unsigned int en_sendlog_meta;
|
||||
unsigned int en_sendlog_body;
|
||||
|
||||
const char *device_id;
|
||||
void* global_logger;
|
||||
void* local_logger;
|
||||
|
||||
@@ -43,6 +45,46 @@ 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;
|
||||
@@ -77,6 +119,10 @@ struct pangu_logger* pangu_log_handle_create(const char* profile, const char* s
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -207,7 +253,7 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
|
||||
cJSON_AddNumberToObject(common_obj, "common_stream_dir", 3); //1:c2s, 2:s2c, 3:double
|
||||
cJSON_AddStringToObject(common_obj, "common_sled_ip", handle->kafka_logger->local_ip_str);
|
||||
cJSON_AddNumberToObject(common_obj, "common_entrance_id", handle->entry_id);
|
||||
cJSON_AddNumberToObject(common_obj, "common_device_id", 0);
|
||||
cJSON_AddStringToObject(common_obj, "common_device_id", handle->device_id);
|
||||
cJSON_AddStringToObject(common_obj, "http_url", http->req->req_spec.url);
|
||||
cJSON_AddStringToObject(common_obj, "http_host", http->req->req_spec.host);
|
||||
for(size_t i=0;i<sizeof(req_fields)/sizeof(struct json_spec);i++)
|
||||
|
||||
Reference in New Issue
Block a user