Skip to content

Commit 6dd6198

Browse files
Merge pull request #662 from Mahagon/master
feat(statuscake): add StatusCake Heartbeat monitor type support
2 parents 05109a2 + dde1401 commit 6dd6198

8 files changed

Lines changed: 542 additions & 13 deletions

File tree

‎api/v1alpha1/endpointmonitor_types.go‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ type UpdownConfig struct {
158158
}
159159

160160
// StatusCakeConfig defines the configuration for StatusCake Monitor Provider
161+
//
162+
// Heartbeat Validation
163+
// See https://developers.statuscake.com/api/#tag/heartbeat/operation/create-heartbeat-test
164+
// +kubebuilder:validation:XValidation:rule="self.testType != 'Heartbeat' || (self.checkRate >= 30 && self.checkRate <= 172800)",message="checkRate must be between 30 and 172800 seconds for Heartbeat monitors"
165+
//
166+
// Uptime Validation
167+
// See https://developers.statuscake.com/api/#tag/uptime/operation/create-uptime-test
168+
// +kubebuilder:validation:XValidation:rule="self.testType == 'Heartbeat' || self.checkRate in [0, 30, 60, 300, 900, 1800, 3600, 86400]",message="checkRate for uptime monitors must be one of: 0, 30, 60, 300, 900, 1800, 3600, 86400"
161169
type StatusCakeConfig struct {
162170
// Basic Auth User
163171
// +optional
@@ -167,11 +175,13 @@ type StatusCakeConfig struct {
167175
// +optional
168176
BasicAuthSecret string `json:"basicAuthSecret,omitempty"`
169177

170-
// Set Check Rate for the monitor
178+
// Set Check Rate for the monitor.
179+
// +kubebuilder:default=300
171180
// +optional
172181
CheckRate int `json:"checkRate,omitempty"`
173182

174-
// Set Test type - HTTP, TCP, PING
183+
// Set Test type - HTTP, TCP, PING, or Heartbeat
184+
// +kubebuilder:validation:Enum=HTTP;TCP;PING;Heartbeat
175185
// +optional
176186
TestType string `json:"testType,omitempty"`
177187

‎charts/ingressmonitorcontroller/crds/endpointmonitor.stakater.com_endpointmonitors.yaml‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ spec:
262262
description: Basic Auth User
263263
type: string
264264
checkRate:
265-
description: Set Check Rate for the monitor
265+
description: |-
266+
Set Check Rate for the monitor.
267+
For heartbeat monitors the valid range is 30–172800 seconds.
266268
type: integer
267269
confirmation:
268270
description: Confirmation value ranges from (0,10)
@@ -309,7 +311,12 @@ spec:
309311
description: Comma separated list of tags
310312
type: string
311313
testType:
312-
description: Set Test type - HTTP, TCP, PING
314+
description: Set Test type - HTTP, TCP, PING, or Heartbeat
315+
enum:
316+
- HTTP
317+
- TCP
318+
- PING
319+
- Heartbeat
313320
type: string
314321
timeout:
315322
description: Timeout is used to set a user agent string.

‎config/crd/bases/endpointmonitor.stakater.com_endpointmonitors.yaml‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ spec:
262262
description: Basic Auth User
263263
type: string
264264
checkRate:
265-
description: Set Check Rate for the monitor
265+
description: |-
266+
Set Check Rate for the monitor.
267+
For heartbeat monitors the valid range is 30–172800 seconds.
266268
type: integer
267269
confirmation:
268270
description: Confirmation value ranges from (0,10)
@@ -309,7 +311,12 @@ spec:
309311
description: Comma separated list of tags
310312
type: string
311313
testType:
312-
description: Set Test type - HTTP, TCP, PING
314+
description: Set Test type - HTTP, TCP, PING, or Heartbeat
315+
enum:
316+
- HTTP
317+
- TCP
318+
- PING
319+
- Heartbeat
313320
type: string
314321
timeout:
315322
description: Timeout is used to set a user agent string.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: endpointmonitor.stakater.com/v1alpha1
2+
kind: EndpointMonitor
3+
metadata:
4+
name: my-service-heartbeat
5+
spec:
6+
providers: StatusCake
7+
statusCakeConfig:
8+
testType: Heartbeat
9+
checkRate: 300
10+
testTags: "abc,def"
11+
contactGroup: "123456,654321"

‎pkg/monitors/statuscake/statuscake-mappers.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,30 @@ func StatusCakeMonitorMonitorsToBaseMonitorsMapper(statuscakeData []StatusCakeMo
4242
}
4343
return monitors
4444
}
45+
46+
// StatusCakeHeartbeatToBaseMonitorMapper maps a StatusCake HeartbeatTestOverview to a Monitor.
47+
// m.URL is the StatusCake-generated push endpoint that clients ping to register a heartbeat.
48+
func StatusCakeHeartbeatToBaseMonitorMapper(hb statuscake.HeartbeatTestOverview) *models.Monitor {
49+
var m models.Monitor
50+
m.Name = hb.Name
51+
m.URL = hb.WebsiteURL
52+
m.ID = hb.ID
53+
54+
var providerConfig endpointmonitorv1alpha1.StatusCakeConfig
55+
providerConfig.TestType = "Heartbeat"
56+
providerConfig.TestTags = strings.Join(hb.Tags, ",")
57+
providerConfig.CheckRate = int(hb.Period)
58+
providerConfig.Paused = hb.Paused
59+
providerConfig.ContactGroup = strings.Join(hb.ContactGroups, ",")
60+
m.Config = &providerConfig
61+
return &m
62+
}
63+
64+
// StatusCakeHeartbeatsToBaseMonitorsMapper maps a slice of HeartbeatTestOverview to Monitors
65+
func StatusCakeHeartbeatsToBaseMonitorsMapper(hbs []statuscake.HeartbeatTestOverview) []models.Monitor {
66+
var monitors []models.Monitor
67+
for _, hb := range hbs {
68+
monitors = append(monitors, *StatusCakeHeartbeatToBaseMonitorMapper(hb))
69+
}
70+
return monitors
71+
}

0 commit comments

Comments
 (0)