Links
import requests
#https://docs.datadoghq.com/ja/api/latest/synthetics/?code-lang=curl
public_id = ""
endpoint = "https://ap1.datadoghq.com/api/v1/synthetics/tests/api/"
# endpoint = f"https://ap1.datadoghq.com/api/v1/synthetics/tests/api/{public_id}"
site_domain = "toge510.com"
api_key = ""
app_key = ""
notification_channel = "@webhook- @slack-"
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'DD-API-KEY': api_key,
'DD-APPLICATION-KEY': app_key,
}
json_data = {
'tags': [
f'env:{site_domain}',
],
'locations': [
'aws:ap-northeast-1',
],
'message': f'{notification_channel}{{#is_alert}}The SSL certification will expire in 10 days.{{/is_alert}}',
'name': f'SSL test on {site_domain}',
'type': 'api',
'subtype': 'ssl',
'config': {
'request': {
'host': site_domain,
'port': 443,
},
'assertions': [
{
'operator': 'isInMoreThan',
'type': 'certificate',
'target': 10,
},
{
'operator': 'moreThanOrEqual',
'type': 'tlsVersion',
'target': '1.3',
},
{
'operator': 'lessThan',
'type': 'responseTime',
'target': 1000,
},
],
},
'options': {
'monitor_name': f'[SSL TEST] https://{site_domain}',
'monitor_priority': 2,
'monitor_options': {
'notify_audit': False,
'locked': False,
'include_tags': True,
'new_host_delay': 300,
'notify_no_data': False,
'renotify_interval': 1440,
},
'tick_every': 86400,
'min_failure_duration': 0,
'min_location_failed': 1,
'scheduling': {
'timeframes': [
{
'day': 1,
'from': '10:00',
'to': '10:10',
},
{
'day': 2,
'from': '10:00',
'to': '10:10',
},
{
'day': 3,
'from': '10:00',
'to': '10:10',
},
{
'day': 4,
'from': '10:00',
'to': '10:10',
},
{
'day': 5,
'from': '10:00',
'to': '10:10',
},
{
'day': 6,
'from': '10:00',
'to': '10:10',
},
{
'day': 7,
'from': '10:00',
'to': '10:10',
},
],
'timezone': 'Asia/Tokyo',
},
'restricted_roles': [
'f4a032ce-a4c0-11ee-b23f-da7ad0900009',
'f4d2876a-a4c0-11ee-b23f-da7ad0900009',
],
}
}
try:
response = requests.post(endpoint, headers=headers, json=json_data)
# response = requests.put(endpoint, headers=headers, json=json_data)
print(response)
print(response.text)
except Exception as e:
print(e)
curl -X GET "https://api.ap1.datadoghq.com/api/v2/roles" -H "Accept: application/json" -H "DD-API-KEY: f895ce" -H "DD-APPLICATION-KEY: 01ab199" | jq
# curl -X GET "https://api.ap1.datadoghq.com/api/v1/synthetics/tests" \
# -H "Accept: application/json" \
# -H "DD-API-KEY: f895ce6ead92e446ac33dd57ed330c5d" \
# -H "DD-APPLICATION-KEY: 01ab199788d3c2d7ce171088c332cb7daad68480"
curl -X POST "https://ap1.datadoghq.com/api/v1/synthetics/tests/api" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: f89" \
-H "DD-APPLICATION-KEY: 01ab199" \
-d @- << EOF
{
"tags": [
"env:toge510.com"
],
"locations": [
"aws:ap-northeast-1"
],
"message": "@webhook-test @slack-test{{#is_alert}}The SSL certification will expire in 10 days.{{/is_alert}}",
"name": "test toge510.com",
"type": "api",
"subtype": "ssl",
"config": {
"request": {
"host": "toge510.com",
"port": 443
},
"assertions": [
{
"operator": "isInMoreThan",
"type": "certificate",
"target": 10
},
{
"operator": "moreThanOrEqual",
"type": "tlsVersion",
"target": "1.3"
},
{
"operator": "lessThan",
"type": "responseTime",
"target": 1000
}
]
},
"options": {
"monitor_name": "[SSL TEST] https://toge510.com",
"monitor_priority": 2,
"monitor_options": {
"notify_audit": false,
"locked": false,
"include_tags": true,
"new_host_delay": 300,
"notify_no_data": false,
"renotify_interval": 1440
},
"tick_every": 86400,
"min_failure_duration": 0,
"min_location_failed": 1,
"scheduling": {
"timeframes": [
{
"day": 1,
"from": "10:00",
"to": "10:10"
},
{
"day": 2,
"from": "10:00",
"to": "10:10"
},
{
"day": 3,
"from": "10:00",
"to": "10:10"
},
{
"day": 4,
"from": "10:00",
"to": "10:10"
},
{
"day": 5,
"from": "10:00",
"to": "10:10"
},
{
"day": 6,
"from": "10:00",
"to": "10:10"
},
{
"day": 7,
"from": "10:00",
"to": "10:10"
}
],
"timezone": "Asia/Tokyo"
},
"restricted_roles": [
"f4a032c",
"f4d2876"
]
}
}
EOF