Catchpoint 提供RESTful API 给用户,特别是那些需要将Catchpiont 融入到CI/CD中的客户中,提供的这些API 很有用。Catchpoint只支持OAuth 2.0 验证方式。需要使用API的用户通过Catchpoint 的UI取得 Secret 和Key,然后通过 https://io.catchpoint.com/ui/api/token 换取token,已进行endpoint的访问。 Token需要转换成base64,每个Token30分钟到期。
1. 获取Key 和Secret,只用在API设置中输入Name和选择一个Contact,就可以生成一对可用的Key和Secret,详细信息可参考:https://support.catchpoint.com/hc/en-us/articles/208029743

2.通过REST API 创建一个测试时不能指定Targeting and Scheduling 信息,如下图,所以创建一个可用的测试需要分成两步。首先创建一个测试,然后更新Targeting and Scheduling 信息。

3. 首先通过 curl https://io.catchpoint.com/ui/api/token --data 'grant_type=client_credentials&client_id=<key>&client_secret=<secret>' 获取token

4. 然后通过endpoint:POST https://io.catchpoint.com/ui/api/v1/tests/{id},创建一个测试,id=0 就代表是要新建一个测试。
Schema:
{"division_id": <division_id>, "status": {"id": 0, "name": "Active"}, "name": "Testing Create from API 2", "test_type": {"id": 0, "name": "Web"}, "schedule_section": {"inheritance_type": {"id": 0, "name": "Inherit"}}, "monitor": {"id": 18, "name": "Chrome"}, "test_url": "<url>", "start": "4/11/2021 5:59:00 PM", "http_method": {"id": 0, "name": "Get"}, "monitor_version": {"major_version_number": 75, "version_type": {"id": 1, "name": "Stable"}}, "change_date": "4/26/2021 2:52:10 PM", "insight_section": {"inheritance_type": {"id": 0, "name": "Inherit"}}, "advanced_settings": {"inheritance_type": {"id": 0, "name": "Inherit"}}, "request_section": {"inheritance_type": {"id": 0, "name": "Inherit"}}, "id": 0, "alert_section": {"inheritance_type": {"id": 0, "name": "Inherit"}}, "product_id": <product_id>,"parent_folder_id": <folder_id>}
5.这样在Response中就可以拿到新创建的测试的ID,拿到这个ID后就可以更改测试的Targeting and Scheduling 信息。
通过POST https://io.catchpoint.com/ui/api/v1/tests/<test_id>/scheduleSection
Schema:
{"inheritance_type":{"id":1,"name":"Override"},"network_type":{"id":0,"name":"Backbone"},"nodes":[{"id":879,"name":"Tokyo, JP - Softlayer","type":{"id":21,"name":"Node"}},{"id":1245,"name":"Tokyo, JP - Alicloud","type":{"id":21,"name":"Node"}}],"run_type":{"run_on":{"id":2,"name":"SelectedNodes"},"number_of_nodes":1},"frequency":{"id":8,"name":"2 Hours"},"node_distribution":{"id":1,"name":"Concurrent"}}
具体的node可以根据自己的需求修改,另外想要获取全部的node信息,可以使用 GET https://io.catchpoint.com/ui/api/v1/nodes 获取所用节点的信息。
两个都完成后就可以到Catchpoint UI去检查创建的测试是否成功,还有配置的信息是否完整。
参考信息: