diff --git a/README.md b/README.md index e193833..e36610b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/uptimerobot/api/monitor.go b/uptimerobot/api/monitor.go index ad66ebe..b0294ec 100644 --- a/uptimerobot/api/monitor.go +++ b/uptimerobot/api/monitor.go @@ -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"` @@ -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 { @@ -270,6 +278,7 @@ type MonitorUpdateRequest struct { FriendlyName string URL string Type string + Status string Interval int SubType string @@ -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": diff --git a/uptimerobot/resource_uptimerobot_monitor.go b/uptimerobot/resource_uptimerobot_monitor.go index a60fc98..c8b725a 100644 --- a/uptimerobot/resource_uptimerobot_monitor.go +++ b/uptimerobot/resource_uptimerobot_monitor.go @@ -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, @@ -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 { @@ -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)