Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Add Pause feature
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdelorme committed Dec 21, 2022
1 parent c473457 commit 7080628
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ resource "uptimerobot_monitor" "main" {
url = "http://example.com"
# pro allows 60 seconds
interval = 300
paused = true
alert_contact {
id = uptimerobot_alert_contact.slack.id
Expand Down
10 changes: 10 additions & 0 deletions uptimerobot/api/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Monitor struct {
URL string `json:"url"`
Type string `json:"type"`
Status string `json:"status"`
Paused bool `json:"paused"`
Interval int `json:"interval"`

SubType string `json:"sub_type"`
Expand Down Expand Up @@ -114,6 +115,13 @@ func (client UptimeRobotApiClient) GetMonitor(id int) (m Monitor, err error) {
m.URL = monitor["url"].(string)
m.Type = intToString(monitorType, int(monitor["type"].(float64)))
m.Status = intToString(monitorStatus, int(monitor["status"].(float64)))

if m.Status == "paused" {
m.Paused = true
} else {
m.Paused = false
}

m.Interval = int(monitor["interval"].(float64))

switch m.Type {
Expand Down Expand Up @@ -270,6 +278,7 @@ type MonitorUpdateRequest struct {
FriendlyName string
URL string
Type string
Status string
Interval int

SubType string
Expand All @@ -295,6 +304,7 @@ func (client UptimeRobotApiClient) UpdateMonitor(req MonitorUpdateRequest) (m Mo
data.Add("friendly_name", req.FriendlyName)
data.Add("url", req.URL)
data.Add("type", fmt.Sprintf("%d", monitorType[req.Type]))
data.Add("status", req.Status)
data.Add("interval", fmt.Sprintf("%d", req.Interval))
switch req.Type {
case "port":
Expand Down
14 changes: 14 additions & 0 deletions uptimerobot/resource_uptimerobot_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func resourceMonitor() *schema.Resource {
Optional: true,
Default: false,
},
"paused": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"alert_contact": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -196,11 +201,19 @@ func resourceMonitorUpdate(d *schema.ResourceData, m interface{}) error {
return err
}

var status string
if d.Get("paused").(bool) {
status = "0"
} else {
status = "1"
}

req := uptimerobotapi.MonitorUpdateRequest{
ID: id,
FriendlyName: d.Get("friendly_name").(string),
URL: d.Get("url").(string),
Type: d.Get("type").(string),
Status: status,
}

switch req.Type {
Expand Down Expand Up @@ -274,6 +287,7 @@ func updateMonitorResource(d *schema.ResourceData, m uptimerobotapi.Monitor) err
d.Set("url", m.URL)
d.Set("type", m.Type)
d.Set("status", m.Status)
d.Set("paused", m.Paused)
d.Set("interval", m.Interval)

d.Set("sub_type", m.SubType)
Expand Down

0 comments on commit 7080628

Please sign in to comment.