diff options
| author | liuxueli <[email protected]> | 2020-06-03 17:45:11 +0800 |
|---|---|---|
| committer | liuxueli <[email protected]> | 2020-06-03 17:45:11 +0800 |
| commit | 8a35de89df07d74824e039158c17e400ae666fd7 (patch) | |
| tree | 75b19952517eca541edfdb0a9688852bdd7eb1df | |
| parent | 40b3b1536061a420d551bc183db6b8f356a636b6 (diff) | |
将设备ID写入到/etc/default/telegraf文件,供telegraf读取写入到日志的tags中v1.2.6.20.06
| -rw-r--r-- | src/tsg_entry.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp index 078acd3..2f53b3b 100644 --- a/src/tsg_entry.cpp +++ b/src/tsg_entry.cpp @@ -42,7 +42,7 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL; #endif -char TSG_MASTER_VERSION_20200603=0; +char TSG_MASTER_VERSION_20200604=0; const char *tsg_conffile="tsgconf/main.conf"; g_tsg_para_t g_tsg_para; @@ -90,6 +90,27 @@ static int tsg_get_sn(char *filename, char *device_sn, int device_sn_len) return flags; } +int tsg_set_device_id_to_telegraf(char *device_sn) +{ + char buff[128]={0}; + FILE *fp=NULL; + + if(device_sn) + { + fp=fopen("/etc/default/telegraf", "wb"); + if(fp) + { + snprintf(buff, sizeof(buff), "device_id=\"%s\"\n", device_sn); + fwrite(buff, strlen(buff), 1, fp); + fclose(fp); + fp=NULL; + return 0; + } + } + + return -1; +} + static void free_policy_label(int thread_seq, void *project_req_value) { dictator_free(thread_seq, project_req_value); @@ -1045,6 +1066,12 @@ extern "C" int TSG_MASTER_INIT() { MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "GET_DEVICE_SN", "Get device SN failed; please check :%s", device_sn_filename); } + + ret=tsg_set_device_id_to_telegraf(g_tsg_para.device_sn); + if(ret<0) + { + MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "SET_DEVICE_SN_TO_TELEGRAF", "Set device SN(%s) failed; please check :%s", g_tsg_para.device_sn, "/etc/default/telegraf"); + } MESA_load_profile_string_def(tsg_conffile, "SYSTEM", "POLICY_PRIORITY_LABEL", label_buff, sizeof(label_buff), "POLICY_PRIORITY"); g_tsg_para.priority_project_id=project_producer_register(label_buff, PROJECT_VAL_TYPE_STRUCT, free_policy_label); |
