-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.go
1010 lines (883 loc) · 34.9 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package checkly
import (
"context"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/netip"
"time"
)
// Client is an interface that implements Checkly's API
type Client interface {
// Create creates a new check with the specified details.
// It returns the newly-created check, or an error.
//
// Deprecated: method type would be removed in future versions,
// use CreateCheck instead.
Create(
ctx context.Context,
check Check,
) (*Check, error)
// Update updates an existing check with the specified details.
// It returns the updated check, or an error.
//
// Deprecated: this method would be removed in future versions,
// use UpdateCheck instead.
Update(
ctx context.Context,
ID string,
check Check,
) (*Check, error)
// Delete deletes the check with the specified ID.
//
// Deprecated: this method would be removed in future versions,
// use DeleteCheck instead.
Delete(
ctx context.Context,
ID string,
) error
// Get takes the ID of an existing check, and returns the check parameters,
// or an error.
//
// Deprecated: this method would be removed in future versions,
// use GetCheck instead.
Get(
ctx context.Context,
ID string,
) (*Check, error)
GetHeartbeatCheck(
ctx context.Context,
ID string,
) (*HeartbeatCheck, error)
// Create creates a new check with the specified details.
// It returns the newly-created check, or an error.
CreateCheck(
ctx context.Context,
check Check,
) (*Check, error)
// CreateHeartbeat creates a new heartbeat check with the specified details.
// It returns the newly-created check, or an error.
CreateHeartbeat(
ctx context.Context,
check HeartbeatCheck,
) (*HeartbeatCheck, error)
// Update updates an existing check with the specified details.
// It returns the updated check, or an error.
UpdateCheck(
ctx context.Context,
ID string,
check Check,
) (*Check, error)
// UpdateHeartbeat updates an existing heartbeat check with the specified details.
// It returns the updated check, or an error.
UpdateHeartbeat(
ctx context.Context,
ID string,
check HeartbeatCheck,
) (*HeartbeatCheck, error)
// Delete deletes the check with the specified ID.
DeleteCheck(
ctx context.Context,
ID string,
) error
// Get takes the ID of an existing check, and returns the check parameters,
// or an error.
GetCheck(
ctx context.Context,
ID string,
) (*Check, error)
// CreateGroup creates a new check group with the specified details.
// It returns the newly-created group, or an error.
CreateGroup(
ctx context.Context,
group Group,
) (*Group, error)
// GetGroup takes the ID of an existing check group, and returns the
// corresponding group, or an error.
GetGroup(
ctx context.Context,
ID int64,
) (*Group, error)
// UpdateGroup takes the ID of an existing check group, and updates the
// corresponding check group to match the supplied group. It returns the updated
// group, or an error.
UpdateGroup(
ctx context.Context,
ID int64,
group Group,
) (*Group, error)
// DeleteGroup deletes the check group with the specified ID. It returns a
DeleteGroup(
ctx context.Context,
ID int64,
) error
// GetCheckResult gets a specific Check result, or it returns an error.
GetCheckResult(
ctx context.Context,
checkID,
checkResultID string,
) (*CheckResult, error)
// GetCheckResults gets the results of the given Check
GetCheckResults(
ctx context.Context,
checkID string,
filters *CheckResultsFilter,
) ([]CheckResult, error)
// CreateSnippet creates a new snippet with the specified details. It returns
// the newly-created snippet, or an error.
CreateSnippet(
ctx context.Context,
snippet Snippet,
) (*Snippet, error)
// GetSnippet takes the ID of an existing snippet, and returns the
// corresponding snippet, or an error.
GetSnippet(
ctx context.Context,
ID int64,
) (*Snippet, error)
// UpdateSnippet takes the ID of an existing snippet, and updates the
// corresponding snippet to match the supplied snippet. It returns the updated
// snippet, or an error.
UpdateSnippet(
ctx context.Context,
ID int64,
snippet Snippet,
) (*Snippet, error)
// DeleteSnippet deletes the snippet with the specified ID. It returns a
DeleteSnippet(
ctx context.Context,
ID int64,
) error
// CreateEnvironmentVariable creates a new environment variable with the
// specified details. It returns the newly-created environment variable,
// or an error.
CreateEnvironmentVariable(
ctx context.Context,
envVar EnvironmentVariable,
) (*EnvironmentVariable, error)
// GetEnvironmentVariable takes the ID of an existing environment variable, and returns the
// corresponding environment variable, or an error.
GetEnvironmentVariable(
ctx context.Context,
key string,
) (*EnvironmentVariable, error)
// UpdateEnvironmentVariable takes the ID of an existing environment variable, and updates the
// corresponding environment variable to match the supplied environment variable. It returns the updated
// environment variable, or an error.
UpdateEnvironmentVariable(
ctx context.Context,
key string,
envVar EnvironmentVariable,
) (*EnvironmentVariable, error)
// DeleteEnvironmentVariable deletes the environment variable with the specified ID. It returns a
DeleteEnvironmentVariable(
ctx context.Context,
key string,
) error
// CreateAlertChannel creates a new alert channel with the specified details. It returns
// the newly-created alert channel, or an error.
CreateAlertChannel(
ctx context.Context,
ac AlertChannel,
) (*AlertChannel, error)
// GetAlertChannel takes the ID of an existing alert channel, and returns the
// corresponding alert channel, or an error.
GetAlertChannel(
ctx context.Context,
ID int64,
) (*AlertChannel, error)
// UpdateAlertChannel takes the ID of an existing alert channel, and updates the
// corresponding alert channel to match the supplied alert channel. It returns the updated
// alert channel, or an error.
UpdateAlertChannel(
ctx context.Context,
ID int64,
ac AlertChannel,
) (*AlertChannel, error)
// DeleteAlertChannel deletes the alert channel with the specified ID.
DeleteAlertChannel(
ctx context.Context,
ID int64,
) error
// CreateDashboard creates a new dashboard with the specified details.
CreateDashboard(
ctx context.Context,
dashboard Dashboard,
) (*Dashboard, error)
// GetDashboard takes the ID of an existing dashboard and returns it
GetDashboard(
ctx context.Context,
ID string,
) (*Dashboard, error)
// UpdateDashboard takes the ID of an existing dashboard, and updates the
// corresponding dashboard to match the supplied dashboard.
UpdateDashboard(
ctx context.Context,
ID string,
dashboard Dashboard,
) (*Dashboard, error)
// DeleteDashboard deletes the dashboard with the specified ID.
DeleteDashboard(
ctx context.Context,
ID string,
) error
// CreateMaintenanceWindow creates a new maintenance window with the specified details.
CreateMaintenanceWindow(
ctx context.Context,
mw MaintenanceWindow,
) (*MaintenanceWindow, error)
// GetMaintenanceWindow takes the ID of an existing maintenance window and returns it
GetMaintenanceWindow(
ctx context.Context,
ID int64,
) (*MaintenanceWindow, error)
// UpdateMaintenanceWindow takes the ID of an existing maintenance window, and updates the
// corresponding maintenance window to match the supplied maintenance window.
UpdateMaintenanceWindow(
ctx context.Context,
ID int64,
mw MaintenanceWindow,
) (*MaintenanceWindow, error)
// DeleteMaintenanceWindow deletes the maintenance window with the specified ID.
DeleteMaintenanceWindow(
ctx context.Context,
ID int64,
) error
// CreatePrivateLocation creates a new private location with the specified details.
CreatePrivateLocation(
ctx context.Context,
pl PrivateLocation,
) (*PrivateLocation, error)
// GetPrivateLocation takes the ID of an existing private location and returns it
GetPrivateLocation(
ctx context.Context,
ID string,
) (*PrivateLocation, error)
// UpdatePrivateLocation takes the ID of an existing private location and updates it
// to match the new one.
UpdatePrivateLocation(
ctx context.Context,
ID string,
pl PrivateLocation,
) (*PrivateLocation, error)
// DeletePrivateLocation deletes the private location with the specified ID.
DeletePrivateLocation(
ctx context.Context,
ID string,
) error
// CreateTriggerCheck creates a new trigger with the specified details.
CreateTriggerCheck(
ctx context.Context,
checkID string,
) (*TriggerCheck, error)
// GetTriggerCheck takes the ID of an existing trigger and returns it
GetTriggerCheck(
ctx context.Context,
checkID string,
) (*TriggerCheck, error)
// DeleteTriggerCheck deletes the trigger with the specified ID.
DeleteTriggerCheck(
ctx context.Context,
checkID string,
) error
// CreateTriggerGroup creates a new trigger with the specified details.
CreateTriggerGroup(
ctx context.Context,
groupID int64,
) (*TriggerGroup, error)
// GetTriggerGroup takes the ID of an existing trigger and returns it
GetTriggerGroup(
ctx context.Context,
groupID int64,
) (*TriggerGroup, error)
// DeleteTriggerGroup deletes the trigger with the specified ID.
DeleteTriggerGroup(
ctx context.Context,
groupID int64,
) error
// SetAccountId sets ID on a client which is required when using User API keys.
SetAccountId(ID string)
// SetChecklySource sets the source of the check for analytics purposes.
SetChecklySource(source string)
// Get a specific runtime specs.
GetRuntime(
ctx context.Context,
ID string,
) (*Runtime, error)
GetStaticIPs(ctx context.Context) ([]StaticIP, error)
}
// client represents a Checkly client. If the Debug field is set to an io.Writer
// (for example os.Stdout), then the client will dump API requests and responses
// to it. To use a non-default HTTP client (for example, for testing, or to set
// a timeout), assign to the HTTPClient field. To set a non-default URL (for
// example, for testing), assign to the URL field.
type client struct {
apiKey string
url string
accountId string
source string
httpClient *http.Client
debug io.Writer
}
// Check type constants
type CheckType string
// TypeBrowser is used to identify a browser check.
const TypeBrowser = "BROWSER"
// TypeAPI is used to identify an API check.
const TypeAPI = "API"
// TypeHeartbeat is used to identify a browser check.
const TypeHeartbeat = "HEARTBEAT"
// Escalation type constants
// RunBased identifies a run-based escalation type, for use with an AlertSettings.
const RunBased = "RUN_BASED"
// TimeBased identifies a time-based escalation type, for use with an AlertSettings.
const TimeBased = "TIME_BASED"
// Assertion source constants
// StatusCode identifies the HTTP status code as an assertion source.
const StatusCode = "STATUS_CODE"
// JSONBody identifies the JSON body data as an assertion source.
const JSONBody = "JSON_BODY"
// TextBody identifies the response body text as an assertion source.
const TextBody = "TEXT_BODY"
// Headers identifies the HTTP headers as an assertion source.
const Headers = "HEADERS"
// ResponseTime identifies the response time as an assertion source.
const ResponseTime = "RESPONSE_TIME"
// Assertion comparison constants
// Equals asserts that the source and target are equal.
const Equals = "EQUALS"
// NotEquals asserts that the source and target are not equal.
const NotEquals = "NOT_EQUALS"
// IsEmpty asserts that the source is empty.
const IsEmpty = "IS_EMPTY"
// NotEmpty asserts that the source is not empty.
const NotEmpty = "NOT_EMPTY"
// GreaterThan asserts that the source is greater than the target.
const GreaterThan = "GREATER_THAN"
// LessThan asserts that the source is less than the target.
const LessThan = "LESS_THAN"
// Contains asserts that the source contains a specified value.
const Contains = "CONTAINS"
// NotContains asserts that the source does not contain a specified value.
const NotContains = "NOT_CONTAINS"
// Check represents the parameters for an existing check.
type Check struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"checkType"`
Frequency int `json:"frequency"`
FrequencyOffset int `json:"frequencyOffset,omitempty"`
Activated bool `json:"activated"`
Muted bool `json:"muted"`
ShouldFail bool `json:"shouldFail"`
RunParallel bool `json:"runParallel"`
Locations []string `json:"locations,omitempty"`
DegradedResponseTime int `json:"degradedResponseTime"`
MaxResponseTime int `json:"maxResponseTime"`
Script string `json:"script,omitempty"`
EnvironmentVariables []EnvironmentVariable `json:"environmentVariables"`
Tags []string `json:"tags,omitempty"`
SSLCheckDomain string `json:"sslCheckDomain"`
SetupSnippetID int64 `json:"setupSnippetId,omitempty"`
TearDownSnippetID int64 `json:"tearDownSnippetId,omitempty"`
LocalSetupScript string `json:"localSetupScript,omitempty"`
LocalTearDownScript string `json:"localTearDownScript,omitempty"`
AlertSettings AlertSettings `json:"alertSettings,omitempty"`
UseGlobalAlertSettings bool `json:"useGlobalAlertSettings"`
Request Request `json:"request"`
Heartbeat Heartbeat `json:"heartbeat"`
GroupID int64 `json:"groupId,omitempty"`
GroupOrder int `json:"groupOrder,omitempty"`
AlertChannelSubscriptions []AlertChannelSubscription `json:"alertChannelSubscriptions,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
// Pointers
PrivateLocations *[]string `json:"privateLocations"`
RuntimeID *string `json:"runtimeId"`
RetryStrategy *RetryStrategy `json:"retryStrategy,omitempty"`
// Deprecated: this property will be removed in future versions.
SSLCheck bool `json:"sslCheck"`
// Deprecated: this property will be removed in future versions. Please use RetryStrategy instead.
DoubleCheck bool `json:"doubleCheck"`
}
// Check represents the parameters for an existing check.
type MultiStepCheck struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"checkType"`
Frequency int `json:"frequency"`
FrequencyOffset int `json:"frequencyOffset,omitempty"`
Activated bool `json:"activated"`
Muted bool `json:"muted"`
ShouldFail bool `json:"shouldFail"`
RunParallel bool `json:"runParallel"`
Locations []string `json:"locations,omitempty"`
Script string `json:"script,omitempty"`
EnvironmentVariables []EnvironmentVariable `json:"environmentVariables"`
Tags []string `json:"tags,omitempty"`
AlertSettings AlertSettings `json:"alertSettings,omitempty"`
UseGlobalAlertSettings bool `json:"useGlobalAlertSettings"`
GroupID int64 `json:"groupId,omitempty"`
GroupOrder int `json:"groupOrder,omitempty"`
AlertChannelSubscriptions []AlertChannelSubscription `json:"alertChannelSubscriptions,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
// Pointers
PrivateLocations *[]string `json:"privateLocations"`
RuntimeID *string `json:"runtimeId"`
RetryStrategy *RetryStrategy `json:"retryStrategy,omitempty"`
}
type HeartbeatCheck struct {
ID string `json:"id"`
Name string `json:"name"`
Activated bool `json:"activated"`
Muted bool `json:"muted"`
Tags []string `json:"tags,omitempty"`
AlertSettings AlertSettings `json:"alertSettings,omitempty"`
UseGlobalAlertSettings bool `json:"useGlobalAlertSettings"`
AlertChannelSubscriptions []AlertChannelSubscription `json:"alertChannelSubscriptions,omitempty"`
Heartbeat Heartbeat `json:"heartbeat"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// Heartbeat represents the parameter for the heartbeat check.
type Heartbeat struct {
Period int `json:"period"`
PeriodUnit string `json:"periodUnit"`
Grace int `json:"grace"`
GraceUnit string `json:"graceUnit"`
PingToken string `json:"pingToken"`
}
// Request represents the parameters for the request made by the check.
type Request struct {
Method string `json:"method"`
URL string `json:"url"`
FollowRedirects bool `json:"followRedirects"`
SkipSSL bool `json:"skipSSL"`
Body string `json:"body"`
BodyType string `json:"bodyType,omitempty"`
Headers []KeyValue `json:"headers"`
QueryParameters []KeyValue `json:"queryParameters"`
Assertions []Assertion `json:"assertions"`
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
IPFamily string `json:"ipFamily,omitempty"`
}
// Assertion represents an assertion about an API response, which will be
// verified as part of the check.
type Assertion struct {
Edit bool `json:"edit"`
Order int `json:"order"`
ArrayIndex int `json:"arrayIndex"`
ArraySelector int `json:"arraySelector"`
Source string `json:"source"`
Property string `json:"property"`
Comparison string `json:"comparison"`
Target string `json:"target"`
}
// BasicAuth represents the HTTP basic authentication credentials for a request.
type BasicAuth struct {
Username string `json:"username"`
Password string `json:"password"`
}
// KeyValue represents a key-value pair, for example a request header setting,
// or a query parameter.
type KeyValue struct {
Key string `json:"key"`
Value string `json:"value"`
Locked bool `json:"locked"`
}
// EnvironmentVariable represents a key-value pair for setting environment
// values during check execution.
type EnvironmentVariable struct {
Key string `json:"key,omitempty"`
Value string `json:"value"`
Locked bool `json:"locked"`
Secret bool `json:"secret"`
}
// PrivateLocationKey represents the keys that the private location has.
type PrivateLocationKey struct {
Id string `json:"id"`
MaskedKey string `json:"maskedKey"`
RawKey string `json:"rawKey"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// DashboardKey represents the keys that the dashboard has.
type DashboardKey struct {
Id string `json:"id"`
MaskedKey string `json:"maskedKey"`
RawKey string `json:"rawKey"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// AlertSettings represents an alert configuration.
type AlertSettings struct {
EscalationType string `json:"escalationType,omitempty"`
RunBasedEscalation RunBasedEscalation `json:"runBasedEscalation,omitempty"`
TimeBasedEscalation TimeBasedEscalation `json:"timeBasedEscalation,omitempty"`
Reminders Reminders `json:"reminders,omitempty"`
ParallelRunFailureThreshold ParallelRunFailureThreshold `json:"parallelRunFailureThreshold,omitempty"`
// Deprecated: this property will be removed in future versions.
SSLCertificates SSLCertificates `json:"sslCertificates,omitempty"`
}
// ParallelRunFailureThreshold represent an alert escalation based on the number
// of failing regions, only applicable for parallel checks
type ParallelRunFailureThreshold struct {
Enabled bool `json:"enabled,omitempty"`
Percentage int `json:"percentage,omitempty"`
}
// RunBasedEscalation represents an alert escalation based on a number of failed
// check runs.
type RunBasedEscalation struct {
FailedRunThreshold int `json:"failedRunThreshold,omitempty"`
}
// TimeBasedEscalation represents an alert escalation based on the number of
// minutes after a check first starts failing.
type TimeBasedEscalation struct {
MinutesFailingThreshold int `json:"minutesFailingThreshold,omitempty"`
}
// Reminders represents the number of reminders to send after an alert
// notification, and the time interval between them.
type Reminders struct {
Amount int `json:"amount,omitempty"`
Interval int `json:"interval,omitempty"`
}
// Deprecated: this type will be removed in future versions.
// SSLCertificates represents alert settings for expiring SSL certificates.
type SSLCertificates struct {
Enabled bool `json:"enabled,omitempty"`
AlertThreshold int `json:"alertThreshold,omitempty"`
}
type RetryStrategy struct {
Type string `json:"type"`
BaseBackoffSeconds int `json:"baseBackoffSeconds"`
MaxRetries int `json:"maxRetries"`
MaxDurationSeconds int `json:"maxDurationSeconds"`
SameRegion bool `json:"sameRegion"`
}
// Group represents a check group.
type Group struct {
ID int64 `json:"id,omitempty"`
Name string `json:"name"`
Activated bool `json:"activated"`
Muted bool `json:"muted"`
RunParallel bool `json:"runParallel"`
Tags []string `json:"tags"`
Locations []string `json:"locations"`
Concurrency int `json:"concurrency"`
APICheckDefaults APICheckDefaults `json:"apiCheckDefaults"`
EnvironmentVariables []EnvironmentVariable `json:"environmentVariables"`
UseGlobalAlertSettings bool `json:"useGlobalAlertSettings"`
AlertSettings AlertSettings `json:"alertSettings,omitempty"`
SetupSnippetID int64 `json:"setupSnippetId,omitempty"`
TearDownSnippetID int64 `json:"tearDownSnippetId,omitempty"`
LocalSetupScript string `json:"localSetupScript,omitempty"`
LocalTearDownScript string `json:"localTearDownScript,omitempty"`
AlertChannelSubscriptions []AlertChannelSubscription `json:"alertChannelSubscriptions,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
// Pointers
RuntimeID *string `json:"runtimeId"`
PrivateLocations *[]string `json:"privateLocations"`
RetryStrategy *RetryStrategy `json:"retryStrategy,omitempty"`
// Deprecated: this property will be removed in future versions. Please use RetryStrategy instead.
DoubleCheck bool `json:"doubleCheck"`
}
// APICheckDefaults represents the default settings for API checks within a
// given group.
type APICheckDefaults struct {
BaseURL string `json:"url"`
Headers []KeyValue `json:"headers,omitempty"`
QueryParameters []KeyValue `json:"queryParameters,omitempty"`
Assertions []Assertion `json:"assertions,omitempty"`
BasicAuth BasicAuth `json:"basicAuth,omitempty"`
}
// CheckResult represents a Check result
type CheckResult struct {
ID string `json:"id"`
Name string `json:"name"`
CheckID string `json:"checkId"`
HasFailures bool `json:"hasFailures"`
HasErrors bool `json:"hasErrors"`
IsDegraded bool `json:"isDegraded"`
OverMaxResponseTime bool `json:"overMaxResponseTime"`
RunLocation string `json:"runLocation"`
ResponseTime int64 `json:"responseTime"`
ApiCheckResult *ApiCheckResult `json:"apiCheckResult"`
BrowserCheckResult *BrowserCheckResult `json:"browserCheckResult"`
CheckRunID int64 `json:"checkRunId"`
Attempts int64 `json:"attempts"`
StartedAt time.Time `json:"startedAt"`
StoppedAt time.Time `json:"stoppedAt"`
CreatedAt time.Time `json:"created_at"`
}
// ApiCheckResult represents an API Check result
type ApiCheckResult map[string]interface{}
// BrowserCheckResult represents a Browser Check result
type BrowserCheckResult map[string]interface{}
// CheckResultsFilter represents the parameters that can be passed while
// getting Check Results
type CheckResultsFilter struct {
Limit int64
Page int64
Location string
To int64
From int64
CheckType CheckType
HasFailures bool
}
// Snippet defines Snippet type
type Snippet struct {
ID int64 `json:"id"`
Name string `json:"name"`
Script string `json:"script"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
const (
AlertTypeEmail = "EMAIL"
AlertTypeSlack = "SLACK"
AlertTypeWebhook = "WEBHOOK"
AlertTypeSMS = "SMS"
AlertTypePagerduty = "PAGERDUTY"
AlertTypeOpsgenie = "OPSGENIE"
AlertTypeCall = "CALL"
)
// AlertChannelSubscription represents a subscription to an alert channel.
type AlertChannelSubscription struct {
ChannelID int64 `json:"alertChannelId"`
Activated bool `json:"activated"`
}
// AlertChannelEmail defines a type for an email alert channel
type AlertChannelEmail struct {
Address string `json:"address"`
}
// AlertChannelSlack defines a type for a slack alert channel
type AlertChannelSlack struct {
WebhookURL string `json:"url"`
Channel string `json:"channel"`
}
// AlertChannelSMS defines a type for a sms alert channel
type AlertChannelSMS struct {
Name string `json:"name"`
Number string `json:"number"`
}
// AlertChannelCALL defines a type for a phone call alert channel
type AlertChannelCall struct {
Name string `json:"name"`
Number string `json:"number"`
}
// AlertChannelOpsgenie defines a type for an opsgenie alert channel
type AlertChannelOpsgenie struct {
Name string `json:"name"`
APIKey string `json:"apiKey"`
Region string `json:"region"`
Priority string `json:"priority"`
}
// AlertChannelPagerduty defines a type for an pager duty alert channel
type AlertChannelPagerduty struct {
Account string `json:"account,omitempty"`
ServiceKey string `json:"serviceKey"`
ServiceName string `json:"serviceName,omitempty"`
}
// AlertChannelWebhook defines a type for a webhook alert channel
type AlertChannelWebhook struct {
Name string `json:"name"`
URL string `json:"url"`
WebhookType string `json:"webhookType,omitempty"`
Method string `json:"method,omitempty"`
Template string `json:"template,omitempty"`
WebhookSecret string `json:"webhookSecret,omitempty"`
Headers []KeyValue `json:"headers,omitempty"`
QueryParameters []KeyValue `json:"queryParameters,omitempty"`
}
// AlertChannel represents an alert channel and its subscribed checks. The API
// defines this data as read-only.
type AlertChannel struct {
ID int64 `json:"id,omitempty"`
Type string `json:"type"`
Email *AlertChannelEmail `json:"-"`
Slack *AlertChannelSlack `json:"-"`
SMS *AlertChannelSMS `json:"-"`
CALL *AlertChannelCall `json:"-"`
Opsgenie *AlertChannelOpsgenie `json:"-"`
Webhook *AlertChannelWebhook `json:"-"`
Pagerduty *AlertChannelPagerduty `json:"-"`
SendRecovery *bool `json:"sendRecovery"`
SendFailure *bool `json:"sendFailure"`
SendDegraded *bool `json:"sendDegraded"`
SSLExpiry *bool `json:"sslExpiry"`
SSLExpiryThreshold *int `json:"sslExpiryThreshold"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// Dashboard defines a type for a dashboard.
type Dashboard struct {
ID int64 `json:"id,omitempty"`
DashboardID string `json:"dashboardId,omitempty"`
CustomUrl string `json:"customUrl"`
CustomDomain string `json:"customDomain,omitempty"`
IsPrivate bool `json:"isPrivate,omitempty"`
Logo string `json:"logo,omitempty"`
Link string `json:"link,omitempty"`
Description string `json:"description,omitempty"`
Favicon string `json:"favicon,omitempty"`
Header string `json:"header,omitempty"`
Width string `json:"width,omitempty"`
RefreshRate int `json:"refreshRate"`
ChecksPerPage int `json:"checksPerPage,omitempty"`
PaginationRate int `json:"paginationRate"`
Paginate bool `json:"paginate"`
Tags []string `json:"tags,omitempty"`
HideTags bool `json:"hideTags,omitempty"`
UseTagsAndOperator bool `json:"useTagsAndOperator,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Keys []DashboardKey `json:"keys,omitempty"`
}
// MaintenanceWindow defines a type for a maintenance window.
type MaintenanceWindow struct {
ID int64 `json:"id"`
Name string `json:"name"`
StartsAt string `json:"startsAt"`
EndsAt string `json:"endsAt"`
RepeatInterval int `json:"repeatInterval,omitempty"`
RepeatUnit string `json:"repeatUnit,omitempty"`
RepeatEndsAt string `json:"repeatEndsAt,omitempty"`
Tags []string `json:"tags,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// PrivateLocation defines a type for a private location.
type PrivateLocation struct {
ID string `json:"id"`
Name string `json:"name"`
SlugName string `json:"slugName"`
Icon string `json:"icon,omitempty"`
Keys []PrivateLocationKey `json:"keys,omitempty"`
LastSeen string `json:"lastSeen,omitempty"`
AgentCount int `json:"agentCount,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// Trigger defines a type for a check trigger.
type TriggerCheck struct {
ID int64 `json:"id,omitempty"`
CheckId string `json:"checkId,omitempty"`
Token string `json:"token"`
URL string `json:"url"`
CalledAt string `json:"called_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// Trigger defines a type for a group trigger.
type TriggerGroup struct {
ID int64 `json:"id,omitempty"`
GroupId int64 `json:"groupId,omitempty"`
Token string `json:"token"`
URL string `json:"url"`
CalledAt string `json:"called_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
type Location struct {
Name string `json:"name"`
Region string `json:"region"`
}
type Runtime struct {
Name string `json:"name"`
MultiStepSupport bool `json:"multiStepSupport"`
Stage string `json:"stage"`
RuntimeEndOfLife string `json:"runtimeEndOfLife"`
Description string `json:"description"`
}
// This type is used to describe Checkly's official
// public range of IP addresses checks are executed from
// see https://www.checklyhq.com/docs/monitoring/allowlisting/#ip-range-allowlisting
type StaticIP struct {
Region string
Address netip.Prefix
}
// SetConfig sets config of alert channel based on it's type
func (a *AlertChannel) SetConfig(cfg interface{}) {
switch v := cfg.(type) {
case *AlertChannelEmail:
a.Email = cfg.(*AlertChannelEmail)
case *AlertChannelSMS:
a.SMS = cfg.(*AlertChannelSMS)
case *AlertChannelCall:
a.CALL = cfg.(*AlertChannelCall)
case *AlertChannelSlack:
a.Slack = cfg.(*AlertChannelSlack)
case *AlertChannelWebhook:
a.Webhook = cfg.(*AlertChannelWebhook)
case *AlertChannelOpsgenie:
a.Opsgenie = cfg.(*AlertChannelOpsgenie)
case *AlertChannelPagerduty:
a.Pagerduty = cfg.(*AlertChannelPagerduty)
default:
log.Printf("Unknown config type %v", v)
}
}
// GetConfig gets the config of the alert channel based on it's type
func (a *AlertChannel) GetConfig() (cfg map[string]interface{}) {
byts := []byte{}
var err error
switch a.Type {
case AlertTypeEmail:
byts, err = json.Marshal(a.Email)
case AlertTypeSMS:
byts, err = json.Marshal(a.SMS)
case AlertTypeCall:
byts, err = json.Marshal(a.CALL)
case AlertTypeSlack:
byts, err = json.Marshal(a.Slack)
case AlertTypeOpsgenie:
byts, err = json.Marshal(a.Opsgenie)
case AlertTypePagerduty:
byts, err = json.Marshal(a.Pagerduty)
case AlertTypeWebhook:
byts, err = json.Marshal(a.Webhook)
}
if err != nil {
panic(err)
}
err = json.Unmarshal(byts, &cfg)
return cfg
}
// AlertChannelConfigFromJSON gets AlertChannel.config from JSON
func AlertChannelConfigFromJSON(channelType string, cfgJSON []byte) (interface{}, error) {
switch channelType {
case AlertTypeEmail:
r := AlertChannelEmail{}
json.Unmarshal(cfgJSON, &r)
return &r, nil
case AlertTypeSMS:
r := AlertChannelSMS{}
json.Unmarshal(cfgJSON, &r)
return &r, nil
case AlertTypeCall:
r := AlertChannelCall{}
json.Unmarshal(cfgJSON, &r)
return &r, nil
case AlertTypeSlack:
r := AlertChannelSlack{}
json.Unmarshal(cfgJSON, &r)
return &r, nil
case AlertTypeOpsgenie:
r := AlertChannelOpsgenie{}
json.Unmarshal(cfgJSON, &r)
return &r, nil
case AlertTypePagerduty: