diff options
| author | tongzongzhen <[email protected]> | 2024-04-17 18:47:25 +0800 |
|---|---|---|
| committer | tongzongzhen <[email protected]> | 2024-04-17 18:47:25 +0800 |
| commit | a9ab020ae7acdcef516e100c26633a16a179ad9d (patch) | |
| tree | 1367e274eafc590262e8b22d1cd4fe14dd65ed9c | |
| parent | 1280af8e80d6011068dcae26c92d25227748d505 (diff) | |
add maat test
| -rw-r--r-- | doc/dp_telemetry_maat_job.json | 9 | ||||
| -rw-r--r-- | etc/dp_telemetry_rules.json | 3 | ||||
| -rw-r--r-- | src/job_ctx.c | 23 |
3 files changed, 30 insertions, 5 deletions
diff --git a/doc/dp_telemetry_maat_job.json b/doc/dp_telemetry_maat_job.json new file mode 100644 index 0000000..8abe0b8 --- /dev/null +++ b/doc/dp_telemetry_maat_job.json @@ -0,0 +1,9 @@ +{ + "job_id": "499a49aa-b4b9-4e8e-a66c-80d4cd40257b", + "job_name": "test_2", + "bpf_expr": "ether host 00:15:5d:b8:10:a6", + "pkt_cnt_max": 100, + "timeout": 120, + "sampling": 2, + "snaplen": 100 +}
\ No newline at end of file diff --git a/etc/dp_telemetry_rules.json b/etc/dp_telemetry_rules.json index a5c9972..6623063 100644 --- a/etc/dp_telemetry_rules.json +++ b/etc/dp_telemetry_rules.json @@ -3,7 +3,8 @@ { "table_name": "DP_TRACE_TELEMETRY_TABLE", "table_content": [ - "0\t{\"job_id\":\"72694b1c-6833-4c46-acde-52e2d6409314\",\"bpf_expr\":\"ip host 172.19.199.171\"}\t1" + "0\t{\"job_id\":\"72694b1c-6833-4c46-acde-52e2d6409314\",\"job_name\":\"test_xx\",\"bpf_expr\":\"ip host 172.19.199.171\",\"pkt_cnt_max\":100,\"timeout\":60,\"sampling\":2,\"snaplen\":100}\t1", + "1\t{\"job_id\":\"499a49aa-b4b9-4e8e-a66c-80d4cd40257b\",\"job_name\":\"test_2\",\"bpf_expr\":\"ether host 00:15:5d:b8:10:a6\",\"pkt_cnt_max\":100,\"timeout\":120,\"sampling\":2,\"snaplen\":100}\t1" ] } ] diff --git a/src/job_ctx.c b/src/job_ctx.c index 1bb1d2b..ec69bd9 100644 --- a/src/job_ctx.c +++ b/src/job_ctx.c @@ -106,9 +106,25 @@ void telemetry_job_add_cb(const char * table_name, int table_id, const char * ke goto out; } - cJSON * bpf_obj = cJSON_GetObjectItem(json, "bpf_expr"); - DP_TRACE_VERIFY(cJSON_IsString(bpf_obj), "bpf expr is not string"); - snprintf(job_desc->bpf_expr, sizeof(job_desc->bpf_expr), "%s", bpf_obj->valuestring); + cJSON * job_name_obj = cJSON_GetObjectItem(json, "job_name"); + DP_TRACE_VERIFY(cJSON_IsString(job_name_obj), "job_name is not string"); + snprintf(telemetry_desc.job_name, sizeof(telemetry_desc.job_name), "%s", job_name_obj->valuestring); + + cJSON * bpf_expr_obj = cJSON_GetObjectItem(json, "bpf_expr"); + DP_TRACE_VERIFY(cJSON_IsString(bpf_expr_obj), "bpf expr is not string"); + snprintf(job_desc->bpf_expr, sizeof(job_desc->bpf_expr), "%s", bpf_expr_obj->valuestring); + + cJSON * pkt_cnt_max_obj = cJSON_GetObjectItem(json, "pkt_cnt_max"); + DP_TRACE_VERIFY(cJSON_IsNumber(pkt_cnt_max_obj), "pkt_cnt_max is not number"); + job_desc->pkt_cnt_max = pkt_cnt_max_obj->valueint; + + cJSON * sampling_obj = cJSON_GetObjectItem(json, "sampling"); + DP_TRACE_VERIFY(cJSON_IsNumber(sampling_obj), "sampling is not number"); + job_desc->sampling = sampling_obj->valueint; + + cJSON * snaplen_obj = cJSON_GetObjectItem(json, "snaplen"); + DP_TRACE_VERIFY(cJSON_IsNumber(snaplen_obj), "snaplen is not number"); + job_desc->snaplen = snaplen_obj->valueint; int index = telemetry_unused_job_index_get(); if (index < 0) @@ -118,7 +134,6 @@ void telemetry_job_add_cb(const char * table_name, int table_id, const char * ke } job_desc->rule_index = index; - job_desc->sampling = 1; job_desc->enable = true; memcpy(&telemetry_descs[index], &telemetry_desc, sizeof(struct dp_trace_telemetry_desc)); |
