云日志服务 LTS-使用e_dict_map、e_search_dict_map函数进行数据富化:使用e_dict_map函数进行数据富化

时间:2025-02-12 15:14:38

使用e_dict_map函数进行数据富化

本案例介绍使用e_dict_map函数完成数据富化的方法。

  • 原始日志
    [{    "http_host":  "example.com",    "http_status":  300,    "request_method":  "GET"},{    "http_host":  "example.org",    "http_status":  200,    "request_method":  "POST"},{    "http_host":  "example.net",    "http_status":  400,    "request_method":  "GET"},{    "http_host":  "huaweicloud.com",    "http_status":  500,    "request_method":  "GET"}]
  • 加工需求

    将http_status字段中的请求状态码转化为文本格式,并添加到status_desc字段中。

  • 加工规则
    e_dict_map({"400": "请求错误", "500": "服务器错误", "300": "跳转", "200": "成功"}, "http_status", "status_desc")

    在实际情况中,HTTP请求状态码不止以上4种,详情请参见HTTP请求状态码。当http_status字段的值为401、404时,需要更新字典覆盖,否则无法匹配。

  • 加工结果
    {"status_desc": "跳转","http_status": 300,"request_method": "GET","http_host": "example.com"}{"status_desc": "成功","http_status": 200,"request_method": "POST","http_host": "example.org"}{"status_desc": "请求错误","http_status": 400,"request_method": "GET","http_host": "example.net"}{"status_desc": "服务器错误","http_status": 500,"request_method": "GET","http_host": "huaweicloud.com"}
support.huaweicloud.com/bestpractice-lts/lts_07_0056.html