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

Commit

Permalink
Merge branch 'drubin-update-contact-intervals'
Browse files Browse the repository at this point in the history
  • Loading branch information
louy committed Mar 15, 2019
2 parents 4c22b76 + 2464966 commit 752c353
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
10 changes: 6 additions & 4 deletions uptimerobot/api/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (client UptimeRobotApiClient) GetMonitor(id int) (m Monitor, err error) {
switch m.Type {
case "port":
m.SubType = intToString(monitorSubType, int(monitor["sub_type"].(float64)))
if (m.SubType != "custom") {
if m.SubType != "custom" {
m.Port = 0
} else {
m.Port = int(monitor["port"].(float64))
Expand All @@ -119,7 +119,9 @@ func (client UptimeRobotApiClient) GetMonitor(id int) (m Monitor, err error) {
}

type MonitorRequestAlertContact struct {
ID int
ID int
Threshold int
Recurrence int
}
type MonitorCreateRequest struct {
FriendlyName string
Expand Down Expand Up @@ -164,7 +166,7 @@ func (client UptimeRobotApiClient) CreateMonitor(req MonitorCreateRequest) (m Mo
}
acStrings := make([]string, len(req.AlertContacts))
for k, v := range req.AlertContacts {
acStrings[k] = fmt.Sprintf("%d", v.ID)
acStrings[k] = fmt.Sprintf("%d_%d_%d", v.ID, v.Threshold, v.Recurrence)
}
data.Add("alert_contacts", strings.Join(acStrings, "-"))

Expand Down Expand Up @@ -227,7 +229,7 @@ func (client UptimeRobotApiClient) UpdateMonitor(req MonitorUpdateRequest) (m Mo
}
acStrings := make([]string, len(req.AlertContacts))
for k, v := range req.AlertContacts {
acStrings[k] = fmt.Sprintf("%d", v.ID)
acStrings[k] = fmt.Sprintf("%d_%d_%d", v.ID, v.Threshold, v.Recurrence)
}
data.Add("alert_contacts", strings.Join(acStrings, "-"))

Expand Down
4 changes: 3 additions & 1 deletion uptimerobot/resource_uptimerobot_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ func resourceMonitorCreate(d *schema.ResourceData, m interface{}) error {
req.AlertContacts = make([]uptimerobotapi.MonitorRequestAlertContact, len(d.Get("alert_contact").([]interface{})))
for k, v := range d.Get("alert_contact").([]interface{}) {
req.AlertContacts[k] = uptimerobotapi.MonitorRequestAlertContact{
ID: v.(map[string]interface{})["id"].(int),
ID: v.(map[string]interface{})["id"].(int),
Threshold: v.(map[string]interface{})["threshold"].(int),
Recurrence: v.(map[string]interface{})["recurrence"].(int),
}
}

Expand Down
47 changes: 47 additions & 0 deletions uptimerobot/resource_uptimerobot_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,53 @@ func TestUptimeRobotDataResourceMonitor_custom_port_monitor(t *testing.T) {
})
}

func TestUptimeRobotDataResourceMonitor_custom_alert_contact_threshold_and_recurrence(t *testing.T) {
var FriendlyName = "TF Test: custom alert contact threshold & recurrence"
var Type = "http"
var URL = "https://google.com"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMonitorDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_alert_contact" "test" {
friendly_name = "#infrastructure"
type = "slack"
value = "https://slack.com/services/xxxx"
}
resource "uptimerobot_monitor" "test" {
friendly_name = "%s"
type = "%s"
url = "%s"
alert_contact {
id = "${uptimerobot_alert_contact.test.id}"
threshold = 0
recurrence = 0
}
}
`, FriendlyName, Type, URL),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "friendly_name", FriendlyName),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "type", Type),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "url", URL),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "alert_contact.#", "1"),
resource.TestCheckResourceAttrSet("uptimerobot_monitor.test", "alert_contact.0.id"),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "alert_contact.0.threshold", "0"),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "alert_contact.0.recurrence", "0"),
),
},
resource.TestStep{
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
// uptimerobot doesn't support pulling alert_contact
// ImportStateVerify: true,
},
},
})
}

func TestUptimeRobotDataResourceMonitor_change_url(t *testing.T) {
var FriendlyName = "TF Test: http monitor"
var Type = "http"
Expand Down

0 comments on commit 752c353

Please sign in to comment.