Query Regarding Cloudflare Health Check API

I'm seeking assistance regarding the Cloudflare Health Check API. Specifically, I'm looking for a way to retrieve information on when the status of a health check last changed. Link to API Call: https://developers.cloudflare.com/api/operations/health-checks-list-health-checks Is there a timestamp provided in the response? I couldn't locate one. In the dashboard under Traffic --> Health Check Analytics, it's possible to filter timestamps for a health check through the Event Log. This is precisely the information I need, specifically the timestamp of the last "Health Status Change" event log. Does anyone know of a solution for this? It seems that through Analytics GraphQL, one could likely access this data. However, it would be preferable to achieve this without using GraphQL. Does anyone have an example of how to query the data from the API call "health-checks-list-health-checks" along with the Event Log for "Health Status Change" solely through GraphQL? Thank you in advance for any assistance or insights you can provide. Best regards, Stefan
Cloudflare API Documentation
Interact with Cloudflare's products and services via the Cloudflare API
1 Reply
Chaika
Chaika8mo ago
When it comes to analytics, the vast majority, and all of the new analytics, all live in GraphQL and are accessable through them. If you wanted to get the last healthChange for a specific check, you could filter by healthChanged and by datetime, and limit by 1, ex:
{
viewer {
zones(filter: {zoneTag: "de38bebf8e042f918f99305ef6082531"}) {
healthCheckEventsAdaptive(filter: { date_gt: "2024-03-27", healthChanged: 1, healthCheckName: "main_website"}, limit: 1, orderBy: [ datetime_DESC ]) {
healthCheckName
healthCheckId
healthStatus
failureReason
healthChanged
datetime
}
}
}
}
{
viewer {
zones(filter: {zoneTag: "de38bebf8e042f918f99305ef6082531"}) {
healthCheckEventsAdaptive(filter: { date_gt: "2024-03-27", healthChanged: 1, healthCheckName: "main_website"}, limit: 1, orderBy: [ datetime_DESC ]) {
healthCheckName
healthCheckId
healthStatus
failureReason
healthChanged
datetime
}
}
}
}
that would only give you the event if it happened within that date though to get more of a usable log with more then one health check, you could use the groups dataset variant and filter just by healthChanged:
{
viewer {
zones(filter: {zoneTag: "de38bebf8e042f918f99305ef6082531"}) {
healthCheckEventsAdaptiveGroups(filter: { date_gt: "2024-03-27", healthChanged: 1}, limit: 1000, orderBy: [ datetime_DESC ]) {
dimensions {
healthCheckId
healthStatus
datetime
failureReason
}
}
}
}
}
{
viewer {
zones(filter: {zoneTag: "de38bebf8e042f918f99305ef6082531"}) {
healthCheckEventsAdaptiveGroups(filter: { date_gt: "2024-03-27", healthChanged: 1}, limit: 1000, orderBy: [ datetime_DESC ]) {
dimensions {
healthCheckId
healthStatus
datetime
failureReason
}
}
}
}
}
you'd get output like this:
{
"dimensions": {
"datetime": "2024-03-30T22:45:39Z",
"failureReason": "noFailure",
"healthCheckId": "d782134f2a9fc7523fe50fc5b28e5779",
"healthStatus": "healthy"
}
},
{
"dimensions": {
"datetime": "2024-03-30T22:39:33Z",
"failureReason": "httpTimeout",
"healthCheckId": "d782134f2a9fc7523fe50fc5b28e5779",
"healthStatus": "unhealthy"
}
},
{
"dimensions": {
"datetime": "2024-03-30T21:15:01Z",
"failureReason": "noFailure",
"healthCheckId": "d782134f2a9fc7523fe50fc5b28e5779",
"healthStatus": "healthy"
}
},
{
"dimensions": {
"datetime": "2024-03-30T21:08:51Z",
"failureReason": "httpTimeout",
"healthCheckId": "d782134f2a9fc7523fe50fc5b28e5779",
"healthStatus": "unhealthy"
}
},
{
"dimensions": {
"datetime": "2024-03-30T22:45:39Z",
"failureReason": "noFailure",
"healthCheckId": "d782134f2a9fc7523fe50fc5b28e5779",
"healthStatus": "healthy"
}
},
{
"dimensions": {
"datetime": "2024-03-30T22:39:33Z",
"failureReason": "httpTimeout",
"healthCheckId": "d782134f2a9fc7523fe50fc5b28e5779",
"healthStatus": "unhealthy"
}
},
{
"dimensions": {
"datetime": "2024-03-30T21:15:01Z",
"failureReason": "noFailure",
"healthCheckId": "d782134f2a9fc7523fe50fc5b28e5779",
"healthStatus": "healthy"
}
},
{
"dimensions": {
"datetime": "2024-03-30T21:08:51Z",
"failureReason": "httpTimeout",
"healthCheckId": "d782134f2a9fc7523fe50fc5b28e5779",
"healthStatus": "unhealthy"
}
},
I would recommend getting a nice graphql client like graphiql https://github.com/skevy/graphiql-app, which has introspection/ability to look through schemas built in, look at Dev tools for the graphql requeste the dashboard is using, and play around with it a bit any sort of analytics the dashboard shows, you can get, and often with more precision/extra fields/etc, graphql is really powerful
Want results from more Discord servers?
Add your server