TSG-14484 Pxoxy支持Maat4
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include <MESA/MESA_prof_load.h>
|
||||
#include <MESA/Maat_rule.h>
|
||||
#include <MESA/maat.h>
|
||||
#include <cjson/cJSON.h>
|
||||
#include <tfe_kafka_logger.h>
|
||||
#include <tfe_proxy.h>
|
||||
@@ -15,16 +15,16 @@ struct maat_table_info
|
||||
const char *name;
|
||||
};
|
||||
|
||||
static Maat_feather_t static_maat = NULL;
|
||||
static struct maat *static_maat = NULL;
|
||||
static tfe_kafka_logger_t *kafka_logger = NULL;
|
||||
static char *device_id = NULL;
|
||||
static char *effective_device_tag=NULL;
|
||||
|
||||
static Maat_feather_t create_maat_feather(const char *instance_name, const char *profile, const char *section, int max_thread, void *logger)
|
||||
static struct maat *create_maat_feather(const char *instance_name, const char *profile, const char *section, int max_thread, void *logger)
|
||||
{
|
||||
Maat_feather_t target;
|
||||
struct maat *target=NULL;
|
||||
int input_mode = 0, maat_stat_on = 0, maat_perf_on = 0;
|
||||
int ret = 0, scan_detail = 0, effect_interval = 60;
|
||||
int ret = 0, effect_interval = 60, log_level=0;
|
||||
char table_info[TFE_STRING_MAX] = {0}, inc_cfg_dir[TFE_STRING_MAX] = {0}, ful_cfg_dir[TFE_STRING_MAX] = {0};
|
||||
char redis_server[TFE_STRING_MAX] = {0};
|
||||
char redis_port_range[TFE_STRING_MAX] = {0};
|
||||
@@ -50,11 +50,14 @@ static Maat_feather_t create_maat_feather(const char *instance_name, const char
|
||||
MESA_load_profile_string_def(profile, section, "stat_file", maat_stat_file, sizeof(maat_stat_file), "");
|
||||
MESA_load_profile_int_def(profile, section, "effect_interval_s", &(effect_interval), 60);
|
||||
MESA_load_profile_int_def(profile, section, "deferred_load_on", &(deferred_load_on), 0);
|
||||
MESA_load_profile_int_def(profile, section, "log_level", &(log_level), LOG_LEVEL_FATAL);
|
||||
|
||||
effect_interval *= 1000; //convert s to ms
|
||||
|
||||
target = Maat_feather(max_thread, table_info, logger);
|
||||
Maat_set_feather_opt(target, MAAT_OPT_INSTANCE_NAME, instance_name, strlen(instance_name) + 1);
|
||||
struct maat_options *opts = maat_options_new();
|
||||
maat_options_set_logger(opts, "log/maat.log", (enum log_level)log_level);
|
||||
maat_options_set_instance_name(opts, instance_name);
|
||||
maat_options_set_caller_thread_number(opts, max_thread);
|
||||
switch (input_mode)
|
||||
{
|
||||
case MAAT_INPUT_JSON:
|
||||
@@ -63,8 +66,7 @@ static Maat_feather_t create_maat_feather(const char *instance_name, const char
|
||||
TFE_LOG_ERROR(logger, "Invalid json_cfg_file, MAAT init failed.");
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
Maat_set_feather_opt(target, MAAT_OPT_JSON_FILE_PATH, json_cfg_file, strlen(json_cfg_file) + 1);
|
||||
maat_options_set_json_file(opts, json_cfg_file);
|
||||
break;
|
||||
case MAAT_INPUT_REDIS:
|
||||
if (!strlen(redis_server))
|
||||
@@ -89,10 +91,7 @@ static Maat_feather_t create_maat_feather(const char *instance_name, const char
|
||||
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
Maat_set_feather_opt(target, MAAT_OPT_REDIS_IP, redis_server, strlen(redis_server) + 1);
|
||||
Maat_set_feather_opt(target, MAAT_OPT_REDIS_PORT, &redis_port_select, sizeof(redis_port_select));
|
||||
Maat_set_feather_opt(target, MAAT_OPT_REDIS_INDEX, &redis_db_idx, sizeof(redis_db_idx));
|
||||
maat_options_set_redis(opts, redis_server, redis_port_select, redis_db_idx);
|
||||
break;
|
||||
case MAAT_INPUT_FILE:
|
||||
if (!strlen(ful_cfg_dir))
|
||||
@@ -106,50 +105,47 @@ static Maat_feather_t create_maat_feather(const char *instance_name, const char
|
||||
TFE_LOG_ERROR(logger, "Invalid inc_cfg_dir, MAAT init failed.");
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
Maat_set_feather_opt(target, MAAT_OPT_FULL_CFG_DIR, ful_cfg_dir, strlen(ful_cfg_dir) + 1);
|
||||
Maat_set_feather_opt(target, MAAT_OPT_INC_CFG_DIR, inc_cfg_dir, strlen(inc_cfg_dir) + 1);
|
||||
maat_options_set_iris(opts, ful_cfg_dir, inc_cfg_dir);
|
||||
break;
|
||||
default:
|
||||
TFE_LOG_ERROR(logger, "Invalid MAAT Input Mode: %d.", input_mode);
|
||||
goto error_out;
|
||||
break;
|
||||
}
|
||||
|
||||
Maat_set_feather_opt(target, MAAT_OPT_FOREIGN_CONT_DIR, "./pangu_files", strlen("./pangu_files") + 1);
|
||||
if (maat_stat_on)
|
||||
{
|
||||
Maat_set_feather_opt(target, MAAT_OPT_STAT_FILE_PATH, maat_stat_file, strlen(maat_stat_file) + 1);
|
||||
Maat_set_feather_opt(target, MAAT_OPT_STAT_ON, NULL, 0);
|
||||
if (maat_perf_on)
|
||||
{
|
||||
Maat_set_feather_opt(target, MAAT_OPT_PERF_ON, NULL, 0);
|
||||
}
|
||||
}
|
||||
maat_options_set_foreign_cont_dir(opts, "./pangu_files");
|
||||
if (maat_stat_on)
|
||||
{
|
||||
maat_options_set_stat_on(opts);
|
||||
if (maat_perf_on)
|
||||
{
|
||||
maat_options_set_perf_on(opts);
|
||||
}
|
||||
}
|
||||
|
||||
if (deferred_load_on)
|
||||
{
|
||||
Maat_set_feather_opt(target, MAAT_OPT_DEFERRED_LOAD, &deferred_load_on, sizeof(deferred_load_on));
|
||||
maat_options_set_deferred_load_on(opts);
|
||||
}
|
||||
Maat_set_feather_opt(target, MAAT_OPT_EFFECT_INVERVAL_MS, &effect_interval, sizeof(effect_interval));
|
||||
Maat_set_feather_opt(target, MAAT_OPT_SCAN_DETAIL, &scan_detail, sizeof(scan_detail));
|
||||
|
||||
maat_options_set_rule_effect_interval_ms(opts, effect_interval);
|
||||
if (strlen(accept_path) > 0)
|
||||
{
|
||||
MESA_load_profile_string_def(accept_path, "maat", "ACCEPT_TAGS", accept_tags, sizeof(accept_tags), "{\"tags\":[{\"tag\":\"device_id\",\"value\":\"device_1\"}]}");
|
||||
Maat_set_feather_opt(target, MAAT_OPT_ACCEPT_TAGS, &accept_tags, sizeof(accept_tags));
|
||||
maat_options_set_accept_tags(opts, accept_tags);
|
||||
TFE_LOG_INFO(logger, "tfe accept tags : %s", accept_tags);
|
||||
}
|
||||
|
||||
ret = Maat_initiate_feather(target);
|
||||
if (ret < 0)
|
||||
target = maat_new(opts, table_info);
|
||||
if (!target)
|
||||
{
|
||||
TFE_LOG_ERROR(logger, "%s MAAT init failed.", __FUNCTION__);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
return target;
|
||||
maat_options_free(opts);
|
||||
return target;
|
||||
error_out:
|
||||
Maat_burn_feather(target);
|
||||
maat_options_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -277,7 +273,7 @@ static int register_maat_table()
|
||||
{
|
||||
for (int i = 0; i < TABLE_TYPE_MAX; i++)
|
||||
{
|
||||
maat_pub_tables[i].id = Maat_table_register(static_maat, maat_pub_tables[i].name);
|
||||
maat_pub_tables[i].id = maat_get_table_id(static_maat, maat_pub_tables[i].name);
|
||||
if (maat_pub_tables[i].id < 0)
|
||||
{
|
||||
TFE_LOG_ERROR(g_default_logger, "Maat table %s register failed.", maat_pub_tables[i].name);
|
||||
|
||||
Reference in New Issue
Block a user