Help Center/ Virtual Private Network/ API Reference/ Application Examples/ Example 4: Creating a VPN Connection Monitor
Updated on 2024-08-23 GMT+08:00

Example 4: Creating a VPN Connection Monitor

Scenario

This section describes how to create a VPN connection monitor by calling APIs.

Prerequisites

  • You have obtained a user token if you need to use token authentication. In addition, you need to add X-Auth-Token to the request header when calling an API. For details about token authentication, see Authentication.

    The token obtained through IAM is valid for only 24 hours. When using a token for authentication, cache it to avoid frequent calling.

Data Preparation

Table 1 Key parameters in the request for creating a VPN connection monitor

Parameter

Description

Example Value

vpn_connection_id

Specifies the ID of the VPN connection to be monitored.

cae286f2-demo-a8df-va86-e22416ca1220

Procedure

  1. Create a VPN connection monitor.
    1. Send POST https://{endpoint}/v5/{project_id}/connection-monitors.
    2. Add X-Auth-Token to the request header.
    3. Specify the following parameters in the request body:
      {
          "connection_monitor": {
              "vpn_connection_id": "cae286f2-demo-a8df-va86-e22416ca1220"
          }
      }
    4. Check the response.
      • The request is successful if the following response is displayed. In the response, id indicates the ID of a VPN connection monitor.
        {
            "connection_monitor": {
                "id": "76f64229-demo-a8df-va86-3907e2815b6d",
                "vpn_connection_id": "cae286f2-demo-a8df-va86-e22416ca1220",
                "type": "gateway",
                "source_ip": "88.***.***.60",
                "destination_ip": "192.***.***.0",
                "proto_type": "icmp"
            },
            "request_id": "54af23d8-989e-445d-bb48-0a9da33d7f0f"
        }
  2. Query details about the VPN connection monitor.
    1. Send GET https://{endpoint}/v5/{project_id}/connection-monitors/{connection_monitor_id}.
    2. Add X-Auth-Token to the request header.
    3. Check the response.
      • The request is successful if the following response is displayed. In the response, id indicates the ID of a VPN connection monitor.
        {
            "connection_monitor": {
                "id": "76f64229-demo-a8df-va86-3907e2815b6d",
                "status": "ACTIVE",
                "vpn_connection_id": "cae286f2-demo-a8df-va86-e22416ca1220",
                "type": "gateway",
                "source_ip": "88.***.***.60",
                "destination_ip": "192.***.***.0",
                "proto_type": "icmp"
            },
            "request_id": "72d05395-0637-4f93-9844-b4979e9d7bdc"
        }