run first test case success
This commit is contained in:
@@ -14,7 +14,7 @@ add_definitions(-fPIC)
|
||||
set(MAAT_SRC alignment.c maat_api.c rcu_hash.c maat_garbage_collection.c maat_config_monitor.c
|
||||
maat_core.c maat_kv.c maat_ex_data.c maat_utils.c maat_command.c maat_redis_monitor.c maat_table.c
|
||||
maat_rule.c maat_object.c maat_ip.c maat_flag.c maat_interval.c maat_expr.c maat_plugin.c
|
||||
maat_ip_plugin.c maat_ipport_plugin.c maat_bool_plugin.c maat_fqdn_plugin.c maat_attribute.c maat_stat.c)
|
||||
maat_ip_plugin.c maat_ipport_plugin.c maat_bool_plugin.c maat_fqdn_plugin.c maat_stat.c)
|
||||
|
||||
set(LIB_SOURCE_FILES
|
||||
${PROJECT_SOURCE_DIR}/deps/cJSON/cJSON.c ${PROJECT_SOURCE_DIR}/deps/log/log.c)
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
**********************************************************************************************
|
||||
* File: maat_attribute.h
|
||||
* Description:
|
||||
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
|
||||
* Date: 2022-10-31
|
||||
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
|
||||
***********************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _MAAT_ATTRIBUTE_H_
|
||||
#define _MAAT_ATTRIBUTE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "cJSON/cJSON.h"
|
||||
#include "maat_table.h"
|
||||
|
||||
struct attribute_runtime;
|
||||
|
||||
void *attribute_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
const char *table_name, struct log_handle *logger);
|
||||
|
||||
void attribute_schema_free(void *attribute_schema);
|
||||
|
||||
void *attribute_runtime_new(void *attribute_schema, size_t max_thread_num,
|
||||
struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger);
|
||||
|
||||
void attribute_runtime_free(void *attribute_runtime);
|
||||
|
||||
void attribute_runtime_scan_times_inc(struct attribute_runtime *virt_rt,
|
||||
int thread_id);
|
||||
|
||||
void attribute_runtime_scan_bytes_add(struct attribute_runtime *virt_rt,
|
||||
int thread_id, long long val);
|
||||
|
||||
long long attribute_runtime_scan_bytes(void *virt_rt);
|
||||
|
||||
long long attribute_runtime_scan_times(void *attribute_runtime);
|
||||
|
||||
long long attribute_runtime_scan_cpu_time(void *attribute_runtime);
|
||||
|
||||
void attribute_runtime_hit_times_inc(struct attribute_runtime *virt_rt,
|
||||
int thread_id);
|
||||
|
||||
long long attribute_runtime_hit_times(void *attribute_runtime);
|
||||
|
||||
void attribute_runtime_hit_item_num_add(struct attribute_runtime *virt_rt,
|
||||
int thread_id, long long val);
|
||||
|
||||
long long attribute_runtime_hit_item_num(void *attribute_runtime);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -28,8 +28,8 @@ void config_monitor_traverse(long long version, const cJSON *json_root,
|
||||
const char *dec_key, struct log_handle *logger);
|
||||
|
||||
int load_maat_json_rule_file(struct maat *maat_inst, const char *json_filename,
|
||||
cJSON *json_root, char *err_str, size_t err_str_sz);
|
||||
void convert_maat_json_rule(cJSON *json_root, unsigned char *json_buff);
|
||||
cJSON **json_root, char *err_str, size_t err_str_sz);
|
||||
void convert_maat_json_rule(cJSON **json_root, unsigned char *json_buff);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ extern "C"
|
||||
#include "maat.h"
|
||||
#include "maat_kv.h"
|
||||
#include "maat_table.h"
|
||||
#include "maat_attribute.h"
|
||||
#include "maat_stat.h"
|
||||
#include "hiredis/hiredis.h"
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "maat_ipport_plugin.h"
|
||||
#include "maat_fqdn_plugin.h"
|
||||
#include "maat_bool_plugin.h"
|
||||
#include "maat_attribute.h"
|
||||
#include "maat_stat.h"
|
||||
#include "uthash/utarray.h"
|
||||
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
/*
|
||||
**********************************************************************************************
|
||||
* File: maat_attribute.c
|
||||
* Description:
|
||||
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
|
||||
* Date: 2022-10-31
|
||||
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
|
||||
***********************************************************************************************
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "maat_kv.h"
|
||||
#include "maat_utils.h"
|
||||
#include "log/log.h"
|
||||
#include "alignment.h"
|
||||
#include "maat_core.h"
|
||||
#include "maat_table.h"
|
||||
|
||||
#define MODULE_ATTRIBUTE module_name_str("maat.attribute")
|
||||
|
||||
struct attribute_schema {
|
||||
int attribute_id;
|
||||
int physical_table_id;
|
||||
struct table_manager *ref_tbl_mgr;
|
||||
};
|
||||
|
||||
struct attribute_runtime {
|
||||
size_t n_worker_thread;
|
||||
long long *scan_times;
|
||||
long long *scan_bytes;
|
||||
long long *scan_cpu_time;
|
||||
long long *hit_times;
|
||||
long long *hit_item_num;
|
||||
};
|
||||
|
||||
void *attribute_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
const char *table_name, struct log_handle *logger)
|
||||
{
|
||||
struct attribute_schema *schema = ALLOC(struct attribute_schema, 1);
|
||||
schema->ref_tbl_mgr = tbl_mgr;
|
||||
|
||||
cJSON *item = cJSON_GetObjectItem(json, "table_id");
|
||||
if (NULL == item || item->type != cJSON_Number) {
|
||||
log_fatal(logger, MODULE_ATTRIBUTE,
|
||||
"[%s:%d] attribute:<%s> schema has no table_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
schema->attribute_id = item->valueint;
|
||||
|
||||
item = cJSON_GetObjectItem(json, "physical_table");
|
||||
if (NULL == item || item->type != cJSON_String) {
|
||||
log_fatal(logger, MODULE_ATTRIBUTE,
|
||||
"[%s:%d] attribute:<%s> schema has no physical_table column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
schema->physical_table_id = table_manager_get_table_id(tbl_mgr, item->valuestring);
|
||||
if (schema->physical_table_id < 0) {
|
||||
log_fatal(logger, MODULE_ATTRIBUTE,
|
||||
"[%s:%d] attribute:<%s>'s physical table:<%s> unregistered.",
|
||||
__FUNCTION__, __LINE__, table_name, item->valuestring);
|
||||
goto error;
|
||||
}
|
||||
|
||||
return schema;
|
||||
error:
|
||||
FREE(schema);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void attribute_schema_free(void *attribute_schema)
|
||||
{
|
||||
FREE(attribute_schema);
|
||||
}
|
||||
|
||||
void *attribute_runtime_new(void *attribute_schema, size_t max_thread_num,
|
||||
struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger)
|
||||
{
|
||||
if (NULL == attribute_schema) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct attribute_runtime *virt_rt = ALLOC(struct attribute_runtime, 1);
|
||||
|
||||
virt_rt->n_worker_thread = max_thread_num;
|
||||
virt_rt->scan_times = alignment_int64_array_alloc(max_thread_num);
|
||||
virt_rt->scan_bytes = alignment_int64_array_alloc(max_thread_num);
|
||||
virt_rt->scan_cpu_time = alignment_int64_array_alloc(max_thread_num);
|
||||
virt_rt->hit_times = alignment_int64_array_alloc(max_thread_num);
|
||||
virt_rt->hit_item_num = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
return virt_rt;
|
||||
}
|
||||
|
||||
void attribute_runtime_free(void *attribute_runtime)
|
||||
{
|
||||
if (NULL == attribute_runtime) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct attribute_runtime *virt_rt = (struct attribute_runtime *)attribute_runtime;
|
||||
|
||||
if (virt_rt->scan_times != NULL) {
|
||||
alignment_int64_array_free(virt_rt->scan_times);
|
||||
virt_rt->scan_times = NULL;
|
||||
}
|
||||
|
||||
if (virt_rt->scan_bytes != NULL) {
|
||||
alignment_int64_array_free(virt_rt->scan_bytes);
|
||||
virt_rt->scan_bytes = NULL;
|
||||
}
|
||||
|
||||
if (virt_rt->scan_cpu_time != NULL) {
|
||||
alignment_int64_array_free(virt_rt->scan_cpu_time);
|
||||
virt_rt->scan_cpu_time = NULL;
|
||||
}
|
||||
|
||||
if (virt_rt->hit_times != NULL) {
|
||||
alignment_int64_array_free(virt_rt->hit_times);
|
||||
virt_rt->hit_times = NULL;
|
||||
}
|
||||
|
||||
if (virt_rt->hit_item_num != NULL) {
|
||||
alignment_int64_array_free(virt_rt->hit_item_num);
|
||||
virt_rt->hit_item_num = NULL;
|
||||
}
|
||||
|
||||
FREE(virt_rt);
|
||||
}
|
||||
|
||||
void attribute_runtime_scan_bytes_add(struct attribute_runtime *virt_rt,
|
||||
int thread_id, long long val)
|
||||
{
|
||||
if (NULL == virt_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(virt_rt->scan_bytes, thread_id, val);
|
||||
}
|
||||
|
||||
long long attribute_runtime_scan_bytes(void *attribute_runtime)
|
||||
{
|
||||
if (NULL == attribute_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct attribute_runtime *virt_rt = (struct attribute_runtime *)attribute_runtime;
|
||||
long long sum = alignment_int64_array_sum(virt_rt->scan_bytes,
|
||||
virt_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(virt_rt->scan_bytes,
|
||||
virt_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void attribute_runtime_scan_times_inc(struct attribute_runtime *virt_rt,
|
||||
int thread_id)
|
||||
{
|
||||
if (NULL == virt_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(virt_rt->scan_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long attribute_runtime_scan_times(void *attribute_runtime)
|
||||
{
|
||||
if (NULL == attribute_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct attribute_runtime *virt_rt = (struct attribute_runtime *)attribute_runtime;
|
||||
long long sum = alignment_int64_array_sum(virt_rt->scan_times,
|
||||
virt_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(virt_rt->scan_times,
|
||||
virt_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
long long attribute_runtime_scan_cpu_time(void *attribute_runtime)
|
||||
{
|
||||
if (NULL == attribute_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct attribute_runtime *virt_rt = (struct attribute_runtime *)attribute_runtime;
|
||||
long long sum = alignment_int64_array_sum(virt_rt->scan_cpu_time,
|
||||
virt_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(virt_rt->scan_cpu_time,
|
||||
virt_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void attribute_runtime_hit_times_inc(struct attribute_runtime *virt_rt,
|
||||
int thread_id)
|
||||
{
|
||||
if (NULL == virt_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(virt_rt->hit_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long attribute_runtime_hit_times(void *attribute_runtime)
|
||||
{
|
||||
if (NULL == attribute_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct attribute_runtime *virt_rt = (struct attribute_runtime *)attribute_runtime;
|
||||
long long sum = alignment_int64_array_sum(virt_rt->hit_times,
|
||||
virt_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(virt_rt->hit_times,
|
||||
virt_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void attribute_runtime_hit_item_num_add(struct attribute_runtime *virt_rt,
|
||||
int thread_id, long long val)
|
||||
{
|
||||
if (NULL == virt_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(virt_rt->hit_item_num, thread_id, val);
|
||||
}
|
||||
|
||||
long long attribute_runtime_hit_item_num(void *attribute_runtime)
|
||||
{
|
||||
if (NULL == attribute_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct attribute_runtime *virt_rt = (struct attribute_runtime *)attribute_runtime;
|
||||
long long sum = alignment_int64_array_sum(virt_rt->hit_item_num,
|
||||
virt_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(virt_rt->hit_item_num,
|
||||
virt_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
@@ -88,15 +88,13 @@ int my_scandir(const char *dir, struct dirent ***namelist,
|
||||
static void config_load_json_content(const cJSON *json_root, const char *table_name, const char *key, void *u_param,
|
||||
int (*update_fn)(const char *, const char *, void *, enum maat_operation))
|
||||
{
|
||||
cJSON *tmp_item = NULL;
|
||||
cJSON *array_item = NULL;
|
||||
int i;
|
||||
|
||||
tmp_item = cJSON_GetObjectItem(json_root, table_name);
|
||||
array_item = cJSON_GetObjectItem(json_root, key);
|
||||
if (array_item != NULL) {
|
||||
for (i = 0; i < cJSON_GetArraySize(tmp_item); i++) {
|
||||
cJSON *rule = cJSON_GetArrayItem(tmp_item, i);
|
||||
for (i = 0; i < cJSON_GetArraySize(array_item); i++) {
|
||||
cJSON *rule = cJSON_GetArrayItem(array_item, i);
|
||||
if (rule == NULL) {
|
||||
continue;
|
||||
}
|
||||
@@ -106,7 +104,7 @@ static void config_load_json_content(const cJSON *json_root, const char *table_n
|
||||
continue;
|
||||
}
|
||||
|
||||
update_fn(tmp_item->valuestring, rule_str, u_param, MAAT_OP_ADD);
|
||||
update_fn(table_name, rule_str, u_param, MAAT_OP_ADD);
|
||||
FREE(rule_str);
|
||||
}
|
||||
}
|
||||
@@ -127,8 +125,10 @@ void config_monitor_traverse(long long current_version, const cJSON *json_root,
|
||||
}
|
||||
|
||||
cJSON *tmp_obj = NULL;
|
||||
cJSON *rule_table = cJSON_GetObjectItem(json_root, "rule_table");
|
||||
cJSON *object2object_table = cJSON_GetObjectItem(json_root, "object2object_table");
|
||||
|
||||
tmp_obj = cJSON_GetObjectItem(json_root, "objects");
|
||||
tmp_obj = cJSON_GetObjectItem(json_root, "items");
|
||||
if (tmp_obj != NULL) {
|
||||
for (i = 0; i < cJSON_GetArraySize(tmp_obj); i++) {
|
||||
cJSON *object = cJSON_GetArrayItem(tmp_obj, i);
|
||||
@@ -136,11 +136,6 @@ void config_monitor_traverse(long long current_version, const cJSON *json_root,
|
||||
continue;
|
||||
}
|
||||
|
||||
cJSON *regions = cJSON_GetObjectItem(object, "regions");
|
||||
if (regions == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cJSON *table_name = cJSON_GetObjectItem(object, "table_name");
|
||||
if (table_name == NULL) {
|
||||
continue;
|
||||
@@ -158,25 +153,107 @@ void config_monitor_traverse(long long current_version, const cJSON *json_root,
|
||||
}
|
||||
}
|
||||
|
||||
config_load_json_content(json_root, "object2object_table", "object_groups", u_param, update_fn);
|
||||
config_load_json_content(json_root, "rule_table", "rules", u_param, update_fn);
|
||||
config_load_json_content(json_root, object2object_table->valuestring, "object_groups", u_param, update_fn);
|
||||
config_load_json_content(json_root, rule_table->valuestring, "rules", u_param, update_fn);
|
||||
|
||||
if (finish_fn != NULL) {
|
||||
finish_fn(u_param);
|
||||
}
|
||||
}
|
||||
|
||||
void convert_maat_json_rule(cJSON *json_root, unsigned char *json_buff)
|
||||
void convert_maat_json_rule(cJSON **json_root, unsigned char *json_buff)
|
||||
{
|
||||
json_root = cJSON_Parse((const char *)json_buff);
|
||||
cJSON *top_objects = cJSON_GetObjectItem(json_root, "objects");
|
||||
//cJSON *object_groups = cJSON_GetObjectItem(json_root, "object_groups");//TODO: object include object in rules
|
||||
cJSON *rules = cJSON_GetObjectItem(json_root, "rules");
|
||||
cJSON *tmp_rule = NULL;
|
||||
*json_root = cJSON_Parse((const char *)json_buff);
|
||||
cJSON *top_items = cJSON_GetObjectItem(*json_root, "items");
|
||||
cJSON *top_objects = cJSON_GetObjectItem(*json_root, "objects");
|
||||
cJSON *rules = cJSON_GetObjectItem(*json_root, "rules");
|
||||
long long item_id = 1;
|
||||
long long object_id = 1;
|
||||
char str[10];
|
||||
|
||||
if (top_items == NULL) {
|
||||
top_items = cJSON_CreateArray();
|
||||
cJSON_AddItemToObject(*json_root, "items", top_items);
|
||||
}
|
||||
|
||||
/*
|
||||
"objects": [ "items": [
|
||||
{ {
|
||||
"object_name": "ASN1234", "table_name": "AS_NUMBER",
|
||||
"object_id": 1, "table_content": {
|
||||
"items": [ "item_id": "1",
|
||||
{ "object_id": "1",
|
||||
"table_name": "AS_NUMBER", --------------------> "keywords": "^AS1234$",
|
||||
"table_type": "expr", "expr_type": "and"
|
||||
"table_content": { }
|
||||
"keywords": "^AS1234$", }
|
||||
"expr_type": "and" ]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
*/
|
||||
cJSON *tmp_node = NULL;
|
||||
cJSON_ArrayForEach(tmp_node, top_objects) {
|
||||
cJSON *object_id_obj = cJSON_GetObjectItem(tmp_node, "object_id");
|
||||
cJSON *items = cJSON_GetObjectItem(tmp_node, "items");
|
||||
cJSON *tmp_item = NULL;
|
||||
cJSON_ArrayForEach(tmp_item, items) {
|
||||
cJSON *table_name = cJSON_GetObjectItem(tmp_item, "table_name");
|
||||
cJSON *table_content = cJSON_GetObjectItem(tmp_item, "table_content");
|
||||
cJSON *new_item = cJSON_CreateObject();
|
||||
cJSON *new_table_content = cJSON_Duplicate(table_content, 0);
|
||||
|
||||
if (object_id_obj == NULL) {
|
||||
memset(str, 0, sizeof(str));
|
||||
snprintf(str, sizeof(str), "%lld", object_id);
|
||||
cJSON_AddStringToObject(new_table_content, "object_id", str);
|
||||
object_id++;
|
||||
} else {
|
||||
cJSON_AddStringToObject(new_table_content, "object_id", object_id_obj->valuestring);
|
||||
}
|
||||
|
||||
if (cJSON_GetObjectItem(table_content, "item_id") == NULL) {
|
||||
memset(str, 0, sizeof(str));
|
||||
snprintf(str, sizeof(str), "%lld", item_id);
|
||||
cJSON_AddStringToObject(new_table_content, "item_id", str);
|
||||
item_id++;
|
||||
}
|
||||
|
||||
cJSON_AddStringToObject(new_item, "table_name", table_name->valuestring);
|
||||
cJSON_AddItemToObject(new_item, "table_content", new_table_content);
|
||||
cJSON_AddItemToArray(top_items, new_item);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
"rules": [ "items":[
|
||||
{ {
|
||||
"rule_id": "201", "table_name": "ATTR_APP_ID",
|
||||
"conditions": [ "table_content": {
|
||||
{ "item_id": "1",
|
||||
"attribute_name": "ATTR_APP_ID", "object_id": "1",
|
||||
"objects": [ "interval": "4001"
|
||||
{
|
||||
"items":[ --------------> }
|
||||
"table_name": "APP_ID_DICT", }
|
||||
"table_type": "interval", ]
|
||||
"interval": "4001"
|
||||
]
|
||||
} "rules": [{
|
||||
] "rule_id": "201",
|
||||
} "conditions": [
|
||||
], {
|
||||
"misc": "blah, blah" "attribute_name": "ATTR_APP_ID",
|
||||
} "object_ids": [1]
|
||||
] }
|
||||
]
|
||||
"misc": "blah, blah"
|
||||
}
|
||||
]
|
||||
*/
|
||||
cJSON *tmp_rule = NULL;
|
||||
cJSON_ArrayForEach(tmp_rule, rules) {
|
||||
cJSON *tmp_condition = NULL;
|
||||
cJSON *condition_array = cJSON_GetObjectItem(tmp_rule, "conditions");
|
||||
@@ -184,26 +261,42 @@ void convert_maat_json_rule(cJSON *json_root, unsigned char *json_buff)
|
||||
cJSON *tmp_object = NULL;
|
||||
cJSON *object_id_array = cJSON_CreateArray();
|
||||
cJSON *object_array = cJSON_GetObjectItem(tmp_condition, "objects");
|
||||
|
||||
if (object_array == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cJSON_ArrayForEach(tmp_object, object_array) {
|
||||
//find items, generate item_id and object_id
|
||||
cJSON *table_name = cJSON_GetObjectItem(tmp_object, "table_name");
|
||||
cJSON *tmp_item = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(tmp_item, "table_name", cJSON_CreateString(table_name->valuestring));
|
||||
cJSON *dup = cJSON_Duplicate(tmp_object, 0);
|
||||
if (cJSON_GetObjectItem(dup, "item_id") == NULL) {
|
||||
memset(str, 0, sizeof(str));
|
||||
snprintf(str, sizeof(str), "%lld", item_id);
|
||||
cJSON_AddItemToObject(dup, "item_id", cJSON_CreateString(str));
|
||||
item_id++;
|
||||
}
|
||||
if (cJSON_GetObjectItem(dup, "object_id") == NULL) {
|
||||
memset(str, 0, sizeof(str));
|
||||
cJSON *object_id_obj = cJSON_GetObjectItem(tmp_object, "object_id");
|
||||
cJSON *items = cJSON_GetObjectItem(tmp_object, "items");
|
||||
cJSON *item = NULL;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
if (object_id_obj != NULL) {
|
||||
snprintf(str, sizeof(str), "%s", object_id_obj->valuestring);
|
||||
} else {
|
||||
snprintf(str, sizeof(str), "%lld", object_id);
|
||||
cJSON_AddItemToObject(dup, "object_id", cJSON_CreateString(str));
|
||||
object_id++;
|
||||
}
|
||||
cJSON_AddItemToObject(tmp_item, "table_content", dup);
|
||||
cJSON_AddItemToArray(top_objects, tmp_item);
|
||||
cJSON_ArrayForEach(item, items) {
|
||||
cJSON *table_name = cJSON_GetObjectItem(item, "table_name");
|
||||
cJSON *tmp_item = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(tmp_item, "table_name", cJSON_CreateString(table_name->valuestring));
|
||||
|
||||
cJSON *dup = cJSON_Duplicate(cJSON_GetObjectItem(item, "table_content"), 1);
|
||||
|
||||
if (cJSON_GetObjectItem(dup, "item_id") == NULL) {
|
||||
memset(str, 0, sizeof(str));
|
||||
snprintf(str, sizeof(str), "%lld", item_id);
|
||||
cJSON_AddStringToObject(dup, "item_id", str);
|
||||
item_id++;
|
||||
}
|
||||
cJSON_AddStringToObject(dup, "object_id", str);
|
||||
|
||||
cJSON_AddItemToObject(tmp_item, "table_content", dup);
|
||||
cJSON_AddItemToArray(top_items, tmp_item);
|
||||
}
|
||||
|
||||
cJSON_AddItemToArray(object_id_array, cJSON_CreateString(str));
|
||||
}
|
||||
@@ -216,7 +309,7 @@ void convert_maat_json_rule(cJSON *json_root, unsigned char *json_buff)
|
||||
}
|
||||
|
||||
int load_maat_json_rule_file(struct maat *maat_inst, const char *json_filename,
|
||||
cJSON *json_root, char *err_str, size_t err_str_sz)
|
||||
cJSON **json_root, char *err_str, size_t err_str_sz)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char *json_buff = NULL;
|
||||
|
||||
@@ -336,7 +336,7 @@ void maat_read_full_config(struct maat *maat_inst)
|
||||
break;
|
||||
case DATA_SOURCE_JSON_FILE:
|
||||
ret = load_maat_json_rule_file(maat_inst, maat_inst->opts.json_ctx.json_file,
|
||||
json_root, err_str, sizeof(err_str));
|
||||
&json_root, err_str, sizeof(err_str));
|
||||
if (ret < 0) {
|
||||
log_fatal(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] Maat re-initiate with JSON file %s failed: %s",
|
||||
@@ -460,7 +460,7 @@ void *rule_monitor_loop(void *arg)
|
||||
md5_file(maat_inst->opts.json_ctx.json_file, md5_tmp);
|
||||
if (0 != strcmp(md5_tmp, maat_inst->opts.json_ctx.effective_json_md5)) {
|
||||
ret = load_maat_json_rule_file(maat_inst, maat_inst->opts.json_ctx.json_file,
|
||||
json_root, err_str, sizeof(err_str));
|
||||
&json_root, err_str, sizeof(err_str));
|
||||
if (ret < 0) {
|
||||
log_fatal(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] Maat re-initiate with JSON file %s (md5=%s)failed: %s\n",
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "maat_config_monitor.h"
|
||||
#include "maat_redis_monitor.h"
|
||||
#include "maat_plugin.h"
|
||||
#include "maat_attribute.h"
|
||||
|
||||
#define MODULE_REDIS_MONITOR module_name_str("maat.redis_monitor")
|
||||
|
||||
|
||||
@@ -279,23 +279,25 @@ static struct maat_rule *maat_rule_new(struct rule_runtime *rule_rt, struct rule
|
||||
}
|
||||
|
||||
tmp_obj = cJSON_GetObjectItem(condition_obj, "negate_option");
|
||||
if (tmp_obj == NULL || tmp_obj->type != cJSON_String) {
|
||||
log_fatal(logger, MODULE_RULE,
|
||||
"[%s:%d] table: <%s> has no negate_option or not string format",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
if (tmp_obj) {
|
||||
if (tmp_obj->type != cJSON_String) {
|
||||
log_fatal(logger, MODULE_RULE,
|
||||
"[%s:%d] table: <%s> has no negate_option or not string format",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (strncmp(tmp_obj->valuestring, "true", 4) == 0) {
|
||||
condition->negate_option = CONDITION_NEGATE_OPTION_SET;
|
||||
} else if (strncmp(tmp_obj->valuestring, "false", 5) == 0) {
|
||||
condition->negate_option = CONDITION_NEGATE_OPTION_UNSET;
|
||||
} else {
|
||||
log_fatal(logger, MODULE_RULE,
|
||||
"[%s:%d] table: <%s> negate_option:%s is illegal",
|
||||
__FUNCTION__, __LINE__, table_name, tmp_obj->valuestring);
|
||||
goto error;
|
||||
}
|
||||
if (strncmp(tmp_obj->valuestring, "true", 4) == 0) {
|
||||
condition->negate_option = CONDITION_NEGATE_OPTION_SET;
|
||||
} else if (strncmp(tmp_obj->valuestring, "false", 5) == 0) {
|
||||
condition->negate_option = CONDITION_NEGATE_OPTION_UNSET;
|
||||
} else {
|
||||
log_fatal(logger, MODULE_RULE,
|
||||
"[%s:%d] table: <%s> negate_option:%s is illegal",
|
||||
__FUNCTION__, __LINE__, table_name, tmp_obj->valuestring);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
if (condition->negate_option == CONDITION_NEGATE_OPTION_SET) {
|
||||
int ret = validate_table_not_condition(rule_rt, schema->ref_tbl_mgr, condition->attribute_id, MAAT_OP_ADD, logger);
|
||||
@@ -315,8 +317,8 @@ static struct maat_rule *maat_rule_new(struct rule_runtime *rule_rt, struct rule
|
||||
|
||||
for (int j = 0; j < n_object_ids; j++) {
|
||||
cJSON *object_id_obj = cJSON_GetArrayItem(tmp_obj, j);
|
||||
if (object_id_obj && object_id_obj->type == cJSON_Number) {
|
||||
long long object_id = object_id_obj->valueint;
|
||||
if (object_id_obj && object_id_obj->type == cJSON_String) {
|
||||
long long object_id = atoll(object_id_obj->valuestring);
|
||||
condition->object_ids[j] = object_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "maat_bool_plugin.h"
|
||||
#include "maat_fqdn_plugin.h"
|
||||
#include "maat_interval.h"
|
||||
#include "maat_attribute.h"
|
||||
#include "expr_matcher/expr_matcher.h"
|
||||
|
||||
#define MODULE_TABLE module_name_str("maat.table")
|
||||
@@ -272,22 +271,6 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.rule_count = bool_plugin_runtime_rule_count,
|
||||
.update_err_count = bool_plugin_runtime_update_err_count
|
||||
},
|
||||
#if 0
|
||||
{
|
||||
.type = TABLE_TYPE_ATTRIBUTE,
|
||||
.new_schema = attribute_schema_new,
|
||||
.free_schema = attribute_schema_free,
|
||||
.new_runtime = attribute_runtime_new,
|
||||
.free_runtime = attribute_runtime_free,
|
||||
.update_runtime = NULL,
|
||||
.commit_runtime = NULL,
|
||||
.scan_times = attribute_runtime_scan_times,
|
||||
.scan_bytes = attribute_runtime_scan_bytes,
|
||||
.scan_cpu_time = attribute_runtime_scan_cpu_time,
|
||||
.hit_times = attribute_runtime_hit_times,
|
||||
.hit_item_num = attribute_runtime_hit_item_num
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.type = TABLE_TYPE_RULE,
|
||||
.new_schema = rule_schema_new,
|
||||
|
||||
Reference in New Issue
Block a user