Exemple #1
0
def _setup_migration_logstore(endpoint, project, access_key_id, access_key):
    log_client = LogClient(
        endpoint=endpoint,
        accessKeyId=access_key_id,
        accessKey=access_key,
    )
    try:
        log_client.create_logstore(
            project_name=project,
            logstore_name=_migration_logstore,
        )
    except LogException as exc:
        if exc.get_error_code() != "LogStoreAlreadyExist":
            raise
    try:
        tokens = [
            ',', ' ', "'", '"', ';', '=', '(', ')', '[', ']', '{', '}', '?',
            '@', '&', '<', '>', '/', ':', '\n', '\t', '\r',
        ]
        line_config = IndexLineConfig(token_list=tokens)
        config = IndexConfig(line_config=line_config)
        log_client.create_index(project, _migration_logstore, config)
    except LogException as exc:
        if exc.get_error_code() != "IndexAlreadyExist":
            raise
Exemple #2
0
res = client.create_project(log_project_name, '操作审计事件日志项目')
res.log_print()


# 等待一段时间,因为创建日志项目是异步的
# Wait for a while, because create a Log Project is asynchronous
time.sleep(120)

# 创建日志库
# Create Log Store
res = client.create_logstore(log_project_name, log_store_name, shard_count=3, preserve_storage=True)
res.log_print()

# 从log_index.json中读取索引配置
# Get Log Index config from json file
index_json = get_json_data('./log_config/log_index.json')
index_detail = IndexConfig()
index_detail.from_json(index_json)
# 创建索引
# Create Log Index
res = client.create_index(log_project_name, log_store_name, index_detail)
res.log_print()


#  从log_dashboard.json中读取报表配置
# Get Log Dashboard config from json file
dashboard_detail = get_json_data('./log_config/log_dashboard.json')
# 创建报表 
# Create Log Dashboard
client.create_dashboard(log_project_name, dashboard_detail)