Skip to content

Commit

Permalink
Add support for DNS monitors (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrHeinz committed Jun 25, 2024
1 parent b781319 commit 066806d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GOLANGCI_LINT := golangci-lint run --disable-all \
-E staticcheck \
-E typecheck \
-E unused
VERSION := 0.11.0
VERSION := 0.11.1
.PHONY: test build

help:
Expand Down
5 changes: 4 additions & 1 deletion docs/data-sources/betteruptime_monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Monitor lookup.
`imap` We will check for an IMAP server at the host specified in the url parameter
(port is required, and can be 143, 993, or both).

`dns` We will check for a DNS server at the host specified in the url parameter
(request_body is required, and should contain the domain to query the DNS server with).

`playwright` We will run the scenario defined by playwright_script, identified in the UI by scenario_name
- **paused** (Boolean) Set to true to pause monitoring - we won't notify you about downtime. Set to false to resume monitoring.
- **paused_at** (String) The time when this monitor was paused.
Expand All @@ -82,7 +85,7 @@ Monitor lookup.
- **recovery_period** (Number) How long the monitor must be up to automatically mark an incident as resolved after being down. In seconds.
- **regions** (List of String) An array of regions to set. Allowed values are ["us", "eu", "as", "au"] or any subset of these regions.
- **remember_cookies** (Boolean) Set to true to keep cookies when redirecting.
- **request_body** (String) Request body for POST, PUT, PATCH requests.
- **request_body** (String) Request body for POST, PUT, PATCH requests. Required if monitor_type is set to dns (domain to query the DNS server with).
- **request_headers** (List of Map of String) An array of request headers, consisting of name and value pairs
- **request_timeout** (Number) How long to wait before timing out the request? In seconds.
- **required_keyword** (String) Required if monitor_type is set to keyword or udp. We will create a new incident if this keyword is missing on your page.
Expand Down
5 changes: 4 additions & 1 deletion docs/resources/betteruptime_monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ https://betterstack.com/docs/uptime/api/monitors/
`imap` We will check for an IMAP server at the host specified in the url parameter
(port is required, and can be 143, 993, or both).

`dns` We will check for a DNS server at the host specified in the url parameter
(request_body is required, and should contain the domain to query the DNS server with).

`playwright` We will run the scenario defined by playwright_script, identified in the UI by scenario_name
- **url** (String) URL of your website or the host you want to ping (see monitor_type below).

Expand Down Expand Up @@ -78,7 +81,7 @@ https://betterstack.com/docs/uptime/api/monitors/
- **recovery_period** (Number) How long the monitor must be up to automatically mark an incident as resolved after being down. In seconds.
- **regions** (List of String) An array of regions to set. Allowed values are ["us", "eu", "as", "au"] or any subset of these regions.
- **remember_cookies** (Boolean) Set to true to keep cookies when redirecting.
- **request_body** (String) Request body for POST, PUT, PATCH requests.
- **request_body** (String) Request body for POST, PUT, PATCH requests. Required if monitor_type is set to dns (domain to query the DNS server with).
- **request_headers** (List of Map of String) An array of request headers, consisting of name and value pairs
- **request_timeout** (Number) How long to wait before timing out the request? In seconds.
- **required_keyword** (String) Required if monitor_type is set to keyword or udp. We will create a new incident if this keyword is missing on your page.
Expand Down
21 changes: 18 additions & 3 deletions examples/advanced/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,35 @@ resource "betteruptime_monitor_group" "this" {
sort_index = 0
}

resource "betteruptime_monitor" "this" {
resource "betteruptime_monitor" "status" {
url = "https://example.com"
monitor_type = "status"
monitor_group_id = betteruptime_monitor_group.this.id
}

resource "betteruptime_status_page_resource" "monitor" {
resource "betteruptime_monitor" "dns" {
url = "1.1.1.1"
monitor_type = "dns"
request_body = "example.com"
monitor_group_id = betteruptime_monitor_group.this.id
}

resource "betteruptime_status_page_resource" "monitor_status" {
status_page_id = betteruptime_status_page.this.id
status_page_section_id = betteruptime_status_page_section.monitors.id
resource_id = betteruptime_monitor.this.id
resource_id = betteruptime_monitor.status.id
resource_type = "Monitor"
public_name = "example.com site"
}

resource "betteruptime_status_page_resource" "monitor_dns" {
status_page_id = betteruptime_status_page.this.id
status_page_section_id = betteruptime_status_page_section.monitors.id
resource_id = betteruptime_monitor.dns.id
resource_type = "Monitor"
public_name = "example.com domain"
}

resource "betteruptime_heartbeat_group" "this" {
name = "example"
sort_index = 0
Expand Down
7 changes: 5 additions & 2 deletions internal/provider/resource_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// TODO: change to map<name, description> and then use to gen monitor_type description
var monitorTypes = []string{"status", "expected_status_code", "keyword", "keyword_absence", "ping", "tcp", "udp", "smtp", "pop", "imap", "playwright"}
var monitorTypes = []string{"status", "expected_status_code", "keyword", "keyword_absence", "ping", "tcp", "udp", "smtp", "pop", "imap", "dns", "playwright"}
var ipVersions = []string{"ipv4", "ipv6"}
var monitorSchema = map[string]*schema.Schema{
"team_name": {
Expand Down Expand Up @@ -86,6 +86,9 @@ var monitorSchema = map[string]*schema.Schema{
**imap** We will check for an IMAP server at the host specified in the url parameter
(port is required, and can be 143, 993, or both).
**dns** We will check for a DNS server at the host specified in the url parameter
(request_body is required, and should contain the domain to query the DNS server with).
**playwright** We will run the scenario defined by playwright_script, identified in the UI by scenario_name`, "**", "`"),
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -242,7 +245,7 @@ var monitorSchema = map[string]*schema.Schema{
Computed: true,
},
"request_body": {
Description: "Request body for POST, PUT, PATCH requests.",
Description: "Request body for POST, PUT, PATCH requests. Required if monitor_type is set to dns (domain to query the DNS server with).",
Type: schema.TypeString,
Optional: true,
Computed: true,
Expand Down

0 comments on commit 066806d

Please sign in to comment.