查询防火墙日志
功能介绍
查询防火墙日志
调用方法
请参见如何调用API。
URI
POST /v1/{project_id}/cfw/{fw_instance_id}/logs
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
filters |
否 |
Array of Filter objects |
参数解释: 过滤条件 约束限制: 不涉及 取值范围: 1-1024 默认取值: 不涉及 |
limit |
是 |
Integer |
参数解释: 每页显示个数 约束限制: 不涉及 取值范围: 1-1024 默认取值: 不涉及 |
offset |
否 |
Integer |
参数解释: 偏移量 约束限制: 第一页为空,其他页不为空 取值范围: 相对于上一页的偏移量 默认取值: 不涉及 |
log_id |
否 |
String |
参数解释: 文档ID 约束限制: 第一页为空,其他页不为空 取值范围: 上一次查询最后一条数据的log_id 默认取值: 不涉及 |
next_date |
否 |
Long |
参数解释: 下个日期 约束限制: 第一页为空,其他页不为空 取值范围: 查询流量日志时为上一次查询最后一条数据的end_time 查询访问控制日志时为上一次查询最后一条数据的hit_time 查询访问控制日志时为上一次查询最后一条数据的event_time 查询URL日志时为上一次查询最后一条数据的hit_time 默认取值: 不涉及 |
start_time |
是 |
Long |
参数解释: 开始时间 约束限制: 不涉及 取值范围: 毫秒级时间戳 默认取值: 不涉及 |
end_time |
是 |
Long |
参数解释: 结束时间 约束限制: 不涉及 取值范围: 毫秒级时间戳 默认取值: 不涉及 |
log_type |
是 |
String |
参数解释: 日志类型 约束限制: 不涉及 取值范围: internet为南北向日志、nat为nat场景日志,vpc为东西向日志,vgw为vgw场景日志 默认取值: 不涉及 |
type |
是 |
String |
参数解释: 日志类型 约束限制: 不涉及 取值范围: attack为攻击日志、acl 访问控制日志,flow 流量日志,url url日志 默认取值: 不涉及 |
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
data |
data object |
参数解释: 日志 取值范围: 不涉及 |
参数 |
参数类型 |
描述 |
---|---|---|
limit |
Integer |
参数解释: 条数 取值范围: 不涉及 |
records |
Array of LogVO objects |
参数解释: 日志 取值范围: 不涉及 |
total |
Long |
参数解释: 记录总数 取值范围: 不涉及 |
参数 |
参数类型 |
描述 |
---|---|---|
app |
String |
参数解释: 应用 取值范围: 不涉及 |
bytes |
Double |
参数解释: 流字节数,流量日志字段 取值范围: 不涉及 |
direction |
String |
参数解释: 会话方向 取值范围: out2in 外到内访问 in2out 内到外访问 |
dst_host |
String |
参数解释: 流字节数,访问控制日志和流量日志中存在 取值范围: 目的网址 |
dst_ip |
String |
参数解释: 目的IP 取值范围: 不涉及 |
dst_port |
Integer |
参数解释: 目的端口 取值范围: 不涉及 |
end_time |
Long |
参数解释: 会话结束时间,流量日志字段 取值范围: 不涉及 |
log_id |
String |
参数解释: 日志ID,用于分页查询 取值范围: 不涉及 |
packets |
Double |
参数解释: 流包数,流量日志字段 取值范围: 不涉及 |
protocol |
String |
参数解释: 协议 取值范围: 不涉及 |
src_ip |
String |
参数解释: 源Ip 取值范围: 不涉及 |
src_port |
Integer |
参数解释: 源端口 取值范围: 不涉及 |
start_time |
Long |
参数解释: 会话开始时间,流量日志字段 取值范围: 不涉及 |
dst_region_id |
AnyType |
参数解释: 目的地区ID 取值范围: 不涉及 |
dst_region_name |
String |
参数解释: 目的地区名称 取值范围: 不涉及 |
dst_province_id |
String |
参数解释: 目的省份ID 取值范围: 不涉及 |
dst_province_name |
String |
参数解释: 目的省份名称 取值范围: 不涉及 |
dst_city_id |
String |
参数解释: 目的城市ID 取值范围: 不涉及 |
dst_city_name |
String |
参数解释: 目的城市名称 取值范围: 不涉及 |
src_region_id |
String |
参数解释: 源地区ID 取值范围: 不涉及 |
src_region_name |
String |
参数解释: 源地区名称 取值范围: 不涉及 |
src_province_id |
String |
参数解释: 源省份ID 取值范围: 不涉及 |
src_province_name |
String |
参数解释: 源省份名称 取值范围: 不涉及 |
src_city_id |
String |
参数解释: 源城市ID 取值范围: 不涉及 |
src_city_name |
String |
参数解释: 源城市名称 取值范围: 不涉及 |
vgw_id |
String |
参数解释: 虚拟网关ID 取值范围: 不涉及 |
sctp_verification_tag |
Long |
参数解释: sctp验证标签,流量日志字段 取值范围: 不涉及 |
sctp_is_handshake_flow |
String |
参数解释: sctp握手流,流量日志字段 取值范围: 不涉及 |
qos_rule_id |
String |
参数解释: qos规则ID,流量日志、访问控制日志存在 取值范围: 不涉及 |
qos_rule_name |
String |
参数解释: qos规则名称,流量日志、访问控制日志存在 取值范围: 不涉及 |
qos_channel_id |
String |
参数解释: qos通道ID,流量日志字段 取值范围: 不涉及 |
qos_channel_name |
String |
参数解释: qos通道名称,流量日志字段 取值范围: 不涉及 |
qos_drop_packets |
Double |
参数解释: qos丢包数,流量日志字段 取值范围: 不涉及 |
qos_drop_bytes |
Double |
参数解释: qos丢弃字节,流量日志字段 取值范围: 不涉及 |
qos_rule_type |
Integer |
参数解释: qos规则类型,流量日志、访问控制日志存在 取值范围: 不涉及 |
qos_channel_type |
Integer |
参数解释: qos通道类型,流量日志字段 取值范围: 不涉及 |
action |
String |
参数解释: 动作,攻击日志、访问控制日志、URL日志存在 取值范围: 不涉及 |
url |
String |
参数解释: url,URL日志字段 取值范围: 不涉及 |
hit_time |
Long |
参数解释: 命中时间,访问控制日志、URL日志存在 取值范围: 不涉及 |
rule_id |
String |
参数解释: 规则ID,访问控制日志、URL日志存在 取值范围: 不涉及 |
rule_name |
String |
参数解释: 规则名称,访问控制日志、URL日志存在 取值范围: 不涉及 |
rule_type |
Integer |
参数解释: 规则类型,访问控制日志和URL日志字段 取值范围: 不涉及 |
attack_rule |
String |
参数解释: 规则类型,攻击日志字段 取值范围: 不涉及 |
attack_rule_id |
String |
参数解释: 攻击规则ID,攻击日志字段 取值范围: 不涉及 |
attack_type |
String |
参数解释: 攻击类型,攻击日志字段 取值范围: 不涉及 |
event_time |
Long |
参数解释: 事件时间,攻击日志字段 取值范围: 不涉及 |
level |
String |
参数解释: 攻击等级,攻击日志字段 取值范围: 不涉及 |
packet |
String |
参数解释: 规则载荷,攻击日志字段 取值范围: 不涉及 |
source |
String |
参数解释: 攻击来源,攻击日志字段 取值范围: 不涉及 |
real_ip |
String |
参数解释: 真实IP,攻击日志字段 取值范围: 不涉及 |
tag |
Integer |
参数解释: 标签类型,攻击日志字段 取值范围: 1 WAF回源IP |
状态码:400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
参数解释: 错误码 取值范围: 不涉及 |
error_msg |
String |
参数解释: 错误描述 取值范围: 不涉及 |
请求示例
项目ID为a16df7cf1d094befa6bbc72cbf51e93a,防火墙ID为fcd04edd-428a-4631-bef5-46a924293cca,时间范围为1751952647737到1751963447737,查询数量1000条,过滤条件为目的IP为方向为100.85.219.117,查询互联网边界的流量日志
https://{Endpoint}//v1/a16df7cf1d094befa6bbc72cbf51e93a/cfw/fcd04edd-428a-4631-bef5-46a924293cca/logs { "limit" : 1000, "filters" : [ { "field" : "dst_ip", "operator" : "equal", "values" : [ "100.85.219.117" ] } ], "start_time" : 1751952647737, "end_time" : 1751963447737, "log_type" : "internet", "type" : "flow" }
响应示例
状态码:200
OK
{ "data" : { "limit" : 1000, "records" : [ { "app" : "DNS", "bytes" : 87, "direction" : "in2out", "dst_ip" : "100.85.219.117", "dst_port" : 53, "end_time" : 1751963431000, "log_id" : "73861", "packets" : 1, "protocol" : "UDP", "src_ip" : "100.93.2.30", "src_port" : 55637, "start_time" : 1751963369000 } ], "total" : 1 } }
状态码:400
Bad Request
{ "error_code" : "CFW.00200003", "error_msg" : "参数错误" }
SDK代码示例
SDK代码示例如下。
项目ID为a16df7cf1d094befa6bbc72cbf51e93a,防火墙ID为fcd04edd-428a-4631-bef5-46a924293cca,时间范围为1751952647737到1751963447737,查询数量1000条,过滤条件为目的IP为方向为100.85.219.117,查询互联网边界的流量日志
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 |
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.cfw.v1.region.CfwRegion; import com.huaweicloud.sdk.cfw.v1.*; import com.huaweicloud.sdk.cfw.v1.model.*; import java.util.List; import java.util.ArrayList; public class ListLogsSolution { 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); CfwClient client = CfwClient.newBuilder() .withCredential(auth) .withRegion(CfwRegion.valueOf("<YOUR REGION>")) .build(); ListLogsRequest request = new ListLogsRequest(); request.withFwInstanceId("{fw_instance_id}"); ListLogsRequestBody body = new ListLogsRequestBody(); List<String> listFiltersValues = new ArrayList<>(); listFiltersValues.add("100.85.219.117"); List<Filter> listbodyFilters = new ArrayList<>(); listbodyFilters.add( new Filter() .withField("dst_ip") .withValues(listFiltersValues) .withOperator(Filter.OperatorEnum.fromValue("equal")) ); body.withType(ListLogsRequestBody.TypeEnum.fromValue("flow")); body.withLogType(ListLogsRequestBody.LogTypeEnum.fromValue("internet")); body.withEndTime(1751963447737L); body.withStartTime(1751952647737L); body.withLimit(1000); body.withFilters(listbodyFilters); request.withBody(body); try { ListLogsResponse response = client.listLogs(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()); } } } |
项目ID为a16df7cf1d094befa6bbc72cbf51e93a,防火墙ID为fcd04edd-428a-4631-bef5-46a924293cca,时间范围为1751952647737到1751963447737,查询数量1000条,过滤条件为目的IP为方向为100.85.219.117,查询互联网边界的流量日志
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 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcfw.v1.region.cfw_region import CfwRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcfw.v1 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 = CfwClient.new_builder() \ .with_credentials(credentials) \ .with_region(CfwRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListLogsRequest() request.fw_instance_id = "{fw_instance_id}" listValuesFilters = [ "100.85.219.117" ] listFiltersbody = [ Filter( field="dst_ip", values=listValuesFilters, operator="equal" ) ] request.body = ListLogsRequestBody( type="flow", log_type="internet", end_time=1751963447737, start_time=1751952647737, limit=1000, filters=listFiltersbody ) response = client.list_logs(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
项目ID为a16df7cf1d094befa6bbc72cbf51e93a,防火墙ID为fcd04edd-428a-4631-bef5-46a924293cca,时间范围为1751952647737到1751963447737,查询数量1000条,过滤条件为目的IP为方向为100.85.219.117,查询互联网边界的流量日志
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 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cfw "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1/region" ) func 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.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cfw.NewCfwClient( cfw.CfwClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListLogsRequest{} request.FwInstanceId = "{fw_instance_id}" var listValuesFilters = []string{ "100.85.219.117", } var listFiltersbody = []model.Filter{ { Field: "dst_ip", Values: &listValuesFilters, Operator: model.GetFilterOperatorEnum().EQUAL, }, } request.Body = &model.ListLogsRequestBody{ Type: model.GetListLogsRequestBodyTypeEnum().FLOW, LogType: model.GetListLogsRequestBodyLogTypeEnum().INTERNET, EndTime: int64(1751963447737), StartTime: int64(1751952647737), Limit: int32(1000), Filters: &listFiltersbody, } response, err := client.ListLogs(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
OK |
400 |
Bad Request |
错误码
请参见错误码。