Skip to content

Commit

Permalink
Merge pull request #218 from handlename/feature/connectivity-monitor-…
Browse files Browse the repository at this point in the history
…supports-alert-status

Add support for AlertStatusOnGone in mackerel_monitor connectivity resource
  • Loading branch information
Arthur1 committed Jun 17, 2024
2 parents 577340c + 1f855ae commit 73005a2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/resources/monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ The following arguments are required:

* `scopes` - The set of monitoring target’s service name or role name.
* `exclude_scopes` - The set of monitoring exclusion target’s service name or role name.
* `alert_status_on_gone` - The alert status when the monitoring target is gone. Valid values are `CRITICAL` and `WARNING`. Default is `CRITICAL`.

### service_metric

Expand Down
4 changes: 4 additions & 0 deletions mackerel/data_source_mackerel_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func dataSourceMackerelMonitor() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"alert_status_on_gone": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions mackerel/data_source_mackerel_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestAccDataSourceMackerelMonitorConnectivity(t *testing.T) {
resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dsName, "connectivity.0.scopes.#", "2"),
resource.TestCheckResourceAttr(dsName, "connectivity.0.exclude_scopes.#", "2"),
resource.TestCheckResourceAttr(dsName, "connectivity.0.alert_status_on_gone", "WARNING"),
),
resource.TestCheckResourceAttr(dsName, "service_metric.#", "0"),
resource.TestCheckResourceAttr(dsName, "external.#", "0"),
Expand Down Expand Up @@ -361,6 +362,7 @@ resource "mackerel_monitor" "foo" {
exclude_scopes = [
mackerel_service.not_scoped.name,
mackerel_role.not_scoped.id]
alert_status_on_gone = "WARNING"
}
}
Expand Down
7 changes: 7 additions & 0 deletions mackerel/resource_mackerel_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ func resourceMackerelMonitor() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"alert_status_on_gone": {
Type: schema.TypeString,
Optional: true,
Default: "CRITICAL",
ValidateFunc: validation.StringInSlice([]string{"CRITICAL", "WARNING"}, false),
},
},
},
},
Expand Down Expand Up @@ -478,6 +484,7 @@ func expandMonitorConnectivity(d *schema.ResourceData) *mackerel.MonitorConnecti
NotificationInterval: uint64(d.Get("notification_interval").(int)),
Scopes: expandStringListFromSet(d.Get("connectivity.0.scopes").(*schema.Set)),
ExcludeScopes: expandStringListFromSet(d.Get("connectivity.0.exclude_scopes").(*schema.Set)),
AlertStatusOnGone: d.Get("connectivity.0.alert_status_on_gone").(string),
}
return monitor
}
Expand Down
3 changes: 3 additions & 0 deletions mackerel/resource_mackerel_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestAccMackerelMonitor_Connectivity(t *testing.T) {
resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "connectivity.0.scopes.#", "0"),
resource.TestCheckResourceAttr(resourceName, "connectivity.0.exclude_scopes.#", "0"),
resource.TestCheckResourceAttr(resourceName, "connectivity.0.alert_status_on_gone", "CRITICAL"),
),
resource.TestCheckResourceAttr(resourceName, "service_metric.#", "0"),
resource.TestCheckResourceAttr(resourceName, "external.#", "0"),
Expand All @@ -134,6 +135,7 @@ func TestAccMackerelMonitor_Connectivity(t *testing.T) {
resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "connectivity.0.scopes.#", "2"),
resource.TestCheckResourceAttr(resourceName, "connectivity.0.exclude_scopes.#", "2"),
resource.TestCheckResourceAttr(resourceName, "connectivity.0.alert_status_on_gone", "WARNING"),
),
resource.TestCheckResourceAttr(resourceName, "service_metric.#", "0"),
resource.TestCheckResourceAttr(resourceName, "external.#", "0"),
Expand Down Expand Up @@ -665,6 +667,7 @@ resource "mackerel_monitor" "foo" {
exclude_scopes = [
mackerel_service.not_scoped.name,
mackerel_role.not_scoped.id]
alert_status_on_gone = "WARNING"
}
}
`, rand, rand, rand, rand, name)
Expand Down
5 changes: 3 additions & 2 deletions mackerel/structure_flattens.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ func flattenMonitorConnectivity(monitor *mackerel.MonitorConnectivity, d *schema
}
d.Set("connectivity", []map[string]interface{}{
{
"scopes": flattenStringListToSet(normalizedScopes),
"exclude_scopes": flattenStringListToSet(normalizedExcludeScopes),
"scopes": flattenStringListToSet(normalizedScopes),
"exclude_scopes": flattenStringListToSet(normalizedExcludeScopes),
"alert_status_on_gone": monitor.AlertStatusOnGone,
},
})
return diags
Expand Down

0 comments on commit 73005a2

Please sign in to comment.