tencent cloud

Feedback

Quick Start with API

Last updated: 2024-09-26 15:35:06
    Note:
    This section primarily demonstrates how to use the official API of CFG to complete an experiment. The API of CFG follows the general API specifications of Tencent Cloud. For details on common parameters and request methods, see API Invocation Methods.
    

    Creation an Experiment: Create via Template

    Prepare Template ID

    Method 1: Retrieve from the Console

    Log in to the Chaotic Fault Generator, click Template Library Management, select the desired template for creating an experiment, and copy the template ID.

    Method 2: Retrieve via API

    Refer to API description in Query Knowledge Base List to obtain the required TemplateId for creating an experiment.

    API Request

    Refer to API description in Create Drill from Experience, and make the following request:
    POST / HTTP/1.1
    Host: cfg.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateTaskFromTemplate
    <Common request parameters>
    
    {
    "TemplateId": 626, # The template ID inquired from the previous step
    "TaskConfig": {
    "TaskTitle": "This is an example of creating an experiment from the API", # Experiment name, if it is not provided, the template name will be used by default.
    "TaskGroupsConfig": [
    {
    "TaskGroupInstances": [
    "ins-xxxxxxxx" # Instance object ID associated with the action group, such as resource IDs for CVM, CLB, etc.
    ]
    }
    ]
    }
    }

    API Output

    {
    "Response": {
    "RequestId": "f0aee8ac-2ed3-4a7f-a25b-f0d7d228dd30",
    "TaskId": 3256 # experiment ID
    }
    }

    Create an Experiment: Create via Action

    Prepare Resource Object ID

    Refer to API description in Query Object Type List to obtain the ObjectTypeId for the resource object required in the experiment.

    Prepare Action ID

    Refer to API description in Obtain Action Library List to obtain the ActionId for the actions required in the experiment.

    Prepare Action Parameters

    Refer to API description in Get Action Configuration Parameters to obtain the parameters for the actions required in the experiment.
    Note:
    Here are two parameters provided for creating an action experiment:
    TaskActionGeneralConfiguration: General parameter, which is optional. If it is empty, the default action parameter will be used.
    TaskActionCustomConfiguration: Custom parameter. Optional parameters have default values set. For required parameters, if the default value is empty, you must explicitly provide a value.
    Parameters should be represented in the format of `{"key1": "value1", "key2": "value2"}` and should be serialized before being passed, for example: `"{\\"domain\\": \\"www.test.com\\"}"`.
    For a clear and intuitive understanding of the specific functions of action parameters, you can see the console.
    This API returns the following:
    {
    "Response": {
    "RequestId": "3e7fa74e-9045-4f01-88d4-ee158affe905",
    Common: [ # General parameters, corresponding to TaskActionGeneralConfiguration in the subsequent action experiment creation.
    {
    "ActionId": 466,
    "ActionName": DNS tampering,
    "ConfigDetail": [
    {
    "Type": "input",
    "Lable": Action Alias,
    "Field": AliasTitle, # Action parameter key
    "DefaultValue": "", # The default value for the action parameter
    "Config": "{}",
    "Required": 0, # If it is required (0 -- No 1 -- Yes)
    "Validate": "{}",
    "Visible": "{}"
    },
    {
    "Type": "number",
    "Lable": Pre-Wait Time (s),
    "Field": "PreTimeWait",
    "DefaultValue": "0",
    Config: "{\\"max\\": 86400, \\"min\\": 0, \\"tooltip\\": \\"Only for auto-advance mode\\"}",
    "Required": 0,
    "Validate": "{}",
    "Visible": "{}"
    },
    {
    "Type": "number",
    "Lable": Post-Wait Time (s),
    "Field": "AfterTimeWait",
    "DefaultValue": "0",
    Config: "{\\"max\\": 86400, \\"min\\": 0, \\"tooltip\\": \\"Only for auto-advance mode\\"}",
    "Required": 0,
    "Validate": "{}",
    "Visible": "{}"
    },
    {
    "Type": "number",
    "Lable": Action Timeout Period (s),
    "Field": "ActionTimeout",
    "DefaultValue": "1800",
    "Config": "{\\"max\\": 86400, \\"min\\": 0, \\"tooltip\\": \\"Action timeout period\\"}",
    "Required": 0,
    "Validate": "{}",
    "Visible": "{\\"op\\": \\"<\\", \\"type\\": \\"need_insert\\", \\"value\\": 0, \\"relatedField\\": \\"ActionTimeout\\"}"
    }
    ]
    }
    ],
    Results: [ # Custom parameters, corresponding to TaskActionCustomConfiguration in the subsequent action experiment creation.
    {
    "ActionId": 466,
    "ActionName": DNS tampering,
    "ConfigDetail": [
    {
    "Type": "number",
    "Lable": Duration (s),
    "Field": "duration",
    "DefaultValue": "180",
    "Config": "{\\"max\\": 1800, \\"min\\": 0}",
    "Required": 1,
    "Validate": "{}",
    "Visible": "{}"
    },
    {
    "Type": "input",
    "Lable": Domain Name,
    "Field": "domain", # Action parameter key
    "DefaultValue": "", # The default value for the action parameter
    "Config": "{}",
    "Required": 1, # If it is required (0 -- No 1 -- Yes)
    "Validate": "{}",
    "Visible": "{}"
    },
    {
    "Type": "input",
    "Lable": "IP",
    "Field": "ip",
    "DefaultValue": "",
    "Config": "{}",
    "Required": 1,
    "Validate": "{}",
    "Visible": "{}"
    }
    ]
    }
    ],
    "ResourceOffline": []
    }
    }

    API Request

    Refer to API description in Creating an Experiment via Action, and make the following request:
    Note:
    For container-type resource objects, a unique instance is identified by the combination of {ClusterId} + {NodeName} + {NameSpace} + {PodName}. When the parameter TaskInstances is passed in, this map needs to be serialized.
    For example: "{"ClusterId":"cls-xxxx","PodName":"pod-xxxxxx","NodeName":"xxxxxxxx","NameSpace":"default-xxxxxx"}"
    POST / HTTP/1.1
    Host: cfg.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateTaskFromTemplate
    <Common request parameters>
    
    {
    "TaskActionId": 462, # Action ID
    TaskInstances: ["ins-xxxxxxxx"], # Resource object instance ID
    "TaskTitle": Network Packet Loss, # Experiment name
    TaskDescription: "This experiment was created from the openapi", # Experiment description
    TaskActionCustomConfiguration: "{\\"interfaces\\": \\"eth0\\"}" # Custom action parameters, should be serialized.
    }

    API Output

    {
    "Response": {
    "RequestId": "f0aee8ac-2ed3-4a7f-a25b-f0d7d228dd30",
    "TaskId": 150
    }
    }
    At this point, you can click Experiment management in the console to view the created experiment, or you can inquire about it through the API.
    Note:
    If you need to delete a created experiment, see the Delete Experiments API description.

    Query the Experiment

    API Request

    Refer to API description in Query Experiments, and make the following request:
    POST / HTTP/1.1
    Host: cfg.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: DescribeTask
    <Common request parameters>
    
    {
    ”RequestId“: "02185fc4-0e8f-49ed-a8d5-6d0788d0e60c",
    "TaskId": "3256" # The experiment ID returned from the experiment creation process mentioned above
    }

    API Output

    {
    "RequestId": "02185fc4-0e8f-49ed-a8d5-6d0788d0e60c",
    "Task": {
    "TaskId": 3256,
    "TaskTitle": "This is an example of creating an experiment from the API",
    "TaskDescription": "Test an empty operation action",
    "TaskTag": "",
    "TaskStatus": 1002,
    "TaskStatusType": 0,
    "TaskProtectStrategy": null,
    "TaskCreateTime": "2023-08-14 11:55:02",
    "TaskUpdateTime": "2023-08-14 14:48:00",
    "TaskStartTime": "2023-08-14 14:48:01",
    "TaskEndTime": null,
    "TaskExpect": null,
    "TaskSummary": null,
    "TaskMode": 1,
    "TaskRegionId": 1,
    "TaskPauseDuration": 60,
    "TaskOwnerUin": "100032429988",
    "TaskPlanId": null,
    "TaskPlanTitle": null,
    "TaskGroups": [
    {
    "TaskGroupActions": [
    {
    "TaskGroupInstances": [
    {
    "TaskGroupInstanceId": 24375, # Task action instance ID
    "TaskGroupInstanceObjectId": "ins-bfydnvta", # Resource object ID
    "TaskGroupInstanceStatus": 3001,
    "TaskGroupInstanceStatusType": 0,
    "TaskGroupInstanceExecuteLog": null,
    "TaskGroupInstanceStartTime": null,
    "TaskGroupInstanceEndTime": null,
    "TaskGroupInstanceCreateTime": "2023-08-14 14:48:00",
    "TaskGroupInstanceUpdateTime": "2023-08-14 14:48:00",
    "TaskGroupInstanceIsRedo": false,
    "TaskGroupInstanceExecuteTime": null
    },
    {
    "TaskGroupInstanceId": 24376, # Task action instance ID
    "TaskGroupInstanceObjectId": "ins-ehxmry76", # Resource object ID
    "TaskGroupInstanceStatus": 3001,
    "TaskGroupInstanceStatusType": 0,
    "TaskGroupInstanceExecuteLog": null,
    "TaskGroupInstanceStartTime": null,
    "TaskGroupInstanceEndTime": null,
    "TaskGroupInstanceCreateTime": "2023-08-14 14:48:00",
    "TaskGroupInstanceUpdateTime": "2023-08-14 14:48:00",
    "TaskGroupInstanceIsRedo": false,
    "TaskGroupInstanceExecuteTime": null
    }
    ],
    "TaskGroupActionId": 11395, # Task action ID
    "ActionId": 12,
    "ActionTitle": "Empty Operation",
    "ActionApiType": 1,
    "ActionType": "Platform",
    "ActionRisk": "Low risk",
    "ActionAttribute": 1,
    "TaskGroupActionOrder": 1,
    "TaskGroupActionGeneralConfiguration": "{\\"AliasTitle\\": \\"\\", \\"PreTimeWait\\": 0, \\"ActionTimeout\\": 1800, \\"AfterTimeWait\\": 0}",
    "TaskGroupActionCustomConfiguration": "{}",
    "TaskGroupActionStatus": 2002,
    "TaskGroupActionStatusType": 0,
    "TaskGroupActionRandomId": 156878,
    "TaskGroupActionRecoverId": 193278,
    "TaskGroupActionExecuteId": null,
    "TaskGroupActionCreateTime": "2023-08-14 11:55:02",
    "TaskGroupActionUpdateTime": "2023-08-14 14:48:00",
    "IsExecuteRedo": false,
    "TaskGroupActionExecuteTime": null
    },
    {
    "TaskGroupInstances": [
    {
    "TaskGroupInstanceId": 24377, # Task action instance ID
    "TaskGroupInstanceObjectId": "ins-bfydnvta", # Resource object ID
    "TaskGroupInstanceStatus": 3001,
    "TaskGroupInstanceStatusType": 0,
    "TaskGroupInstanceExecuteLog": null,
    "TaskGroupInstanceStartTime": null,
    "TaskGroupInstanceEndTime": null,
    "TaskGroupInstanceCreateTime": "2023-08-14 14:48:00",
    "TaskGroupInstanceUpdateTime": "2023-08-14 14:48:00",
    "TaskGroupInstanceIsRedo": false,
    "TaskGroupInstanceExecuteTime": null
    },
    {
    "TaskGroupInstanceId": 24378, # Task action instance ID
    "TaskGroupInstanceObjectId": "ins-ehxmry76", # Resource object ID
    "TaskGroupInstanceStatus": 3001,
    "TaskGroupInstanceStatusType": 0,
    "TaskGroupInstanceExecuteLog": null,
    "TaskGroupInstanceStartTime": null,
    "TaskGroupInstanceEndTime": null,
    "TaskGroupInstanceCreateTime": "2023-08-14 14:48:00",
    "TaskGroupInstanceUpdateTime": "2023-08-14 14:48:00",
    "TaskGroupInstanceIsRedo": false,
    "TaskGroupInstanceExecuteTime": null
    }
    ],
    "TaskGroupActionId": 11396, # Task action ID
    "ActionId": 13,
    "ActionTitle": "Empty Operation (rollback)",
    "ActionApiType": 1,
    "ActionType": "Platform",
    "ActionRisk": "Low risk",
    "ActionAttribute": 2,
    "TaskGroupActionOrder": 2,
    "TaskGroupActionGeneralConfiguration": "{\\"PreTimeWait\\": 0, \\"ActionTimeout\\": 1800, \\"AfterTimeWait\\": 0}",
    "TaskGroupActionCustomConfiguration": "{}",
    "TaskGroupActionStatus": 2001,
    "TaskGroupActionStatusType": 0,
    "TaskGroupActionRandomId": 193278,
    "TaskGroupActionRecoverId": null,
    "TaskGroupActionExecuteId": 156878,
    "TaskGroupActionCreateTime": "2023-08-14 11:55:02",
    "TaskGroupActionUpdateTime": "2023-08-14 11:55:02",
    "IsExecuteRedo": false,
    "TaskGroupActionExecuteTime": null
    }
    ],
    "TaskGroupId": 4684, # Action group ID
    "TaskGroupTitle": "abc",
    "TaskGroupDescription": "abc",
    "TaskGroupOrder": 1,
    "TaskGroupMode": 1,
    "TaskGroupInstanceList": [
    "ins-bfydnvta",
    "ins-ehxmry76"
    ],
    "ObjectTypeId": 1,
    "TaskGroupCreateTime": "2023-08-14 11:55:02",
    "TaskGroupUpdateTime": "2023-08-14 11:55:02",
    "TaskGroupInstancesExecuteRule": [
    {
    "TaskGroupInstancesExecuteMode": 1
    }
    ],
    "TaskGroupSelectedInstanceList": [
    "ins-bfydnvta",
    "ins-ehxmry76"
    ],
    "TaskGroupDiscardInstanceList": []
    }
    ],
    "TaskMonitors": [],
    "TaskPolicy": null,
    "Tags": []
    },
    "ReportInfo": null
    }

    Execute the Experiment

    API Request

    Refer to API description in Execute Experiments, and make the following request:
    POST / HTTP/1.1
    Host: cfg.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: ExecuteTask
    <Common request parameters>
    
    {
    "TaskId": "3256"
    }

    API Output

    {
    "Response": {
    "RequestId": "46924e75-a149-4130-aac0-853dbf0abea9"
    }
    }

    Execute Action

    API Request

    Refer to API description in Execute Action, and make the following request:
    POST / HTTP/1.1
    Host: cfg.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: ExecuteTaskInstance
    <Common request parameters>
    
    {
    "TaskId": "3256",
    "TaskActionId": "11396", # Task action ID (obtained from the experiment inquiry response)
    "TaskInstanceIds": [
    "xxxxxxxx-01", # Task action instance ID (obtained from the experiment inquiry response)
    "xxxxxxxx-02"
    ],
    "IsOperateAll": true, # Whether to execute the entire task. When true is set, TaskInstanceIds will be ignored, and all instances provided during experiment creation will be executed.
    "ActionType": 2, # 2--Execute, 3--Skip, 5--Retry
    "TaskGroupId": 4684, # Action group ID (obtained from the experiment inquiry response)
    }

    API Output

    {
    "Response": {
    "RequestId": "6549ed1a-911f-46dd-b6cd-2c02d5bd180f"
    }
    }
    Note:
    The action execution here supports skip and retry operations, which can be controlled by adjusting the value of ActionType:
    3: Skip
    5: Retry

    End the Experiment

    API Request

    Refer to API description in End Experiment, and make the following request:
    POST / HTTP/1.1
    Host: cfg.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: ModifyTaskRunStatus
    <Common request parameters>
    
    {
    "TaskId": 3256, # Experiment task ID
    "Status": 1004, # End status code, no need to modify
    "Summary": "This experiment meets the expectations", # Experiment conclusion
    "IsExpect": true, # Is the execution result as expected?
    }

    API Output

    {
    "Response": {
    "RequestId": "e38eca72-e4ae-4a86-9696-7df399e672bd"
    }
    }
    Note:
    To view the logs of the experiment, refer to API description in Getting Experiments Process Log.
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support