antiddos

package
v0.0.0-...-63319d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2024 License: MPL-2.0, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

The Anti-DDoS traffic cleaning service (Anti-DDoS for short) defends resources (Elastic Cloud Servers (ECSs), Elastic Load Balance (ELB) instances, and Bare Metal Servers (BMSs)) on HUAWEI CLOUD against network- and application-layer distributed denial of service (DDoS) attacks and sends alarms immediately when detecting an attack. In addition, Anti-DDoS improves the utilization of bandwidth and ensures the stable running of users' services.

Example to update the Anti-DDoS defense policy of a specified EIP.

updateOpt := antiddos.UpdateOpts{
  EnableL7:            true,
  TrafficPosId:        1,
  HttpRequestPosId:    2,
  CleaningAccessPosId: 3,
  AppTypeId:           1,
}

floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635"
actual, err := antiddos.Update(client.ServiceClient(), floatingIpId, updateOpt).Extract()
if err != nil {
  panic(err)
}

Example to enable the Anti-DDoS traffic cleaning defense.

floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635"
actual, err := antiddos.Create(client.ServiceClient(), floatingIpId, createOpt).Extract()
if err != nil {
  panic(err)
}

Example to query the traffic of a specified EIP in the last 24 hours. Traffic is detected in five-minute intervals.

floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635"
actual, err := antiddos.DailyReport(client.ServiceClient(), floatingIpId).Extract()
if err != nil {
  panic(err)
}

Example to disable the Anti-DDoS traffic cleaning defense.

floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635"
actual, err := antiddos.Delete(client.ServiceClient(), floatingIpId).Extract()
if err != nil {
  panic(err)
}

Example to query configured Anti-DDoS defense policies.

floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635"
actual, err := antiddos.Get(client.ServiceClient(), floatingIpId).Extract()
if err != nil {
  panic(err)
}

Example to query the defense status of a specified EIP.

floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635"
actual, err := antiddos.GetStatus(client.ServiceClient(), floatingIpId).Extract()
if err != nil {
  panic(err)
}

Example to query the execution status of a specified Anti-DDoS configuration task.

actual, err := antiddos.GetTask(client.ServiceClient(), antiddos.GetTaskOpts{
    TaskId: "4a4fefe7-34a1-40e2-a87c-16932af3ac4a",
}).Extract()
if err != nil {
  panic(err)
}

Example to query optional Anti-DDoS defense policies.

actual, err := antiddos.ListConfigs(client.ServiceClient()).Extract()
if err != nil {
  panic(err)
}

Example to query events of a specified EIP in the last 24 hours.

floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635"
actual, err := antiddos.ListLogs(client.ServiceClient(), floatingIpId, antiddos.ListLogsOpts{
    Limit:   2,
    Offset:  1,
    SortDir: "asc",
}).Extract()
if err != nil {
  panic(err)
}

Example to query the defense statuses of all EIPs.

listOpt := antiddos.ListStatusOpts{
    Limit:  2,
    Offset: 1,
    Status: "notConfig",
    Ip:     "49.",
}

actual, err := antiddos.ListStatus(client.ServiceClient(), listOpt).Extract()
if err != nil {
  panic(err)
}

Example to query weekly defense statistics about all your EIPs.

actual, err := antiddos.WeeklyReport(client.ServiceClient(), antiddos.WeeklyReportOpts{}).Extract()
if err != nil {
  panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateURL

func CreateURL(c *golangsdk.ServiceClient, floatingIpId string) string

func DailyReportURL

func DailyReportURL(c *golangsdk.ServiceClient, floatingIpId string) string

func DeleteURL

func DeleteURL(c *golangsdk.ServiceClient, floatingIpId string) string

func GetStatusURL

func GetStatusURL(c *golangsdk.ServiceClient, floatingIpId string) string

func GetTaskURL

func GetTaskURL(c *golangsdk.ServiceClient) string

func GetURL

func GetURL(c *golangsdk.ServiceClient, floatingIpId string) string

func ListConfigsURL

func ListConfigsURL(c *golangsdk.ServiceClient) string

func ListLogsURL

func ListLogsURL(c *golangsdk.ServiceClient, floatingIpId string) string

func ListStatusURL

func ListStatusURL(c *golangsdk.ServiceClient) string

func UpdateURL

func UpdateURL(c *golangsdk.ServiceClient, floatingIpId string) string

func WeeklyReportURL

func WeeklyReportURL(c *golangsdk.ServiceClient) string

Types

type CreateOpts

type CreateOpts struct {
	// Whether to enable L7 defense
	EnableL7 bool `json:"enable_L7"`

	// Position ID of traffic. The value ranges from 1 to 9.
	TrafficPosId int `json:"traffic_pos_id"`

	// Position ID of number of HTTP requests. The value ranges from 1 to 15.
	HttpRequestPosId int `json:"http_request_pos_id"`

	// Position ID of access limit during cleaning. The value ranges from 1 to 8.
	CleaningAccessPosId int `json:"cleaning_access_pos_id"`

	// Application type ID. Possible values: 0 1
	AppTypeId int `json:"app_type_id"`
}

func (CreateOpts) ToCreateMap

func (opts CreateOpts) ToCreateMap() (map[string]interface{}, error)

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToCreateMap() (map[string]interface{}, error)
}

type CreateResponse

type CreateResponse struct {
	// Internal error code
	ErrorCode string `json:"error_code"`

	// Internal error description
	ErrorDescription string `json:"error_description"`

	// ID of a task. This ID can be used to query the status of the task. This field is reserved for use in task auditing later. It is temporarily unused.
	TaskId string `json:"task_id"`
}

type CreateResult

type CreateResult struct {
	// contains filtered or unexported fields
}

func Create

func Create(client *golangsdk.ServiceClient, floatingIpId string, opts CreateOptsBuilder) (r CreateResult)

func (CreateResult) Extract

func (r CreateResult) Extract() (*CreateResponse, error)

type DailyReportResponse

type DailyReportResponse struct {
	// Traffic in the last 24 hours
	Data []Data `json:"data"`
}

type DailyReportResult

type DailyReportResult struct {
	// contains filtered or unexported fields
}

func DailyReport

func DailyReport(client *golangsdk.ServiceClient, floatingIpId string) (r DailyReportResult)

func (DailyReportResult) Extract

func (r DailyReportResult) Extract() ([]Data, error)

type Data

type Data struct {
	// Start time
	PeriodStart int `json:"period_start"`

	// Inbound traffic (bit/s)
	BpsIn int `json:"bps_in"`

	// Attack traffic (bit/s)
	BpsAttack int `json:"bps_attack"`

	// Total traffic
	TotalBps int `json:"total_bps"`

	// Inbound packet rate (number of packets per second)
	PpsIn int `json:"pps_in"`

	// Attack packet rate (number of packets per second)
	PpsAttack int `json:"pps_attack"`

	// Total packet rate
	TotalPps int `json:"total_pps"`
}

type DdosStatus

type DdosStatus struct {
	// Floating IP address
	FloatingIpAddress string `json:"floating_ip_address"`

	// ID of an EIP
	FloatingIpId string `json:"floating_ip_id"`

	// EIP type.
	NetworkType string `json:"network_type"`

	// Defense status
	Status string `json:"status"`

	ProtecType       string `json:"protect_type"`
	TrafficThreshold int    `json:"traffic_threshold"`
	HttpThreshold    int    `json:"http_threshold"`
	BlackHoleEndTime int    `json:"blackhole_endtime"`
}

func FilterDdosStatus

func FilterDdosStatus(ddosStatus []DdosStatus, opts ListStatusOpts) ([]DdosStatus, error)

func ListStatus

func ListStatus(client *golangsdk.ServiceClient, opts ListStatusOpts) ([]DdosStatus, error)

ListStatus returns collection of DdosStatus. It accepts a ListStatusOpts struct, which allows you to filter and sort the returned collection for greater efficiency.

type DeleteResponse

type DeleteResponse struct {
	// Internal error code
	ErrorCode string `json:"error_code"`

	// Internal error description
	ErrorDescription string `json:"error_description"`

	// ID of a task. This ID can be used to query the status of the task. This field is reserved for use in task auditing later. It is temporarily unused.
	TaskId string `json:"task_id"`
}

type DeleteResult

type DeleteResult struct {
	// contains filtered or unexported fields
}

func Delete

func Delete(client *golangsdk.ServiceClient, floatingIpId string) (r DeleteResult)

func (DeleteResult) Extract

func (r DeleteResult) Extract() (*DeleteResponse, error)

type GetResponse

type GetResponse struct {
	// Whether L7 defense has been enabled
	EnableL7 bool `json:"enable_L7"`

	// Position ID of traffic. The value ranges from 1 to 9.
	TrafficPosId int `json:"traffic_pos_id"`

	// Position ID of number of HTTP requests. The value ranges from 1 to 15.
	HttpRequestPosId int `json:"http_request_pos_id"`

	// Position ID of access limit during cleaning. The value ranges from 1 to 8.
	CleaningAccessPosId int `json:"cleaning_access_pos_id"`

	// Application type ID. Possible values: 0 1
	AppTypeId int `json:"app_type_id"`
}

type GetResult

type GetResult struct {
	// contains filtered or unexported fields
}

func Get

func Get(client *golangsdk.ServiceClient, floatingIpId string) (r GetResult)

func (GetResult) Extract

func (r GetResult) Extract() (*GetResponse, error)

type GetStatusResponse

type GetStatusResponse struct {
	// Defense status
	Status string `json:"status"`
}

type GetStatusResult

type GetStatusResult struct {
	// contains filtered or unexported fields
}

func GetStatus

func GetStatus(client *golangsdk.ServiceClient, floatingIpId string) (r GetStatusResult)

func (GetStatusResult) Extract

func (r GetStatusResult) Extract() (*GetStatusResponse, error)

type GetTaskOpts

type GetTaskOpts struct {
	// Task ID (nonnegative integer) character string
	TaskId string `q:"task_id"`
}

func (GetTaskOpts) ToGetTaskQuery

func (opts GetTaskOpts) ToGetTaskQuery() (string, error)

type GetTaskOptsBuilder

type GetTaskOptsBuilder interface {
	ToGetTaskQuery() (string, error)
}

type GetTaskResponse

type GetTaskResponse struct {
	// Status of a task, which can be one of the following: success, failed, waiting, running, preprocess, ready
	TaskStatus string `json:"task_status"`

	// Additional information about a task
	TaskMsg string `json:"task_msg"`
}

type GetTaskResult

type GetTaskResult struct {
	// contains filtered or unexported fields
}

func GetTask

func GetTask(client *golangsdk.ServiceClient, opts GetTaskOptsBuilder) (r GetTaskResult)

func (GetTaskResult) Extract

func (r GetTaskResult) Extract() (*GetTaskResponse, error)

type ListConfigsResponse

type ListConfigsResponse struct {
	// List of traffic limits
	TrafficLimitedList []struct {
		// Position ID of traffic
		TrafficPosId int `json:"traffic_pos_id"`

		// Threshold of traffic per second (Mbit/s)
		TrafficPerSecond int `json:"traffic_per_second"`

		// Threshold of number of packets per second
		PacketPerSecond int `json:"packet_per_second"`
	} `json:"traffic_limited_list"`

	// List of HTTP limits
	HttpLimitedList []struct {
		// Position ID of number of HTTP requests
		HttpRequestPosId int `json:"http_request_pos_id"`

		// Threshold of number of HTTP requests per second
		HttpPacketPerSecond int `json:"http_packet_per_second"`
	} `json:"http_limited_list"`

	// List of limits of numbers of connections
	ConnectionLimitedList []struct {
		// Position ID of access limit during cleaning
		CleaningAccessPosId int `json:"cleaning_access_pos_id"`

		// Position ID of access limit during cleaning
		NewConnectionLimited int `json:"new_connection_limited"`

		// Position ID of access limit during cleaning
		TotalConnectionLimited int `json:"total_connection_limited"`
	} `json:"connection_limited_list"`
}

type ListConfigsResult

type ListConfigsResult struct {
	// contains filtered or unexported fields
}

func ListConfigs

func ListConfigs(client *golangsdk.ServiceClient) (r ListConfigsResult)

func (ListConfigsResult) Extract

type ListLogsOpts

type ListLogsOpts struct {
	// Limit of number of returned results or the maximum number of returned results of a query. The value ranges from 1 to 100, and this parameter is used together with the offset parameter. If neither limit nor offset is used, query results of all ECSs are returned.
	Limit int `q:"limit"`

	// Offset. This parameter is valid only when used together with the limit parameter.
	Offset int `q:"offset"`

	// Possible values: desc: indicates that query results are given and sorted by time in descending order. asc: indicates that query results are given and sorted by time in ascending order.The default value is desc.
	SortDir string `q:"sort_dir"`
}

func (ListLogsOpts) ToListLogsQuery

func (opts ListLogsOpts) ToListLogsQuery() (string, error)

type ListLogsOptsBuilder

type ListLogsOptsBuilder interface {
	ToListLogsQuery() (string, error)
}

type ListLogsResponse

type ListLogsResponse struct {
	// Total number of EIPs
	Total int `json:"total"`

	// List of events
	Logs []Logs `json:"logs"`
}

type ListLogsResult

type ListLogsResult struct {
	// contains filtered or unexported fields
}

func ListLogs

func ListLogs(client *golangsdk.ServiceClient, floatingIpId string, opts ListLogsOptsBuilder) (r ListLogsResult)

func (ListLogsResult) Extract

func (r ListLogsResult) Extract() ([]Logs, error)

type ListStatusOpts

type ListStatusOpts struct {
	// ID of an EIP
	FloatingIpId string

	// If this parameter is not used, the defense statuses of all ECSs are displayed in the Neutron-queried order by default.
	Status string `q:"status"`

	// Limit of number of returned results
	Limit int `q:"limit"`

	// Offset
	Offset int `q:"offset"`

	// IP address. Both IPv4 and IPv6 addresses are supported. For example, if you enter ?ip=192.168, the defense status of EIPs corresponding to 192.168.111.1 and 10.192.168.8 is returned.
	Ip string `q:"ip"`
}

type ListStatusResponse

type ListStatusResponse struct {
	// Total number of EIPs
	Total int `json:"total"`

	// List of defense statuses
	DdosStatus []DdosStatus `json:"ddosStatus"`
}

type ListStatusResult

type ListStatusResult struct {
	// contains filtered or unexported fields
}

func (ListStatusResult) Extract

func (r ListStatusResult) Extract() ([]DdosStatus, error)

Extract is a function that accepts a ListStatusOpts struct, which allows you to filter and sort the returned collection for greater efficiency.

type Logs

type Logs struct {
	// Start time
	StartTime int `json:"start_time"`

	// End time
	EndTime int `json:"end_time"`

	// Defense status, the possible value of which is one of the following: 1: indicates that traffic cleaning is underway. 2: indicates that traffic is discarded.
	Status int `json:"status"`

	// Traffic at the triggering point.
	TriggerBps int `json:"trigger_bps"`

	// Packet rate at the triggering point
	TriggerPps int `json:"trigger_pps"`

	// HTTP request rate at the triggering point
	TriggerHttpPps int `json:"trigger_http_pps"`
}

type UpdateOpts

type UpdateOpts struct {
	// Whether to enable L7 defense
	EnableL7 bool `json:"enable_L7"`

	// Position ID of traffic. The value ranges from 1 to 9.
	TrafficPosId int `json:"traffic_pos_id"`

	// Position ID of number of HTTP requests. The value ranges from 1 to 15.
	HttpRequestPosId int `json:"http_request_pos_id"`

	// Position ID of access limit during cleaning. The value ranges from 1 to 8.
	CleaningAccessPosId int `json:"cleaning_access_pos_id"`

	// Application type ID. Possible values: 0 1
	AppTypeId int `json:"app_type_id"`
}

func (UpdateOpts) ToUpdateMap

func (opts UpdateOpts) ToUpdateMap() (map[string]interface{}, error)

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToUpdateMap() (map[string]interface{}, error)
}

type UpdateResponse

type UpdateResponse struct {
	// Internal error code
	ErrorCode string `json:"error_code"`

	// Internal error description
	ErrorDescription string `json:"error_description"`

	// ID of a task. This ID can be used to query the status of the task. This field is reserved for use in task auditing later. It is temporarily unused.
	TaskId string `json:"task_id"`
}

type UpdateResult

type UpdateResult struct {
	// contains filtered or unexported fields
}

func Update

func Update(client *golangsdk.ServiceClient, floatingIpId string, opts UpdateOptsBuilder) (r UpdateResult)

func (UpdateResult) Extract

func (r UpdateResult) Extract() (*UpdateResponse, error)

type WeekData

type WeekData struct {
	// Number of DDoS attacks intercepted
	DdosInterceptTimes int `json:"ddos_intercept_times"`

	// Number of DDoS blackholes
	DdosBlackholeTimes int `json:"ddos_blackhole_times"`

	// Maximum attack traffic
	MaxAttackBps int `json:"max_attack_bps"`

	// Maximum number of attack connections
	MaxAttackConns int `json:"max_attack_conns"`

	// Start date
	PeriodStartDate time.Time `json:"period_start_date"`
}

type WeeklyReportOpts

type WeeklyReportOpts struct {
	// Start date of a seven-day period
	PeriodStartDate time.Time `q:""`
}

func (WeeklyReportOpts) ToWeeklyReportQuery

func (opts WeeklyReportOpts) ToWeeklyReportQuery() (string, error)

type WeeklyReportOptsBuilder

type WeeklyReportOptsBuilder interface {
	ToWeeklyReportQuery() (string, error)
}

type WeeklyReportResponse

type WeeklyReportResponse struct {
	// Number of DDoS attacks intercepted in a week
	DdosInterceptTimes int `json:"ddos_intercept_times"`

	// Number of DDoS attacks intercepted in a week
	Weekdata []WeekData `json:"-"`

	// Top 10 attacked IP addresses
	Top10 []struct {
		// EIP
		FloatingIpAddress string `json:"floating_ip_address"`

		// Number of DDoS attacks intercepted, including cleaning operations and blackholes
		Times int `json:"times"`
	} `json:"top10"`
}

func (*WeeklyReportResponse) UnmarshalJSON

func (r *WeeklyReportResponse) UnmarshalJSON(b []byte) error

type WeeklyReportResult

type WeeklyReportResult struct {
	// contains filtered or unexported fields
}

func WeeklyReport

func WeeklyReport(client *golangsdk.ServiceClient, opts WeeklyReportOptsBuilder) (r WeeklyReportResult)

func (WeeklyReportResult) Extract

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL