Network probe
Initialization
Confirm Endpoint
Before configuring the endpoint for SDK usage, please refer to the developer guide section on VPC Service Domain Name to understand endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to the VPC section in the Region Selection Guide. The probe service is part of the VPC service and adopts the VPC service domain name.
Retrieve access key
To use Baidu AI Cloud products, you need to have a Baidu AI Cloud account, along with a valid AK (Access Key ID) and SK (Secret Access Key) for signature authentication.
Your AK/SK information can be obtained and understood through the following steps:
After obtaining the key, it must be provided as a parameter during Client configuration. The SDK integrates an authentication mechanism, so you don’t need to understand the underlying authentication process. Simply fill in the AK/SK in the designated fields as required, and the SDK will automatically handle the authentication for you.
Create a new probe client
The Probe client is designed for the probe service, offering developers a variety of methods to interact seamlessly with the service.
Create a new probe client with AK/SK
Users can refer to the following code to create a new probe client to access probe with AK/SK:
1import (
2 "github.com/baidubce/bce-sdk-go/services/vpc"
3)
4func main() {
5 // User’s Access Key ID and Secret Access Key
6 ACCESS_KEY_ID, SECRET_ACCESS_KEY := <your-access-key-id>, <your-secret-access-key>
7 // User-specified Endpoint
8 ENDPOINT := <domain-name>
9 // Initialize a probe client
10 probeClient, err := vpc.NewClient(AK, SK, ENDPOINT)
11}
In the code above, ACCESS_KEY_ID corresponds to “Access Key ID” in the console. SECRET_ACCESS_KEY corresponds to “Access Key Secret” in the console. Refer to the Guide - How to Retrieve AKSK. The third parameter ENDPOINT is a user-specified domain name. If left empty, the default domain name will be used as the VPC service address.
Note:The
endpointparameter must be defined with the domain name of the specified region. For example, if the service is located in Beijing, the endpoint will bebcc.bj.baidubce.com.
Create a probe client with STS
Request STS Token
Probe allows temporary third-party access authorization through the STS mechanism. The STS (Security Token Service) is Baidu AI Cloud’s temporary authorization service. Using STS, you can generate access credentials with customized validity periods and permissions for third-party users. These users can then leverage these credentials to directly call Baidu AI Cloud APIs or SDKs and access cloud resources.
To use the probe service through STS, users first need to request an authorization string via the STS client.
Create probe client with STS Token
Once the STS token is obtained, integrate it into the probe client to facilitate token-based probe client creation.
Code example
The GO SDK implements the STS service API. Below is a complete example for requesting an STS token and creating an probe client object:
1import (
2 "fmt"
3 "github.com/baidubce/bce-sdk-go/auth" //Import the authentication module
4 "github.com/baidubce/bce-sdk-go/services/vpc" //Import VPC service module
5 "github.com/baidubce/bce-sdk-go/services/sts" //Import the Baige service module
6)
7func main() {
8 //Create a Client object for the STS service, using the default Endpoint
9 AK, SK := <your-access-key-id>, <your-secret-access-key>
10 stsClient, err := sts.NewClient(AK, SK)
11 if err != nil {
12 fmt.Println("create sts client object :", err)
13 return
14 }
15 //Obtain a temporary authentication token with a validity period of 60 seconds and an empty ACL
16 stsObj, err := stsClient.GetSessionToken(60, "")
17 if err != nil {
18 fmt.Println("get session token failed:", err)
19 return
20 }
21 fmt.Println("GetSessionToken result:")
22 fmt.Println(" accessKeyId:", stsObj.AccessKeyId)
23 fmt.Println(" secretAccessKey:", stsObj.SecretAccessKey)
24 fmt.Println(" sessionToken:", stsObj.SessionToken)
25 fmt.Println(" createTime:", stsObj.CreateTime)
26 fmt.Println(" expiration:", stsObj.Expiration)
27 fmt.Println(" userId:", stsObj.UserId)
28 //Create a probe client object using the requested temporary STS, with the default endpoint
29 probeClient, err := vpc.NewClient(stsObj.AccessKeyId, stsObj.SecretAccessKey, "bcc.bj.baidubce.com")
30 if err != nil {
31 fmt.Println("create Probe client failed:", err)
32 return
33 }
34 stsCredential, err := auth.NewSessionBceCredentials(
35 stsObj.AccessKeyId,
36 stsObj.SecretAccessKey,
37 stsObj.SessionToken)
38 if err != nil {
39 fmt.Println("create sts credential object failed:", err)
40 return
41 }
42 probeClient.Config.Credentials = stsCredential
43}
Note: Currently, when configuring a probe client with STS, regardless of where the corresponding probe service endpoint is located, the STS endpoint must be set to http://sts.bj.baidubce.com. This default is utilized when creating an STS object in the above code.
Configure HTTPS protocol for probe access
Network probe supports the HTTPS protocol. By specifying HTTPS in the endpoint when creating a probe client object, users can access the network probe service via HTTPS in the Probe GO SDK:
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2 ENDPOINT := ""https://bcc.bj.baidubce.com" // Specify the use of HTTPS protocol
3AK, SK := <your-access-key-id>, <your-secret-access-key>
4probeClient, _ := vpc.NewClient(AK, SK, ENDPOINT)
Configure probe client
If users need to configure specific parameters for the probe client, they can customize the configuration using the exported Config field of the probe client object after its creation. This allows for configuring parameters such as proxy and maximum number of connections for the client.
Use a proxy
The following code snippet enables the client to access probe service using a proxy:
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2 // Create a probe client object
3AK, SK := <your-access-key-id>, <your-secret-access-key>
4ENDPOINT := "bcc.bj.baidubce.com"
5probeClient, _ := vpc.NewClient(AK, SK, ENDPOINT)
6 // Use the local port 8080 for the proxy
7probeClient.Config.ProxyUrl = "127.0.0.1:8080"
Set network parameters
Users can configure network parameters using the following example code:
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2AK, SK := <your-access-key-id>, <your-secret-access-key>
3ENDPOINT := "bcc.bj.baidubce.com"
4probeClient, _ := vpc.NewClient(AK, SK, ENDPOINT)
5 // Configure to not retry, default: Back Off retry
6probeClient.Config.Retry = bce.NewNoRetryPolicy()
7 // Configure connection timeout to 30 seconds
8probeClient.Config.ConnectionTimeoutInMillis = 30 * 1000
Configure options for generating signature strings
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2AK, SK := <your-access-key-id>, <your-secret-access-key>
3ENDPOINT := "bcc.bj.baidubce.com"
4probeClient, _ := vpc.NewClient(AK, SK, ENDPOINT)
5 // Configure the HTTP request header Host for signing
6headersToSign := map[string]struct{}{"Host": struct{}{}}
7probeClient.Config.SignOption.HeadersToSign = HeadersToSign
8 // Configure the validity period of the signature to 30 seconds
9probeClient.Config.SignOption.ExpireSeconds = 30
Parameter description
When using the GO SDK to access probe, the Config field of the created probe client object supports the following parameters, as shown in the table below:
| ConfigMap name | Types | Meaning |
|---|---|---|
| Endpoint | string | Domain name for service requests |
| ProxyUrl | string | The proxy address for client requests |
| Region | string | Region for resource requests |
| UserAgent | string | User name, HTTP request’s User-Agent header |
| Credentials | *auth.BceCredentials | Authentication object for requests, divided into regular AK/SK and STS |
| SignOption | *auth.SignOptions | Options for authentication string signing |
| Retry | RetryPolicy | Retry policy for connections |
| ConnectionTimeoutInMillis | int | Connection timeout, in milliseconds, defaulting to 20 minutes |
Description:
- The
Credentialsis created using theauth.NewBceCredentialsandauth.NewSessionBceCredentialsfunctions. The former is used by default, while the latter is used for STS certification. See "Create a probe client with STS" for details. - The
SignOptionfield represents options when generating a signature string, as detailed in the table below:
| Name | Types | Meaning |
|---|---|---|
| HeadersToSign | map[string]struct{} | HTTP headers used when generating the signature string |
| Timestamp | int64 | Timestamp used in the generated signature string, defaulting to the value at the time of sending request |
| ExpireSeconds | int | Validity period of the signature string |
1 Among configuration options, HeadersToSign defaults to `Host`, `Content-Type`, `Content-Length` and `Content-MD5`; TimeStamp is typically set to zero, indicating that the timestamp at the time of generating the certification string shall be used, and users generally shall not explicitly specify the value for this field; ExpireSeconds defaults to 1,800 seconds or 30 minutes.
- The
Retryfield specifies the retry policy, currently supporting two types:NoRetryPolicyandBackOffRetryPolicy. By default, the latter is used. This retry policy specifies the maximum number of retries, the maximum retry duration, and the retry base. Retries increase exponentially based on the retry base multiplied by 2 until the maximum number of retries or the maximum retry duration is reached.
Probe management
Create Network Probe
Refer to the following code to create a probe.
Function declaration
1type CreateProbeArgs struct {
2 ClientToken string `json:"-"`
3 Name string `json:"name"`
4 VpcId string `json:"vpcId"`
5 SubnetId string `json:"subnetId"`
6 Protocol string `json:"protocol"`
7 Frequency int `json:"frequency"`
8 DestIp string `json:"destIp"`
9 DestPort string `json:"destPort"`
10 SourceIps []string `json:"sourceIps"`
11 SourceIpNum int `json:"sourceIpNum,omitempty"`
12 Description string `json:"description,omitempty"`
13 Payload string `json:"payload,omitempty"`
14}
15type CreateProbeResult struct {
16 ProbeId string `json:"probeId"`
17}
18func (c *Client) CreateProbe(args *CreateProbeArgs) (*CreateProbeResult, error)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Xl6a5e196
Response value
- Operation succeeded:
1{
2 "probeId": "probe-s2kyrsdnvk287ziu",
3}
- Operation failed:
Throw an exception. For the exception list, refer to Exception List
Code example
For specific code examples, refer to example_create_probe.go
Query network probe list.
Refer to the following code to query the list of probes.
Function declaration
1type ListProbesArgs struct {
2 Marker string
3 MaxKeys int
4}
5type Probe struct {
6 ProbeId string `json:"probeId"`
7 Name string `json:"name"`
8 VpcId string `json:"vpcId"`
9 SubnetId string `json:"subnetId"`
10 Protocol string `json:"protocol"`
11 Frequency int `json:"frequency"`
12 DestIp string `json:"destIp"`
13 DestPort string `json:"destPort"`
14 SourceIps []string `json:"sourceIps"`
15 SourceIpNum int `json:"sourceIpNum,omitempty"`
16 Description string `json:"description,omitempty"`
17 Payload string `json:"payload,omitempty"`
18 Status string `json:"status"`
19}
20type ListProbesResult struct {
21 Probes []Probe `json:"probes"`
22 Marker string `json:"marker"`
23 IsTruncated bool `json:"isTruncated"`
24 NextMarker string `json:"nextMarker"`
25 MaxKeys int `json:"maxKeys"`
26}
27func (c *Client) ListProbes(args *ListProbesArgs) (*ListProbesResult, error)
This API retrieves information for all eligible probes.
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Ul6lld6c5
Response Value
- Operation succeeded:
1{
2 "nextMarker": "probe-68sfxk5ihf85hjs",
3 "marker": "probe-6gfqbgfypumvmyh0",
4 "maxKeys": 1,
5 "isTruncated": true,
6 "probes": [
7 {
8 "description":"dsdsds",
9 "destIp":"1.2.3.4",
10 "destPort":11,
11 "frequency":20,
12 "name":"probe1",
13 "payload":"qqqqqqwwwww",
14 "probeId":"probe-6gfqbgfypumvmyh0",
15 "protocol":"UDP",
16 "sourceIps":[
17 "192.168.0.4"
18 ],
19 "status":"active",
20 "subnetId":"sbn-qz55vemw0n40",
21 "vpcId":"vpc-2pa2x0bjt26i"
22 }
23 ]
24 }
- Operation failed:
Throw an exception. For the exception list, refer to Exception List
Code example
For specific code examples, refer to example_list_probes.go
View probe details
Refer to the following code to retrieve detailed information for a specific probe.
Function declaration
1type Probe struct {
2 ProbeId string `json:"probeId"`
3 Name string `json:"name"`
4 VpcId string `json:"vpcId"`
5 SubnetId string `json:"subnetId"`
6 Protocol string `json:"protocol"`
7 Frequency int `json:"frequency"`
8 DestIp string `json:"destIp"`
9 DestPort string `json:"destPort"`
10 SourceIps []string `json:"sourceIps"`
11 SourceIpNum int `json:"sourceIpNum,omitempty"`
12 Description string `json:"description,omitempty"`
13 Payload string `json:"payload,omitempty"`
14 Status string `json:"status"`
15}
16func (c *Client) GetProbeDetail(probeId string) (*Probe, error)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/5l6lt3w4d
Response value
- Operation succeeded:
1 {
2 "probeId":"probe-6gfqbgfypumvmyh0",
3 "description":"dsdsds",
4 "destIp":"1.2.3.4",
5 "destPort":11,
6 "frequency":20,
7 "name":"probe1",
8 "payload":"qqqqqqwwwww",
9 "protocol":"UDP",
10 "sourceIps":[
11 "192.168.0.4"
12 ],
13 "status":"active",
14 "subnetId":"sbn-qz55vemw0n40",
15 "vpcId":"vpc-2pa2x0bjt26i"
16}
- Operation failed:
Throw an exception. For the exception list, refer to Exception List
Code example
For specific code examples, refer to example_get_probe_detail.go
Update probe
Refer to the following code to update information for a specific probe.
Function declaration
1type UpdateProbeArgs struct {
2 ClientToken string `json:"-"`
3 Name string `json:"name,omitempty"`
4 Frequency int `json:"frequency,omitempty"`
5 DestIp string `json:"destIp,omitempty"`
6 DestPort string `json:"destPort,omitempty"`
7 Description string `json:"description,omitempty"`
8 Payload string `json:"payload,omitempty"`
9}
10type UpdateProbeResult struct {
11 ProbeId string `json:"probeId"`
12}
13func (c *Client) UpdateProbe(probeId string, args *UpdateProbeArgs) error
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/dl6lu4bl8
Response Value
- Operation succeeded:
There are no special response parameters
- Operation failed:
Throw an exception. For the exception list, refer to: Exception List
Code example
For specific code examples, refer to example_update_probe.go
Delete network probe
Use the provided code to delete a specific probe.
Function declaration
1func (c *Client) DeleteProbe(probeId string, clientToken string) error
Parameter Meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/cl6ll9ur9
Response Value
- Operation succeeded:
There are no special response parameters
- Operation failed:
Throw an exception. For the exception list, refer to: Exception List
Code example
For specific code examples, refer to example_delete_probe.go
