网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
Haydn解决方案工厂
数字化诊断治理专家服务
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts盘古助手
华为云Astro大屏应用
计算
弹性云服务器 ECS
Flexus云服务
裸金属服务器 BMS
云手机服务器 CPH
专属主机 DeH
弹性伸缩 AS
镜像服务 IMS
函数工作流 FunctionGraph
云耀云服务器(旧版)
VR云渲游平台 CVR
Huawei Cloud EulerOS
云化数据中心 CloudDC
网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
CDN与智能边缘
内容分发网络 CDN
智能边缘云 IEC
智能边缘平台 IEF
CloudPond云服务
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
大数据
MapReduce服务 MRS
数据湖探索 DLI
表格存储服务 CloudTable
可信智能计算服务 TICS
推荐系统 RES
云搜索服务 CSS
数据可视化 DLV
数据接入服务 DIS
数据仓库服务 GaussDB(DWS)
数据治理中心 DataArts Studio
湖仓构建 LakeFormation
智能数据洞察 DataArts Insight
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
开天aPaaS
应用平台 AppStage
开天企业工作台 MSSE
开天集成工作台 MSSI
API中心 API Hub
云消息服务 KooMessage
交换数据空间 EDS
云地图服务 KooMap
云手机服务 KooPhone
组织成员账号 OrgID
云空间服务 KooDrive
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
区块链
区块链服务 BCS
数字资产链 DAC
华为云区块链引擎服务 HBS
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
Haydn解决方案工厂
数字化诊断治理专家服务
价格
成本优化最佳实践
专属云商业逻辑
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
其他
管理控制台
消息中心
产品价格详情
系统权限
客户关联华为云合作伙伴须知
公共问题
宽限期保留期
奖励推广计划
活动
云服务信任体系能力说明
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts盘古助手
华为云Astro大屏应用
存储
对象存储服务 OBS
云硬盘 EVS
云备份 CBR
高性能弹性文件服务 SFS Turbo
弹性文件服务 SFS
存储容灾服务 SDRS
云硬盘备份 VBS
云服务器备份 CSBS
数据快递服务 DES
云存储网关 CSG
专属分布式存储服务 DSS
数据工坊 DWR
地图数据 MapDS
键值存储服务 KVS
容器
云容器引擎 CCE
云容器实例 CCI
容器镜像服务 SWR
云原生服务中心 OSC
应用服务网格 ASM
华为云UCS
数据库
云数据库 RDS
数据复制服务 DRS
文档数据库服务 DDS
分布式数据库中间件 DDM
云数据库 GaussDB
云数据库 GeminiDB
数据管理服务 DAS
数据库和应用迁移 UGO
云数据库 TaurusDB
人工智能
AI开发平台ModelArts
华为HiLens
图引擎服务 GES
图像识别 Image
文字识别 OCR
自然语言处理 NLP
内容审核 Moderation
图像搜索 ImageSearch
医疗智能体 EIHealth
企业级AI应用开发专业套件 ModelArts Pro
人脸识别服务 FRS
对话机器人服务 CBS
语音交互服务 SIS
人证核身服务 IVS
视频智能分析服务 VIAS
城市智能体
自动驾驶云服务 Octopus
盘古大模型 PanguLargeModels
IoT物联网
设备接入 IoTDA
全球SIM联接 GSL
IoT数据分析 IoTA
路网数字化服务 DRIS
IoT边缘 IoTEdge
设备发放 IoTDP
企业应用
域名注册服务 Domains
云解析服务 DNS
企业门户 EWP
ICP备案
商标注册
华为云WeLink
华为云会议 Meeting
隐私保护通话 PrivateNumber
语音通话 VoiceCall
消息&短信 MSGSMS
云管理网络
SD-WAN 云服务
边缘数据中心管理 EDCM
云桌面 Workspace
应用与数据集成平台 ROMA Connect
ROMA资产中心 ROMA Exchange
API全生命周期管理 ROMA API
政企自服务管理 ESM
视频
实时音视频 SparkRTC
视频直播 Live
视频点播 VOD
媒体处理 MPC
视频接入服务 VIS
数字内容生产线 MetaStudio
迁移
主机迁移服务 SMS
对象存储迁移服务 OMS
云数据迁移 CDM
迁移中心 MGC
专属云
专属计算集群 DCC
开发者工具
SDK开发指南
API签名指南
DevStar
华为云命令行工具服务 KooCLI
Huawei Cloud Toolkit
CodeArts API
云化转型
云架构中心
云采用框架
用户服务
账号中心
费用中心
成本中心
资源中心
企业管理
工单管理
客户运营能力
国际站常见问题
支持计划
专业服务
合作伙伴支持计划
我的凭证
华为云公共事业服务云平台
工业软件
工业数字模型驱动引擎
硬件开发工具链平台云服务
工业数据转换引擎云服务
文档首页/ 云日志服务 LTS/ API参考/ API说明/ 云端结构化配置/ 修改结构化配置(不推荐)

修改结构化配置(不推荐)

更新时间:2025-02-11 GMT+08:00
分享

功能介绍

该接口用于修改指定日志流下的结构化配置,由于参数较多且构建复杂,建议您使用8.9.2-修改结构化配置(推荐)。

调用方法

请参见如何调用API

URI

PUT /v2/{project_id}/lts/struct/template

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,获取方式请参见:获取项目ID,获取账号ID,日志组ID、日志流ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

从IAM服务获取的用户Token,获取方式请参见:获取用户Token

Content-Type

String

该字段填为:application/json;charset=UTF-8。

表3 请求Body参数

参数

是否必选

参数类型

描述

log_group_id

String

日志组ID

最小长度:36

最大长度:36

log_stream_id

String

日志流ID

最小长度:36

最大长度:36

project_id

String

项目ID

最小长度:32

最大长度:32

content

String

填写一条示例日志。

demo_fields

Array of DemoFields objects

示例字段列表。

说明:

demo_fields中的字段顺序,须和content中的字段顺序保持一致。

最大个数:200

parse_type

String

结构化类型参数(json、split、nginx、built_in、custom_regex)。

regex_rules

String

正则表达式(使用正则结构化规则时候需要)。

最大长度:5000

layers

Integer

最大解析层数(使用JSON方式结构化需要)。

最大值:3

tokenizer

String

分隔符(使用分隔符结构化时需要)。

log_format

String

Nginx配置规则(使用分隔符结构化时需要)。

tag_fields

Array of TagField objects

tag字段列表(使用tag字段解析时需要,其中系统模板不支持使用tag字段)。

最大个数:200

rule

StructRule object

结构化方式

表4 DemoFields

参数

是否必选

参数类型

描述

fieldName

String

字段名称

最小长度:1

最大长度:50

userDefinedName

String

自定义别名(json,Nginx方式中按需添加)

最小长度:1

最大长度:64

type

String

字段数据类型。

可选范围:string、long、float

isAnalysis

Boolean

预留字段。

content

String

字段内容。

说明:

在系统模板中,此参数为demoLog。

index

Integer

序号

表5 TagField

参数

是否必选

参数类型

描述

fieldName

String

字段名称

最小长度:1

最大长度:50

content

String

示例字段。

最小长度:1

最大长度:64

type

String

字段数据类型。可选范围:string、long、float

isAnalysis

Boolean

预留字段。

表6 StructRule

参数

是否必选

参数类型

描述

type

String

内置系统模板类型

param

String

系统模板名称

响应参数

状态码:200

表7 响应Body参数

参数

参数类型

描述

-

String

状态码:400

表8 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

枚举值:

  • SVCSTG.ALS.200201

  • SVCSTG.ALS.200340

  • SVCSTG.ALS.200332

  • SVCSTG.ALS.200209

  • SVCSTG.ALS.200.339

error_msg

String

调用失败响应信息描述。

枚举值:

  • parseType is invalid/ smart extra failed./ The number of demo_fields and rules is not equal

  • {字段名/别名} is repeated with internal fields

  • userDefinedName repeat./ field name repeat

  • check logContent type error

  • nginx log_format is error

状态码:401

表9 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

枚举值:

  • LTS.0403

error_msg

String

调用失败响应信息描述。

枚举值:

  • Invalid projectId

状态码:403

表10 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

枚举值:

  • LTS.0403

error_msg

String

调用失败响应信息描述。

枚举值:

  • Invalid projectId

状态码:500

表11 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

枚举值:

  • LTS.0202

error_msg

String

调用失败响应信息描述。

枚举值:

  • Failed to query lts struct log

状态码:503

表12 响应Body参数

参数

参数类型

描述

-

String

请求示例

  • 修改VPC方式的结构化配置。

    PUT https://{endpoint}/v2/{project_id}/lts/struct/template
    
    {
      "content" : "1 5f67944957444bd6bb4fe3b367de8f3d 1d515d18-1b36-47dc-a983-bd6512aed4bd 192.168.0.154 192.168.3.25 38929 53 17 1 96 1548752136 1548752736 ACCEPT OK",
      "demo_fields" : [ {
        "fieldName" : "version",
        "content" : 1,
        "type" : "long"
      }, {
        "fieldName" : "project_id",
        "content" : "5f67944957444bd6bb4fe3b367de8f3d",
        "type" : "string"
      }, {
        "fieldName" : "interface_id",
        "content" : "1d515d18-1b36-47dc-a983-bd6512aed4bd",
        "type" : "string"
      }, {
        "fieldName" : "srcaddr",
        "content" : "192.168.0.154",
        "type" : "string"
      }, {
        "fieldName" : "dstaddr",
        "content" : "192.168.3.25",
        "type" : "string"
      }, {
        "fieldName" : "srcport",
        "content" : "38929",
        "type" : "long"
      }, {
        "fieldName" : "dstport",
        "content" : "53",
        "type" : "long"
      }, {
        "fieldName" : "protocol",
        "content" : "17",
        "type" : "long"
      }, {
        "fieldName" : "packets",
        "content" : "1",
        "type" : "long"
      }, {
        "fieldName" : "bytes",
        "content" : "96",
        "type" : "long"
      }, {
        "fieldName" : "start",
        "content" : "1548752136",
        "type" : "long"
      }, {
        "fieldName" : "end",
        "content" : "1548752736",
        "type" : "long"
      }, {
        "fieldName" : "action",
        "content" : "ACCEPT",
        "type" : "string"
      }, {
        "fieldName" : "log_status",
        "content" : "OK",
        "type" : "string"
      } ],
      "rule" : {
        "type" : "built_in",
        "param" : "VPC"
      },
      "log_group_id" : " ",
      "log_stream_id" : " ",
      "project_id" : " ",
      "parse_type" : " ",
      "tag_fields" : [ {
        "fieldName" : "hostIP",
        "content" : "192.168.2.134",
        "type" : "string",
        "isAnalysis" : true
      } ]
    }
  • 修改ELB方式的结构化配置。

    PUT https://{endpoint}/v2/{project_id}/lts/struct/template
    
    {
      "content" : "1594727856.337 e7c37d97-e922-457c-bbf3-dsadeqac 2020-07-14T19:57:36+08:00 elb_01 192.0.0.0:88888 200 \"GET http://prod.sss.ads.sg2.aaa/loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada HTTP/1.1\" 233 293 138 0.001 \"200\" \"0.000\" \"0.001\" \"0.001\" \"100.0.0.0:9999\" \"lua-resty-http/0.14 (Lua) ngx_lua/10000\" \"-\" \"-\" loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa listener_6077809b-913f-466d-a96c-376f08882d5d 08cc2b3f68aa4dddd1e6a90dddd1688348a4480 pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b \"-\" 2fb78dsadadq1213das1121dab146ad3cb0 -:80 \"101.0.0.0:10000\" - - - - 9739",
      "demo_fields" : [ {
        "fieldName" : "msec",
        "content" : "1594727856.337",
        "type" : "float"
      }, {
        "fieldName" : "access_log_topic_id",
        "content" : "e7c37d97-e922-457c-bbf3-dsadeqac",
        "type" : "string"
      }, {
        "fieldName" : "time_iso8601",
        "content" : "2020-07-14T19:57:36+08:00",
        "type" : "string"
      }, {
        "fieldName" : "log_ver",
        "content" : "elb_01",
        "type" : "string"
      }, {
        "fieldName" : "remote_addr",
        "content" : "192.0.0.0",
        "type" : "string"
      }, {
        "fieldName" : "remote_port",
        "content" : "88888",
        "type" : "long"
      }, {
        "fieldName" : "status",
        "content" : "200",
        "type" : "long"
      }, {
        "fieldName" : "request_method",
        "content" : "GET",
        "type" : "string"
      }, {
        "fieldName" : "scheme",
        "content" : "http",
        "type" : "string"
      }, {
        "fieldName" : "host",
        "content" : "prod.sss.ads.sg2.aaa",
        "type" : "string"
      }, {
        "fieldName" : "router_request_uri",
        "content" : "loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada",
        "type" : "string"
      }, {
        "fieldName" : "server_protocol",
        "content" : "HTTP/1.1",
        "type" : "string"
      }, {
        "fieldName" : "request_length",
        "content" : "233",
        "type" : "long"
      }, {
        "fieldName" : "bytes_sent",
        "content" : "293",
        "type" : "long"
      }, {
        "fieldName" : "body_bytes_sent",
        "content" : "138",
        "type" : "long"
      }, {
        "fieldName" : "request_time",
        "content" : "0.001",
        "type" : "float"
      }, {
        "fieldName" : "upstream_status",
        "content" : "200",
        "type" : "long"
      }, {
        "fieldName" : "upstream_connect_time",
        "content" : "0.000",
        "type" : "float"
      }, {
        "fieldName" : "upstream_header_time",
        "content" : "0.001",
        "type" : "float"
      }, {
        "fieldName" : "upstream_response_time",
        "content" : "0.001",
        "type" : "float"
      }, {
        "fieldName" : "upstream_addr",
        "content" : "100.0.0.0:9999",
        "type" : "string"
      }, {
        "fieldName" : "http_user_agent",
        "content" : "lua-resty-http/0.14 (Lua) ngx_lua/10000",
        "type" : "string"
      }, {
        "fieldName" : "http_referer",
        "content" : "-",
        "type" : "string"
      }, {
        "fieldName" : "http_x_forwarded_for",
        "content" : "-",
        "type" : "string"
      }, {
        "fieldName" : "lb_name",
        "content" : "loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa",
        "type" : "string"
      }, {
        "fieldName" : "listener_name",
        "content" : "listener_6077809b-913f-466d-a96c-376f08882d5d",
        "type" : "string"
      }, {
        "fieldName" : "listener_id",
        "content" : "08cc2b3f68aa4dddd1e6a90dddd1688348a4480",
        "type" : "string"
      }, {
        "fieldName" : "pool_name",
        "content" : "pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b",
        "type" : "string"
      }, {
        "fieldName" : "member_name",
        "content" : "-",
        "type" : "string"
      }, {
        "fieldName" : "tenant_id",
        "content" : "2fb78dsadadq1213das1121dab146ad3cb0",
        "type" : "string"
      }, {
        "fieldName" : "eip_address",
        "content" : "-",
        "type" : "string"
      }, {
        "fieldName" : "eip_port",
        "content" : "80",
        "type" : "long"
      }, {
        "fieldName" : "upstream_addr_priv",
        "content" : "101.0.0.0:10000",
        "type" : "string"
      }, {
        "fieldName" : "certificate_id",
        "content" : "-",
        "type" : "string"
      }, {
        "fieldName" : "ssl_protocol",
        "content" : "-",
        "type" : "string"
      }, {
        "fieldName" : "ssl_cipher",
        "content" : "-",
        "type" : "string"
      }, {
        "fieldName" : "sni_domain_name",
        "content" : "-",
        "type" : "string"
      }, {
        "fieldName" : "tcpinfo_rtt",
        "content" : "9739",
        "type" : "long"
      } ],
      "rule" : {
        "type" : "built_in",
        "param" : "ELB"
      },
      "tag_fields" : [ {
        "fieldName" : "hostIP",
        "content" : "192.168.2.134",
        "type" : "string",
        "isAnalysis" : true
      } ],
      "log_group_id" : " ",
      "log_stream_id" : " ",
      "project_id" : " ",
      "parse_type" : " "
    }

响应示例

状态码:200

请求响应成功, 成功修改结构化配置。

{ 
    "2a473356cca5487f8373be891bffc1cf_8a75b77d-7d72-4d7e-8c50-a24562cf8b0b_fd5e1a7c-7412-475d-a013-8891d539574e"
}

状态码:400

BadRequest。非法请求。 建议根据error_msg直接修改该请求,不要重试该请求。

{
  "errorCode" : "LTS.0612",
  "errorMessage" : "timee fieldType is error"
}

状态码:401

AuthFailed。鉴权失败, 请确认token后再次请求 。

{
  "error_code" : "LTS.0414",
  "error_msg" : "Invalid token"
}

状态码:403

Forbidden。

请求被拒绝访问。

返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。

{
  "error_code" : "LTS.0001",
  "error_msg" : "Invalid projectId"
}

状态码:500

InternalServerError。

表明服务端能被请求访问到,但是服务内部出错。

{
  "error_code" : "LTS.0102",
  "error_msg" : "Failed to create log group"
}

SDK代码示例

SDK代码示例如下。

  • 修改VPC方式的结构化配置。

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.lts.v2.region.LtsRegion;
    import com.huaweicloud.sdk.lts.v2.*;
    import com.huaweicloud.sdk.lts.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class UpdateStructTemplateSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            LtsClient client = LtsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(LtsRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateStructTemplateRequest request = new UpdateStructTemplateRequest();
            LtsStructTemplateInfo body = new LtsStructTemplateInfo();
            Rule rulebody = new Rule();
            rulebody.withType("built_in")
                .withParam("VPC");
            List<TagField> listbodyTagFields = new ArrayList<>();
            listbodyTagFields.add(
                new TagField()
                    .withFieldName("hostIP")
                    .withType("string")
                    .withContent("192.168.2.134")
                    .withIsAnalysis(true)
            );
            List<StructFieldInfo> listbodyDemoFields = new ArrayList<>();
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1")
                    .withFieldName("version")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("5f67944957444bd6bb4fe3b367de8f3d")
                    .withFieldName("project_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1d515d18-1b36-47dc-a983-bd6512aed4bd")
                    .withFieldName("interface_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("192.168.0.154")
                    .withFieldName("srcaddr")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("192.168.3.25")
                    .withFieldName("dstaddr")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("38929")
                    .withFieldName("srcport")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("53")
                    .withFieldName("dstport")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("17")
                    .withFieldName("protocol")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1")
                    .withFieldName("packets")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("96")
                    .withFieldName("bytes")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1548752136")
                    .withFieldName("start")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1548752736")
                    .withFieldName("end")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("ACCEPT")
                    .withFieldName("action")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("OK")
                    .withFieldName("log_status")
                    .withType("string")
            );
            body.withRule(rulebody);
            body.withProjectId(" ");
            body.withLogStreamId(" ");
            body.withParseType(LtsStructTemplateInfo.ParseTypeEnum.fromValue(" "));
            body.withLogGroupId(" ");
            body.withContent("1 5f67944957444bd6bb4fe3b367de8f3d 1d515d18-1b36-47dc-a983-bd6512aed4bd 192.168.0.154 192.168.3.25 38929 53 17 1 96 1548752136 1548752736 ACCEPT OK");
            body.withTagFields(listbodyTagFields);
            body.withDemoFields(listbodyDemoFields);
            request.withBody(body);
            try {
                UpdateStructTemplateResponse response = client.updateStructTemplate(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 修改ELB方式的结构化配置。

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.lts.v2.region.LtsRegion;
    import com.huaweicloud.sdk.lts.v2.*;
    import com.huaweicloud.sdk.lts.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class UpdateStructTemplateSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            LtsClient client = LtsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(LtsRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateStructTemplateRequest request = new UpdateStructTemplateRequest();
            LtsStructTemplateInfo body = new LtsStructTemplateInfo();
            Rule rulebody = new Rule();
            rulebody.withType("built_in")
                .withParam("ELB");
            List<TagField> listbodyTagFields = new ArrayList<>();
            listbodyTagFields.add(
                new TagField()
                    .withFieldName("hostIP")
                    .withType("string")
                    .withContent("192.168.2.134")
                    .withIsAnalysis(true)
            );
            List<StructFieldInfo> listbodyDemoFields = new ArrayList<>();
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1594727856.337")
                    .withFieldName("msec")
                    .withType("float")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("e7c37d97-e922-457c-bbf3-dsadeqac")
                    .withFieldName("access_log_topic_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("2020-07-14T19:57:36+08:00")
                    .withFieldName("time_iso8601")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("elb_01")
                    .withFieldName("log_ver")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("192.0.0.0")
                    .withFieldName("remote_addr")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("88888")
                    .withFieldName("remote_port")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("200")
                    .withFieldName("status")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("GET")
                    .withFieldName("request_method")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("http")
                    .withFieldName("scheme")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("prod.sss.ads.sg2.aaa")
                    .withFieldName("host")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada")
                    .withFieldName("router_request_uri")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("HTTP/1.1")
                    .withFieldName("server_protocol")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("233")
                    .withFieldName("request_length")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("293")
                    .withFieldName("bytes_sent")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("138")
                    .withFieldName("body_bytes_sent")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("0.001")
                    .withFieldName("request_time")
                    .withType("float")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("200")
                    .withFieldName("upstream_status")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("0.000")
                    .withFieldName("upstream_connect_time")
                    .withType("float")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("0.001")
                    .withFieldName("upstream_header_time")
                    .withType("float")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("0.001")
                    .withFieldName("upstream_response_time")
                    .withType("float")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("100.0.0.0:9999")
                    .withFieldName("upstream_addr")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("lua-resty-http/0.14 (Lua) ngx_lua/10000")
                    .withFieldName("http_user_agent")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("http_referer")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("http_x_forwarded_for")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa")
                    .withFieldName("lb_name")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("listener_6077809b-913f-466d-a96c-376f08882d5d")
                    .withFieldName("listener_name")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("08cc2b3f68aa4dddd1e6a90dddd1688348a4480")
                    .withFieldName("listener_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b")
                    .withFieldName("pool_name")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("member_name")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("2fb78dsadadq1213das1121dab146ad3cb0")
                    .withFieldName("tenant_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("eip_address")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("80")
                    .withFieldName("eip_port")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("101.0.0.0:10000")
                    .withFieldName("upstream_addr_priv")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("certificate_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("ssl_protocol")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("ssl_cipher")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("sni_domain_name")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("9739")
                    .withFieldName("tcpinfo_rtt")
                    .withType("long")
            );
            body.withRule(rulebody);
            body.withProjectId(" ");
            body.withLogStreamId(" ");
            body.withParseType(LtsStructTemplateInfo.ParseTypeEnum.fromValue(" "));
            body.withLogGroupId(" ");
            body.withContent("1594727856.337 e7c37d97-e922-457c-bbf3-dsadeqac 2020-07-14T19:57:36+08:00 elb_01 192.0.0.0:88888 200 "GET http://prod.sss.ads.sg2.aaa/loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada HTTP/1.1" 233 293 138 0.001 "200" "0.000" "0.001" "0.001" "100.0.0.0:9999" "lua-resty-http/0.14 (Lua) ngx_lua/10000" "-" "-" loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa listener_6077809b-913f-466d-a96c-376f08882d5d 08cc2b3f68aa4dddd1e6a90dddd1688348a4480 pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b "-" 2fb78dsadadq1213das1121dab146ad3cb0 -:80 "101.0.0.0:10000" - - - - 9739");
            body.withTagFields(listbodyTagFields);
            body.withDemoFields(listbodyDemoFields);
            request.withBody(body);
            try {
                UpdateStructTemplateResponse response = client.updateStructTemplate(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 修改VPC方式的结构化配置。

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdklts.v2.region.lts_region import LtsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdklts.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = LtsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(LtsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateStructTemplateRequest()
            rulebody = Rule(
                type="built_in",
                param="VPC"
            )
            listTagFieldsbody = [
                TagField(
                    field_name="hostIP",
                    type="string",
                    content="192.168.2.134",
                    is_analysis=True
                )
            ]
            listDemoFieldsbody = [
                StructFieldInfo(
                    content="1",
                    field_name="version",
                    type="long"
                ),
                StructFieldInfo(
                    content="5f67944957444bd6bb4fe3b367de8f3d",
                    field_name="project_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="1d515d18-1b36-47dc-a983-bd6512aed4bd",
                    field_name="interface_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="192.168.0.154",
                    field_name="srcaddr",
                    type="string"
                ),
                StructFieldInfo(
                    content="192.168.3.25",
                    field_name="dstaddr",
                    type="string"
                ),
                StructFieldInfo(
                    content="38929",
                    field_name="srcport",
                    type="long"
                ),
                StructFieldInfo(
                    content="53",
                    field_name="dstport",
                    type="long"
                ),
                StructFieldInfo(
                    content="17",
                    field_name="protocol",
                    type="long"
                ),
                StructFieldInfo(
                    content="1",
                    field_name="packets",
                    type="long"
                ),
                StructFieldInfo(
                    content="96",
                    field_name="bytes",
                    type="long"
                ),
                StructFieldInfo(
                    content="1548752136",
                    field_name="start",
                    type="long"
                ),
                StructFieldInfo(
                    content="1548752736",
                    field_name="end",
                    type="long"
                ),
                StructFieldInfo(
                    content="ACCEPT",
                    field_name="action",
                    type="string"
                ),
                StructFieldInfo(
                    content="OK",
                    field_name="log_status",
                    type="string"
                )
            ]
            request.body = LtsStructTemplateInfo(
                rule=rulebody,
                project_id=" ",
                log_stream_id=" ",
                parse_type=" ",
                log_group_id=" ",
                content="1 5f67944957444bd6bb4fe3b367de8f3d 1d515d18-1b36-47dc-a983-bd6512aed4bd 192.168.0.154 192.168.3.25 38929 53 17 1 96 1548752136 1548752736 ACCEPT OK",
                tag_fields=listTagFieldsbody,
                demo_fields=listDemoFieldsbody
            )
            response = client.update_struct_template(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 修改ELB方式的结构化配置。

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdklts.v2.region.lts_region import LtsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdklts.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = LtsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(LtsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateStructTemplateRequest()
            rulebody = Rule(
                type="built_in",
                param="ELB"
            )
            listTagFieldsbody = [
                TagField(
                    field_name="hostIP",
                    type="string",
                    content="192.168.2.134",
                    is_analysis=True
                )
            ]
            listDemoFieldsbody = [
                StructFieldInfo(
                    content="1594727856.337",
                    field_name="msec",
                    type="float"
                ),
                StructFieldInfo(
                    content="e7c37d97-e922-457c-bbf3-dsadeqac",
                    field_name="access_log_topic_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="2020-07-14T19:57:36+08:00",
                    field_name="time_iso8601",
                    type="string"
                ),
                StructFieldInfo(
                    content="elb_01",
                    field_name="log_ver",
                    type="string"
                ),
                StructFieldInfo(
                    content="192.0.0.0",
                    field_name="remote_addr",
                    type="string"
                ),
                StructFieldInfo(
                    content="88888",
                    field_name="remote_port",
                    type="long"
                ),
                StructFieldInfo(
                    content="200",
                    field_name="status",
                    type="long"
                ),
                StructFieldInfo(
                    content="GET",
                    field_name="request_method",
                    type="string"
                ),
                StructFieldInfo(
                    content="http",
                    field_name="scheme",
                    type="string"
                ),
                StructFieldInfo(
                    content="prod.sss.ads.sg2.aaa",
                    field_name="host",
                    type="string"
                ),
                StructFieldInfo(
                    content="loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada",
                    field_name="router_request_uri",
                    type="string"
                ),
                StructFieldInfo(
                    content="HTTP/1.1",
                    field_name="server_protocol",
                    type="string"
                ),
                StructFieldInfo(
                    content="233",
                    field_name="request_length",
                    type="long"
                ),
                StructFieldInfo(
                    content="293",
                    field_name="bytes_sent",
                    type="long"
                ),
                StructFieldInfo(
                    content="138",
                    field_name="body_bytes_sent",
                    type="long"
                ),
                StructFieldInfo(
                    content="0.001",
                    field_name="request_time",
                    type="float"
                ),
                StructFieldInfo(
                    content="200",
                    field_name="upstream_status",
                    type="long"
                ),
                StructFieldInfo(
                    content="0.000",
                    field_name="upstream_connect_time",
                    type="float"
                ),
                StructFieldInfo(
                    content="0.001",
                    field_name="upstream_header_time",
                    type="float"
                ),
                StructFieldInfo(
                    content="0.001",
                    field_name="upstream_response_time",
                    type="float"
                ),
                StructFieldInfo(
                    content="100.0.0.0:9999",
                    field_name="upstream_addr",
                    type="string"
                ),
                StructFieldInfo(
                    content="lua-resty-http/0.14 (Lua) ngx_lua/10000",
                    field_name="http_user_agent",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="http_referer",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="http_x_forwarded_for",
                    type="string"
                ),
                StructFieldInfo(
                    content="loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa",
                    field_name="lb_name",
                    type="string"
                ),
                StructFieldInfo(
                    content="listener_6077809b-913f-466d-a96c-376f08882d5d",
                    field_name="listener_name",
                    type="string"
                ),
                StructFieldInfo(
                    content="08cc2b3f68aa4dddd1e6a90dddd1688348a4480",
                    field_name="listener_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b",
                    field_name="pool_name",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="member_name",
                    type="string"
                ),
                StructFieldInfo(
                    content="2fb78dsadadq1213das1121dab146ad3cb0",
                    field_name="tenant_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="eip_address",
                    type="string"
                ),
                StructFieldInfo(
                    content="80",
                    field_name="eip_port",
                    type="long"
                ),
                StructFieldInfo(
                    content="101.0.0.0:10000",
                    field_name="upstream_addr_priv",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="certificate_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="ssl_protocol",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="ssl_cipher",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="sni_domain_name",
                    type="string"
                ),
                StructFieldInfo(
                    content="9739",
                    field_name="tcpinfo_rtt",
                    type="long"
                )
            ]
            request.body = LtsStructTemplateInfo(
                rule=rulebody,
                project_id=" ",
                log_stream_id=" ",
                parse_type=" ",
                log_group_id=" ",
                content="1594727856.337 e7c37d97-e922-457c-bbf3-dsadeqac 2020-07-14T19:57:36+08:00 elb_01 192.0.0.0:88888 200 "GET http://prod.sss.ads.sg2.aaa/loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada HTTP/1.1" 233 293 138 0.001 "200" "0.000" "0.001" "0.001" "100.0.0.0:9999" "lua-resty-http/0.14 (Lua) ngx_lua/10000" "-" "-" loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa listener_6077809b-913f-466d-a96c-376f08882d5d 08cc2b3f68aa4dddd1e6a90dddd1688348a4480 pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b "-" 2fb78dsadadq1213das1121dab146ad3cb0 -:80 "101.0.0.0:10000" - - - - 9739",
                tag_fields=listTagFieldsbody,
                demo_fields=listDemoFieldsbody
            )
            response = client.update_struct_template(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 修改VPC方式的结构化配置。

  • 修改ELB方式的结构化配置。

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

  • 修改VPC方式的结构化配置。

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.lts.v2.region.LtsRegion;
    import com.huaweicloud.sdk.lts.v2.*;
    import com.huaweicloud.sdk.lts.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class UpdateStructTemplateSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            LtsClient client = LtsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(LtsRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateStructTemplateRequest request = new UpdateStructTemplateRequest();
            LtsStructTemplateInfo body = new LtsStructTemplateInfo();
            Rule rulebody = new Rule();
            rulebody.withType("built_in")
                .withParam("VPC");
            List<TagField> listbodyTagFields = new ArrayList<>();
            listbodyTagFields.add(
                new TagField()
                    .withFieldName("hostIP")
                    .withType("string")
                    .withContent("192.168.2.134")
                    .withIsAnalysis(true)
            );
            List<StructFieldInfo> listbodyDemoFields = new ArrayList<>();
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1")
                    .withFieldName("version")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("5f67944957444bd6bb4fe3b367de8f3d")
                    .withFieldName("project_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1d515d18-1b36-47dc-a983-bd6512aed4bd")
                    .withFieldName("interface_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("192.168.0.154")
                    .withFieldName("srcaddr")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("192.168.3.25")
                    .withFieldName("dstaddr")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("38929")
                    .withFieldName("srcport")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("53")
                    .withFieldName("dstport")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("17")
                    .withFieldName("protocol")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1")
                    .withFieldName("packets")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("96")
                    .withFieldName("bytes")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1548752136")
                    .withFieldName("start")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1548752736")
                    .withFieldName("end")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("ACCEPT")
                    .withFieldName("action")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("OK")
                    .withFieldName("log_status")
                    .withType("string")
            );
            body.withRule(rulebody);
            body.withProjectId(" ");
            body.withLogStreamId(" ");
            body.withParseType(LtsStructTemplateInfo.ParseTypeEnum.fromValue(" "));
            body.withLogGroupId(" ");
            body.withContent("1 5f67944957444bd6bb4fe3b367de8f3d 1d515d18-1b36-47dc-a983-bd6512aed4bd 192.168.0.154 192.168.3.25 38929 53 17 1 96 1548752136 1548752736 ACCEPT OK");
            body.withTagFields(listbodyTagFields);
            body.withDemoFields(listbodyDemoFields);
            request.withBody(body);
            try {
                UpdateStructTemplateResponse response = client.updateStructTemplate(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 修改ELB方式的结构化配置。

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.lts.v2.region.LtsRegion;
    import com.huaweicloud.sdk.lts.v2.*;
    import com.huaweicloud.sdk.lts.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class UpdateStructTemplateSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            LtsClient client = LtsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(LtsRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateStructTemplateRequest request = new UpdateStructTemplateRequest();
            LtsStructTemplateInfo body = new LtsStructTemplateInfo();
            Rule rulebody = new Rule();
            rulebody.withType("built_in")
                .withParam("ELB");
            List<TagField> listbodyTagFields = new ArrayList<>();
            listbodyTagFields.add(
                new TagField()
                    .withFieldName("hostIP")
                    .withType("string")
                    .withContent("192.168.2.134")
                    .withIsAnalysis(true)
            );
            List<StructFieldInfo> listbodyDemoFields = new ArrayList<>();
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("1594727856.337")
                    .withFieldName("msec")
                    .withType("float")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("e7c37d97-e922-457c-bbf3-dsadeqac")
                    .withFieldName("access_log_topic_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("2020-07-14T19:57:36+08:00")
                    .withFieldName("time_iso8601")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("elb_01")
                    .withFieldName("log_ver")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("192.0.0.0")
                    .withFieldName("remote_addr")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("88888")
                    .withFieldName("remote_port")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("200")
                    .withFieldName("status")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("GET")
                    .withFieldName("request_method")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("http")
                    .withFieldName("scheme")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("prod.sss.ads.sg2.aaa")
                    .withFieldName("host")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada")
                    .withFieldName("router_request_uri")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("HTTP/1.1")
                    .withFieldName("server_protocol")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("233")
                    .withFieldName("request_length")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("293")
                    .withFieldName("bytes_sent")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("138")
                    .withFieldName("body_bytes_sent")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("0.001")
                    .withFieldName("request_time")
                    .withType("float")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("200")
                    .withFieldName("upstream_status")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("0.000")
                    .withFieldName("upstream_connect_time")
                    .withType("float")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("0.001")
                    .withFieldName("upstream_header_time")
                    .withType("float")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("0.001")
                    .withFieldName("upstream_response_time")
                    .withType("float")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("100.0.0.0:9999")
                    .withFieldName("upstream_addr")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("lua-resty-http/0.14 (Lua) ngx_lua/10000")
                    .withFieldName("http_user_agent")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("http_referer")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("http_x_forwarded_for")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa")
                    .withFieldName("lb_name")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("listener_6077809b-913f-466d-a96c-376f08882d5d")
                    .withFieldName("listener_name")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("08cc2b3f68aa4dddd1e6a90dddd1688348a4480")
                    .withFieldName("listener_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b")
                    .withFieldName("pool_name")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("member_name")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("2fb78dsadadq1213das1121dab146ad3cb0")
                    .withFieldName("tenant_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("eip_address")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("80")
                    .withFieldName("eip_port")
                    .withType("long")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("101.0.0.0:10000")
                    .withFieldName("upstream_addr_priv")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("certificate_id")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("ssl_protocol")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("ssl_cipher")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("-")
                    .withFieldName("sni_domain_name")
                    .withType("string")
            );
            listbodyDemoFields.add(
                new StructFieldInfo()
                    .withContent("9739")
                    .withFieldName("tcpinfo_rtt")
                    .withType("long")
            );
            body.withRule(rulebody);
            body.withProjectId(" ");
            body.withLogStreamId(" ");
            body.withParseType(LtsStructTemplateInfo.ParseTypeEnum.fromValue(" "));
            body.withLogGroupId(" ");
            body.withContent("1594727856.337 e7c37d97-e922-457c-bbf3-dsadeqac 2020-07-14T19:57:36+08:00 elb_01 192.0.0.0:88888 200 "GET http://prod.sss.ads.sg2.aaa/loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada HTTP/1.1" 233 293 138 0.001 "200" "0.000" "0.001" "0.001" "100.0.0.0:9999" "lua-resty-http/0.14 (Lua) ngx_lua/10000" "-" "-" loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa listener_6077809b-913f-466d-a96c-376f08882d5d 08cc2b3f68aa4dddd1e6a90dddd1688348a4480 pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b "-" 2fb78dsadadq1213das1121dab146ad3cb0 -:80 "101.0.0.0:10000" - - - - 9739");
            body.withTagFields(listbodyTagFields);
            body.withDemoFields(listbodyDemoFields);
            request.withBody(body);
            try {
                UpdateStructTemplateResponse response = client.updateStructTemplate(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 修改VPC方式的结构化配置。

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdklts.v2.region.lts_region import LtsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdklts.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = LtsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(LtsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateStructTemplateRequest()
            rulebody = Rule(
                type="built_in",
                param="VPC"
            )
            listTagFieldsbody = [
                TagField(
                    field_name="hostIP",
                    type="string",
                    content="192.168.2.134",
                    is_analysis=True
                )
            ]
            listDemoFieldsbody = [
                StructFieldInfo(
                    content="1",
                    field_name="version",
                    type="long"
                ),
                StructFieldInfo(
                    content="5f67944957444bd6bb4fe3b367de8f3d",
                    field_name="project_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="1d515d18-1b36-47dc-a983-bd6512aed4bd",
                    field_name="interface_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="192.168.0.154",
                    field_name="srcaddr",
                    type="string"
                ),
                StructFieldInfo(
                    content="192.168.3.25",
                    field_name="dstaddr",
                    type="string"
                ),
                StructFieldInfo(
                    content="38929",
                    field_name="srcport",
                    type="long"
                ),
                StructFieldInfo(
                    content="53",
                    field_name="dstport",
                    type="long"
                ),
                StructFieldInfo(
                    content="17",
                    field_name="protocol",
                    type="long"
                ),
                StructFieldInfo(
                    content="1",
                    field_name="packets",
                    type="long"
                ),
                StructFieldInfo(
                    content="96",
                    field_name="bytes",
                    type="long"
                ),
                StructFieldInfo(
                    content="1548752136",
                    field_name="start",
                    type="long"
                ),
                StructFieldInfo(
                    content="1548752736",
                    field_name="end",
                    type="long"
                ),
                StructFieldInfo(
                    content="ACCEPT",
                    field_name="action",
                    type="string"
                ),
                StructFieldInfo(
                    content="OK",
                    field_name="log_status",
                    type="string"
                )
            ]
            request.body = LtsStructTemplateInfo(
                rule=rulebody,
                project_id=" ",
                log_stream_id=" ",
                parse_type=" ",
                log_group_id=" ",
                content="1 5f67944957444bd6bb4fe3b367de8f3d 1d515d18-1b36-47dc-a983-bd6512aed4bd 192.168.0.154 192.168.3.25 38929 53 17 1 96 1548752136 1548752736 ACCEPT OK",
                tag_fields=listTagFieldsbody,
                demo_fields=listDemoFieldsbody
            )
            response = client.update_struct_template(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 修改ELB方式的结构化配置。

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdklts.v2.region.lts_region import LtsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdklts.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = LtsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(LtsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateStructTemplateRequest()
            rulebody = Rule(
                type="built_in",
                param="ELB"
            )
            listTagFieldsbody = [
                TagField(
                    field_name="hostIP",
                    type="string",
                    content="192.168.2.134",
                    is_analysis=True
                )
            ]
            listDemoFieldsbody = [
                StructFieldInfo(
                    content="1594727856.337",
                    field_name="msec",
                    type="float"
                ),
                StructFieldInfo(
                    content="e7c37d97-e922-457c-bbf3-dsadeqac",
                    field_name="access_log_topic_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="2020-07-14T19:57:36+08:00",
                    field_name="time_iso8601",
                    type="string"
                ),
                StructFieldInfo(
                    content="elb_01",
                    field_name="log_ver",
                    type="string"
                ),
                StructFieldInfo(
                    content="192.0.0.0",
                    field_name="remote_addr",
                    type="string"
                ),
                StructFieldInfo(
                    content="88888",
                    field_name="remote_port",
                    type="long"
                ),
                StructFieldInfo(
                    content="200",
                    field_name="status",
                    type="long"
                ),
                StructFieldInfo(
                    content="GET",
                    field_name="request_method",
                    type="string"
                ),
                StructFieldInfo(
                    content="http",
                    field_name="scheme",
                    type="string"
                ),
                StructFieldInfo(
                    content="prod.sss.ads.sg2.aaa",
                    field_name="host",
                    type="string"
                ),
                StructFieldInfo(
                    content="loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada",
                    field_name="router_request_uri",
                    type="string"
                ),
                StructFieldInfo(
                    content="HTTP/1.1",
                    field_name="server_protocol",
                    type="string"
                ),
                StructFieldInfo(
                    content="233",
                    field_name="request_length",
                    type="long"
                ),
                StructFieldInfo(
                    content="293",
                    field_name="bytes_sent",
                    type="long"
                ),
                StructFieldInfo(
                    content="138",
                    field_name="body_bytes_sent",
                    type="long"
                ),
                StructFieldInfo(
                    content="0.001",
                    field_name="request_time",
                    type="float"
                ),
                StructFieldInfo(
                    content="200",
                    field_name="upstream_status",
                    type="long"
                ),
                StructFieldInfo(
                    content="0.000",
                    field_name="upstream_connect_time",
                    type="float"
                ),
                StructFieldInfo(
                    content="0.001",
                    field_name="upstream_header_time",
                    type="float"
                ),
                StructFieldInfo(
                    content="0.001",
                    field_name="upstream_response_time",
                    type="float"
                ),
                StructFieldInfo(
                    content="100.0.0.0:9999",
                    field_name="upstream_addr",
                    type="string"
                ),
                StructFieldInfo(
                    content="lua-resty-http/0.14 (Lua) ngx_lua/10000",
                    field_name="http_user_agent",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="http_referer",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="http_x_forwarded_for",
                    type="string"
                ),
                StructFieldInfo(
                    content="loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa",
                    field_name="lb_name",
                    type="string"
                ),
                StructFieldInfo(
                    content="listener_6077809b-913f-466d-a96c-376f08882d5d",
                    field_name="listener_name",
                    type="string"
                ),
                StructFieldInfo(
                    content="08cc2b3f68aa4dddd1e6a90dddd1688348a4480",
                    field_name="listener_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b",
                    field_name="pool_name",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="member_name",
                    type="string"
                ),
                StructFieldInfo(
                    content="2fb78dsadadq1213das1121dab146ad3cb0",
                    field_name="tenant_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="eip_address",
                    type="string"
                ),
                StructFieldInfo(
                    content="80",
                    field_name="eip_port",
                    type="long"
                ),
                StructFieldInfo(
                    content="101.0.0.0:10000",
                    field_name="upstream_addr_priv",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="certificate_id",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="ssl_protocol",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="ssl_cipher",
                    type="string"
                ),
                StructFieldInfo(
                    content="-",
                    field_name="sni_domain_name",
                    type="string"
                ),
                StructFieldInfo(
                    content="9739",
                    field_name="tcpinfo_rtt",
                    type="long"
                )
            ]
            request.body = LtsStructTemplateInfo(
                rule=rulebody,
                project_id=" ",
                log_stream_id=" ",
                parse_type=" ",
                log_group_id=" ",
                content="1594727856.337 e7c37d97-e922-457c-bbf3-dsadeqac 2020-07-14T19:57:36+08:00 elb_01 192.0.0.0:88888 200 "GET http://prod.sss.ads.sg2.aaa/loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada HTTP/1.1" 233 293 138 0.001 "200" "0.000" "0.001" "0.001" "100.0.0.0:9999" "lua-resty-http/0.14 (Lua) ngx_lua/10000" "-" "-" loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa listener_6077809b-913f-466d-a96c-376f08882d5d 08cc2b3f68aa4dddd1e6a90dddd1688348a4480 pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b "-" 2fb78dsadadq1213das1121dab146ad3cb0 -:80 "101.0.0.0:10000" - - - - 9739",
                tag_fields=listTagFieldsbody,
                demo_fields=listDemoFieldsbody
            )
            response = client.update_struct_template(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 修改VPC方式的结构化配置。

  • 修改ELB方式的结构化配置。

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求响应成功, 成功修改结构化配置。

400

BadRequest。非法请求。 建议根据error_msg直接修改该请求,不要重试该请求。

401

AuthFailed。鉴权失败, 请确认token后再次请求 。

403

Forbidden。

请求被拒绝访问。

返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。

500

InternalServerError。

表明服务端能被请求访问到,但是服务内部出错。

503

ServiceUnavailable。

被请求的服务无效, 服务不可用。

错误码

请参见错误码

提示

您即将访问非华为云网站,请注意账号财产安全

文档反馈

文档反馈

意见反馈

0/500

标记内容

同时提交标记内容