diff options
| author | 童宗振 <[email protected]> | 2024-04-24 08:38:20 +0000 |
|---|---|---|
| committer | 童宗振 <[email protected]> | 2024-04-24 08:38:20 +0000 |
| commit | 491a486f86ec4132f44d3937367b3ab255de8a90 (patch) | |
| tree | c635b2d36f5a805772b01a192af96de5de04593c | |
| parent | be47e141bfd2536cd674ae2666ea5ac95f7945b3 (diff) | |
| parent | 3e5b0adb45e1c0f11d7f69a56947f51a5705dc52 (diff) | |
Merge branch 'maat_field_mod' into 'master'
Maat field mod
See merge request tsg/dp_telemetry_app!22
| -rw-r--r-- | README.md | 9 | ||||
| -rw-r--r-- | etc/dp_telemetry_rules.json | 2 | ||||
| -rw-r--r-- | etc/dp_trace.conf | 7 | ||||
| -rw-r--r-- | etc/dp_trace_dy.conf | 11 | ||||
| -rw-r--r-- | etc/table_schema.json | 2 | ||||
| -rw-r--r-- | include/common.h | 21 | ||||
| -rw-r--r-- | include/config.h | 1 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | src/config.c | 1 | ||||
| -rw-r--r-- | src/job_ctx.c | 17 | ||||
| -rw-r--r-- | src/maat.c | 9 |
11 files changed, 65 insertions, 27 deletions
@@ -13,4 +13,13 @@ mkdir build && cd build cmake .. make +``` + +## 运行 + +拷贝etc目录到build目录。并根据实际情况,修改配置文件。 + +```shell +# build dir +./src/dp_trace_telemetry -c etc/dp_trace.conf -d etc/dp_trace_dy.conf ```
\ No newline at end of file diff --git a/etc/dp_telemetry_rules.json b/etc/dp_telemetry_rules.json index 9830e08..8a67a73 100644 --- a/etc/dp_telemetry_rules.json +++ b/etc/dp_telemetry_rules.json @@ -3,7 +3,7 @@ { "table_name": "DATAPATH_TELEMETRY_JOB", "table_content": [ - "72694b1c-6833-4c46-acde-52e2d6409314\t100\tether host 00:15:5d:b8:10:a6\t60\t2\t200\t0\t{}\t1" + "72694b1c-6833-4c46-acde-52e2d6409314\t100\tether\\bhost\\b00:15:5d:b8:10:a6\t60\t2\t200\t0\t{}\t[]\t1" ] } ] diff --git a/etc/dp_trace.conf b/etc/dp_trace.conf index ecd4273..0435678 100644 --- a/etc/dp_trace.conf +++ b/etc/dp_trace.conf @@ -17,11 +17,12 @@ sasl_username=admin sasl_password=galaxy2019 [maat] +maat_log_level=3 # 0:json 1:redis -maat_log_level=0 -maat_input_mode=0 +maat_input_mode=1 +deferred_load_on=0 table_schema=../etc/table_schema.json json_cfg_file=../etc/dp_telemetry_rules.json maat_redis_server=192.168.44.3 maat_redis_port_range=7002 -maat_redis_db_index=0
\ No newline at end of file +maat_redis_db_index=1
\ No newline at end of file diff --git a/etc/dp_trace_dy.conf b/etc/dp_trace_dy.conf index 9e9240d..4c0b92d 100644 --- a/etc/dp_trace_dy.conf +++ b/etc/dp_trace_dy.conf @@ -3,15 +3,8 @@ dp_trace_file_max_size_in_KB=20 dp_trace_merge_timeout=30 [dp_trace_rule:0] -enable=1 +enable=0 bpf_expr=ether host 00:15:5d:b8:10:a6 pkt_cnt_max=0 sampling=1 -snaplen=0 - -[dp_trace_rule:1] -#invalid expr -bpf_expr=net 192.168.65.59/0 - -[dp_trace_rule:2] -bpf_expr=ip host 172.19.199.171
\ No newline at end of file +snaplen=0
\ No newline at end of file diff --git a/etc/table_schema.json b/etc/table_schema.json index 30bae66..ed500c9 100644 --- a/etc/table_schema.json +++ b/etc/table_schema.json @@ -3,7 +3,7 @@ "table_id": 1, "table_name": "DATAPATH_TELEMETRY_JOB", "table_type": "plugin", - "valid_column": 9, + "valid_column": 10, "custom": { "key": 1, "key_type": "pointer" diff --git a/include/common.h b/include/common.h index 68c9989..da3884f 100644 --- a/include/common.h +++ b/include/common.h @@ -94,4 +94,25 @@ static inline char * paths_combine(const char * restrict prog_absolute_path, con realpath(combine_path, resolve_path); return resolve_path; +} + +static inline void backspace_remove(const char * input, char * output) +{ + int i, j; + + for (i = 0, j = 0; i < strlen(input) - 1; i++) + { + if (input[i] == '\\' && input[i + 1] == 'b') + { + i += 1; + output[j++] = ' '; + } + else + { + output[j++] = input[i]; + } + } + output[j++] = input[i]; + + output[j] = '\0'; }
\ No newline at end of file diff --git a/include/config.h b/include/config.h index 967d337..d7c69bd 100644 --- a/include/config.h +++ b/include/config.h @@ -37,6 +37,7 @@ struct config // maat unsigned int maat_log_level; unsigned int maat_input_mode; + unsigned int deferred_load_on; char table_schema[PATH_MAX]; char json_cfg_file[PATH_MAX]; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9bc5d95..9d96289 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,12 +20,12 @@ if(ENABLE_DEVELOP_MOCKING) target_link_options(${PROJECT_NAME} PRIVATE -Wl,--wrap=kafka_handle_create,--wrap=kafka_topic_new,--wrap=kafka_produce) endif() -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/etc - ${CMAKE_BINARY_DIR}/etc - COMMENT "copy config file to build directory" -) +# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD +# COMMAND ${CMAKE_COMMAND} -E copy_directory +# ${CMAKE_SOURCE_DIR}/etc +# ${CMAKE_BINARY_DIR}/etc +# COMMENT "copy config file to build directory" +# ) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT Program) diff --git a/src/config.c b/src/config.c index 0f89db1..1593544 100644 --- a/src/config.c +++ b/src/config.c @@ -104,6 +104,7 @@ void config_load() MESA_load_profile_int_def(config_path, "maat", "maat_log_level", &(g_conf->maat_log_level), LOG_LEVEL_FATAL); MESA_load_profile_int_def(config_path, "maat", "maat_input_mode", &(g_conf->maat_input_mode), 0); + MESA_load_profile_int_def(config_path, "maat", "deferred_load_on", &(g_conf->deferred_load_on), 0); MESA_load_profile_string_def(config_path, "maat", "table_schema", tmp_path, sizeof(tmp_path), ""); paths_combine(g_conf->absolute_path, tmp_path, g_conf->table_schema, sizeof(g_conf->table_schema)); diff --git a/src/job_ctx.c b/src/job_ctx.c index 79d6f1d..a0dba57 100644 --- a/src/job_ctx.c +++ b/src/job_ctx.c @@ -84,20 +84,22 @@ void telemetry_job_add_cb(const char * table_name, int table_id, const char * ke unsigned int snaplen = 0; unsigned int with_packet_capture = 0; char device_group[512]; + char traffic_link_id[1024]; unsigned int is_valid = 0; - ret = sscanf(table_line, "%s\t%u\t%128[^\t]\t%u\t%u\t%u\t%u\t%s\t%u", uuid, &pkt_cnt_max, bpf_expr, &timeout, - &sampling, &snaplen, &with_packet_capture, device_group, &is_valid); - if (ret != 9) + dzlog_debug("telemetry add maat parse config rule:%s", table_line); + ret = sscanf(table_line, "%s\t%u\t%s\t%u\t%u\t%u\t%u\t%512s\t%1024s\t%u", uuid, &pkt_cnt_max, bpf_expr, &timeout, + &sampling, &snaplen, &with_packet_capture, device_group, traffic_link_id, &is_valid); + if (ret != 10) { - dzlog_warn("maat parse config failed:%s", table_line); - return; + dzlog_warn("maat parse config failed. Not enough fields:%s", table_line); + // return; } if (is_valid == 0) { dzlog_warn("rule is not valid:%s", table_line); - return; + // return; } ret = uuid_parse(uuid, telemetry_desc.uuid); @@ -107,7 +109,8 @@ void telemetry_job_add_cb(const char * table_name, int table_id, const char * ke return; } - snprintf(job_desc->bpf_expr, sizeof(job_desc->bpf_expr), "%s", bpf_expr); + backspace_remove(bpf_expr, job_desc->bpf_expr); + job_desc->pkt_cnt_max = pkt_cnt_max; job_desc->sampling = sampling; job_desc->snaplen = snaplen; @@ -17,6 +17,15 @@ static struct maat * dp_trace_maat_instance_create() struct maat_options * opts = maat_options_new(); maat_options_set_logger(opts, "log/maat.log", (enum log_level)conf->maat_log_level); maat_options_set_instance_name(opts, "dp_trace_telemetry"); + +#if 0 + if (conf->deferred_load_on) + { + maat_options_set_deferred_load_on(opts); + } + dzlog_info("maat defere load on:%u", conf->deferred_load_on); +#endif + maat_options_set_caller_thread_number(opts, 0); switch (conf->maat_input_mode) { |
