Skip to content

Commit fa5f4e3

Browse files
committed
feat(endpoints): add domain-expiration-only-check
1 parent 5d626f2 commit fa5f4e3

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,6 +3136,11 @@ endpoints:
31363136
conditions:
31373137
- "[DOMAIN_EXPIRATION] > 720h"
31383138
- "[CERTIFICATE_EXPIRATION] > 240h"
3139+
- name: check-domain-expiration-only
3140+
url: "domain://example.org"
3141+
interval: 1h
3142+
conditions:
3143+
- "[DOMAIN_EXPIRATION] > 720h"
31393144
```
31403145

31413146
> ⚠ The usage of the `[DOMAIN_EXPIRATION]` placeholder requires Gatus to use RDAP, or as a fallback, send a request to the official IANA WHOIS service

config/endpoint/endpoint.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const (
5353
TypeGRPC Type = "GRPC"
5454
TypeWS Type = "WEBSOCKET"
5555
TypeSSH Type = "SSH"
56+
TypeDomain Type = "DOMAIN"
5657
TypeUNKNOWN Type = "UNKNOWN"
5758
)
5859

@@ -184,6 +185,8 @@ func (e *Endpoint) Type() Type {
184185
return TypeWS
185186
case strings.HasPrefix(e.URL, "ssh://"):
186187
return TypeSSH
188+
case strings.HasPrefix(e.URL, "domain://"):
189+
return TypeDomain
187190
default:
188191
return TypeUNKNOWN
189192
}
@@ -452,8 +455,12 @@ func (e *Endpoint) call(result *Result) {
452455
var err error
453456
var certificate *x509.Certificate
454457
endpointType := e.Type()
455-
if endpointType == TypeHTTP {
458+
switch endpointType {
459+
case TypeHTTP:
456460
request = e.buildHTTPRequest()
461+
case TypeDomain:
462+
// domain expiration checked before call `call`
463+
return
457464
}
458465
startTime := time.Now()
459466
if endpointType == TypeDNS {

config/endpoint/endpoint_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,27 @@ func TestEndpoint(t *testing.T) {
162162
return &http.Response{StatusCode: http.StatusOK, Body: http.NoBody}
163163
}),
164164
},
165+
{
166+
Name: "domain-expiration-without-http-request",
167+
Endpoint: Endpoint{
168+
Name: "domain-check",
169+
URL: "domain://twin.sh",
170+
Conditions: []Condition{"[DOMAIN_EXPIRATION] > 100h"},
171+
Interval: 5 * time.Minute,
172+
},
173+
ExpectedResult: &Result{
174+
Success: true,
175+
Connected: false,
176+
Hostname: "twin.sh",
177+
ConditionResults: []*ConditionResult{
178+
{Condition: "[DOMAIN_EXPIRATION] > 100h", Success: true},
179+
},
180+
DomainExpiration: 999999 * time.Hour, // Note that this test only checks if it's non-zero.
181+
},
182+
MockRoundTripper: test.MockRoundTripper(func(r *http.Request) *http.Response {
183+
return &http.Response{StatusCode: http.StatusOK, Body: http.NoBody}
184+
}),
185+
},
165186
{
166187
Name: "endpoint-that-will-time-out-and-hidden-hostname",
167188
Endpoint: Endpoint{
@@ -364,6 +385,12 @@ func TestEndpoint_Type(t *testing.T) {
364385
},
365386
want: TypeSSH,
366387
},
388+
{
389+
args: args{
390+
URL: "domain://example.org",
391+
},
392+
want: TypeDomain,
393+
},
367394
{
368395
args: args{
369396
URL: "invalid://example.org",

0 commit comments

Comments
 (0)