Skip to content
This repository has been archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #30 from masayoshi634/add-host-monitor-max-check-a…
Browse files Browse the repository at this point in the history
…ttempts

Add max_check_attempts to host and service monitor
  • Loading branch information
kjmkznr authored Sep 15, 2020
2 parents 2c1d6b5 + 08f5b82 commit 4b2eade
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/provider/resource_mackerel_external_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func resourceMackerelExternalMonitor() *schema.Resource {
Optional: true,
},
"max_check_attempts": {
Type: schema.TypeFloat,
Optional: true,
Default: 1,
//ValidateFunc: validateDurationTime 1 - 10
Type: schema.TypeInt,
Optional: true,
Default: 1,
ValidateFunc: validation.IntBetween(1, 10),
},
"certification_expiration_warning": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -204,7 +204,7 @@ func getMackerelExternalMonitorInput(d *schema.ResourceData) *mackerel.MonitorEx
input.ContainsString = v.(string)
}
if v, ok := d.GetOk("max_check_attempts"); ok {
input.MaxCheckAttempts = uint64(v.(float64))
input.MaxCheckAttempts = uint64(v.(int))
}
if v, ok := d.GetOk("certification_expiration_warning"); ok {
input.CertificationExpirationWarning = puint64(uint64(v.(int)))
Expand Down
11 changes: 11 additions & 0 deletions internal/provider/resource_mackerel_host_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"

"github.com/mackerelio/mackerel-client-go"
)

Expand Down Expand Up @@ -46,6 +48,12 @@ func resourceMackerelHostMonitor() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"max_check_attempts": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 10),
Default: 1,
},
"scopes": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -76,6 +84,7 @@ func resourceMackerelHostMonitorCreate(d *schema.ResourceData, meta interface{})
Warning: pfloat64(d.Get("warning").(float64)),
Critical: pfloat64(d.Get("critical").(float64)),
NotificationInterval: uint64(d.Get("notification_interval").(int)),
MaxCheckAttempts: uint64(d.Get("max_check_attempts").(int)),
IsMute: d.Get("is_mute").(bool),
}

Expand Down Expand Up @@ -118,6 +127,7 @@ func resourceMackerelHostMonitorRead(d *schema.ResourceData, meta interface{}) e
_ = d.Set("warning", mon.Warning)
_ = d.Set("critical", mon.Critical)
_ = d.Set("notification_interval", mon.NotificationInterval)
_ = d.Set("max_check_attempts", mon.MaxCheckAttempts)
_ = d.Set("scopes", flattenStringList(mon.Scopes))
_ = d.Set("exclude_scopes", flattenStringList(mon.ExcludeScopes))
_ = d.Set("is_mute", mon.IsMute)
Expand All @@ -140,6 +150,7 @@ func resourceMackerelHostMonitorUpdate(d *schema.ResourceData, meta interface{})
Warning: pfloat64(d.Get("warning").(float64)),
Critical: pfloat64(d.Get("critical").(float64)),
NotificationInterval: uint64(d.Get("notification_interval").(int)),
MaxCheckAttempts: uint64(d.Get("max_check_attempts").(int)),
IsMute: d.Get("is_mute").(bool),
}

Expand Down
11 changes: 11 additions & 0 deletions internal/provider/resource_mackerel_host_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func TestAccMackerelHostMonitor_Basic(t *testing.T) {
"mackerel_host_monitor.foobar", "critical", "90"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "notification_interval", "10"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "max_check_attempts", "3"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "scopes.#", "0"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -70,6 +72,8 @@ func TestAccMackerelHostMonitor_Update(t *testing.T) {
"mackerel_host_monitor.foobar", "critical", "90"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "notification_interval", "10"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "max_check_attempts", "3"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "scopes.#", "0"),
resource.TestCheckResourceAttr(
Expand All @@ -93,6 +97,8 @@ func TestAccMackerelHostMonitor_Update(t *testing.T) {
"mackerel_host_monitor.foobar", "critical", "95.5"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "notification_interval", "10"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "max_check_attempts", "3"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "scopes.#", "0"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -128,6 +134,8 @@ func TestAccMackerelHostMonitor_Minimum(t *testing.T) {
"mackerel_host_monitor.foobar", "critical", "90"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "notification_interval", "10"),
resource.TestCheckResourceAttr(
"mackerel_host_monitor.foobar", "max_check_attempts", "3"),
),
},
},
Expand Down Expand Up @@ -166,6 +174,7 @@ resource "mackerel_host_monitor" "foobar" {
warning = 80.0
critical = 90.0
notification_interval = 10
max_check_attempts = 3
}`, rName)
}

Expand All @@ -179,6 +188,7 @@ resource "mackerel_host_monitor" "foobar" {
warning = 85.5
critical = 95.5
notification_interval = 10
max_check_attempts = 3
}`, rName)
}

Expand All @@ -192,5 +202,6 @@ resource "mackerel_host_monitor" "foobar" {
warning = 80.0
critical = 90.0
notification_interval = 10
max_check_attempts = 3
}`, rName)
}
10 changes: 10 additions & 0 deletions internal/provider/resource_mackerel_service_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/mackerelio/mackerel-client-go"
)

Expand Down Expand Up @@ -50,6 +51,12 @@ func resourceMackerelServiceMonitor() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"max_check_attempts": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 10),
Default: 1,
},
"is_mute": {
Type: schema.TypeBool,
Optional: true,
Expand All @@ -71,6 +78,7 @@ func resourceMackerelServiceMonitorCreate(d *schema.ResourceData, meta interface
Warning: pfloat64(d.Get("warning").(float64)),
Critical: pfloat64(d.Get("critical").(float64)),
NotificationInterval: uint64(d.Get("notification_interval").(int)),
MaxCheckAttempts: uint64(d.Get("max_check_attempts").(int)),
IsMute: d.Get("is_mute").(bool),
}

Expand Down Expand Up @@ -106,6 +114,7 @@ func resourceMackerelServiceMonitorRead(d *schema.ResourceData, meta interface{}
_ = d.Set("warning", mon.Warning)
_ = d.Set("critical", mon.Critical)
_ = d.Set("notification_interval", mon.NotificationInterval)
_ = d.Set("max_check_attempts", mon.MaxCheckAttempts)
_ = d.Set("is_mute", mon.IsMute)
break
}
Expand All @@ -127,6 +136,7 @@ func resourceMackerelServiceMonitorUpdate(d *schema.ResourceData, meta interface
Warning: pfloat64(d.Get("warning").(float64)),
Critical: pfloat64(d.Get("critical").(float64)),
NotificationInterval: uint64(d.Get("notification_interval").(int)),
MaxCheckAttempts: uint64(d.Get("max_check_attempts").(int)),
IsMute: d.Get("is_mute").(bool),
}

Expand Down
9 changes: 9 additions & 0 deletions internal/provider/resource_mackerel_service_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func TestAccMackerelServiceMonitor_Basic(t *testing.T) {
"mackerel_service_monitor.foobar", "critical", "90"),
resource.TestCheckResourceAttr(
"mackerel_service_monitor.foobar", "notification_interval", "10"),
resource.TestCheckResourceAttr(
"mackerel_service_monitor.foobar", "max_check_attempts", "3"),
),
},
},
Expand Down Expand Up @@ -70,6 +72,8 @@ func TestAccMackerelServiceMonitor_Update(t *testing.T) {
"mackerel_service_monitor.foobar", "critical", "90"),
resource.TestCheckResourceAttr(
"mackerel_service_monitor.foobar", "notification_interval", "10"),
resource.TestCheckResourceAttr(
"mackerel_service_monitor.foobar", "max_check_attempts", "3"),
),
},
{
Expand All @@ -91,6 +95,8 @@ func TestAccMackerelServiceMonitor_Update(t *testing.T) {
"mackerel_service_monitor.foobar", "critical", "95.5"),
resource.TestCheckResourceAttr(
"mackerel_service_monitor.foobar", "notification_interval", "10"),
resource.TestCheckResourceAttr(
"mackerel_service_monitor.foobar", "max_check_attempts", "3"),
),
},
},
Expand Down Expand Up @@ -167,6 +173,7 @@ resource "mackerel_service_monitor" "foobar" {
warning = 80.0
critical = 90.0
notification_interval = 10
max_check_attempts = 3
}
`, rName, rName)
}
Expand All @@ -186,6 +193,7 @@ resource "mackerel_service_monitor" "foobar" {
warning = 85.5
critical = 95.5
notification_interval = 10
max_check_attempts = 3
}
`, rName, rName)
}
Expand All @@ -205,6 +213,7 @@ resource "mackerel_service_monitor" "foobar" {
warning = 80.0
critical = 90.0
notification_interval = 10
max_check_attempts = 3
}
`, rName, rName)
}

0 comments on commit 4b2eade

Please sign in to comment.