Skip to content

Commit

Permalink
feat: add monitor advanced settings
Browse files Browse the repository at this point in the history
  • Loading branch information
eidam committed May 18, 2021
1 parent 6ea6eea commit 41b50f4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/resources/monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ resource "statusflare_monitor" "example" {
### Optional

- **expect_status** (Number) The expected HTTP status code. The default is 200.
- **follow_redirects** (Boolean)
- **insecure_skip_verify** (Boolean)
- **integrations** (List of String) IDs of integrations attached to this monitor.
- **interval** (Number) Check interval in seconds.
- **method** (String) The HTTP method. The default is 'GET'.
- **retries** (Number) Retries or also 'notify_after' field in API. The default is 1.
- **scheme** (String) The scheme might be http or https. The default value is https.
- **timeout** (Number) Timeout interval in seconds.
- **worker** (String) ID of the worker to perform checks from. The default is 'managed'.

### Read-Only
Expand Down
29 changes: 29 additions & 0 deletions internal/provider/resource_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ func resourceMonitor() *schema.Resource {
},
Description: "IDs of integrations attached to this monitor.",
},
"follow_redirects": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"insecure_skip_verify": {
Type: schema.TypeBool,
Optional: true,
},
"timeout": {
Type: schema.TypeInt,
Default: 30,
Optional: true,
Description: "Timeout interval in seconds.",
},
"interval": {
Type: schema.TypeInt,
Default: 300,
Optional: true,
Description: "Check interval in seconds.",
},
}

return &schema.Resource{
Expand Down Expand Up @@ -149,6 +170,10 @@ func dataToMonitor(src *schema.ResourceData, dst *statusflare.Monitor) {
dst.NotifyAfter = src.Get("retries").(int)
dst.Worker = src.Get("worker").(string)
dst.Integrations = toStrArray(src.Get("integrations").([]interface{}))
dst.FollowRedirects = src.Get("follow_redirects").(bool)
dst.InsecureSkipVerify = src.Get("insecure_skip_verify").(bool)
dst.Timeout = src.Get("timeout").(int)
dst.Interval = src.Get("interval").(int)
}

func monitorToData(src *statusflare.Monitor, dst *schema.ResourceData) {
Expand All @@ -160,4 +185,8 @@ func monitorToData(src *statusflare.Monitor, dst *schema.ResourceData) {
dst.Set("worker", src.Worker)
dst.Set("retries", src.NotifyAfter)
dst.Set("integrations", src.Integrations)
dst.Set("follow_redirects", src.FollowRedirects)
dst.Set("insecure_skip_verify", src.InsecureSkipVerify)
dst.Set("timeout", src.Timeout)
dst.Set("interval", src.Interval)
}
22 changes: 13 additions & 9 deletions statusflare/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import (
)

type Monitor struct {
Id string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Scheme string `json:"schema"` // not sure if it's typo in API, but I'm using Scheme here
Method string `json:"method"`
ExpectStatus int `json:"expect_status"`
NotifyAfter int `json:"notify_after"`
Worker string `json:"worker"`
Integrations []string `json:"integrations"`
Id string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Scheme string `json:"schema"` // not sure if it's typo in API, but I'm using Scheme here
Method string `json:"method"`
ExpectStatus int `json:"expect_status"`
NotifyAfter int `json:"notify_after"`
Worker string `json:"worker"`
Integrations []string `json:"integrations"`
FollowRedirects bool `json:"follow_redirects"`
InsecureSkipVerify bool `json:"insecure_skip_verify"`
Timeout int `json:"timeout"`
Interval int `json:"interval"`
}

// create new monitor
Expand Down

0 comments on commit 41b50f4

Please sign in to comment.