diff --git a/README.md b/README.md index 0476577..ecc2b86 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The Guance Provider provides resources to manage [Guance Cloud](https://en.guanc ## Documentation, questions, and discussions -Official documentation on how to use this provider can be found on the [Terraform Registry](https://registry.terraform.io/providers/guance/guance/latest/docs). +Official documentation on how to use this provider can be found on the [Terraform Registry](https://registry.terraform.io/providers/GuanceCloud/guance/latest/docs). The remainder of this document will focus on the development aspects of the provider. @@ -14,14 +14,26 @@ The resource supports as follows: * [x] notification * [x] pipeline -* [x] members * [x] member group * [x] alert policy -* [ ] mute -* [ ] monitor, see built-in modules at [terraform-guance-monitor](https://github.com/GuanceCloud/terraform-guance-monitor) -* [ ] dashboard, see built-in modules at [terraform-guance-dashboard](https://github.com/GuanceCloud/terraform-guance-dashboard) +* [x] mute +* [x] black list +* [x] monitor, see built-in modules at [terraform-guance-monitor](https://github.com/GuanceCloud/terraform-guance-monitor) +* [x] dashboard, see built-in modules at [terraform-guance-dashboard](https://github.com/GuanceCloud/terraform-guance-dashboard) + +The data source supports as follows: + +* [x] members + +The region supports as follows: + +* [x] hangzhou +* [x] ningxia +* [x] zhangjiakou +* [x] guangzhou +* [x] oregon -If there are more resources you need, create an [issue]() for free. +If there are more resources you need, create an [issue](https://github.com/GuanceCloud/terraform-provider-guance/issues) for free. ## Compatibility @@ -30,11 +42,11 @@ version it implements, and Terraform: | Guance Provider | Terraform Plugin Protocol | Terraform | |:---------------:|:-------------------------:|:---------:| -| `>= 0.x` | `5` and `6` | `>= 0.12` | +| `>= 0.x` | `6` | `>= 1.0` | Details can be found by querying the [Registry API](https://www.terraform.io/internals/provider-registry-protocol#list-available-versions) that return all the details about which versions are currently available for a particular provider. -[Here](https://registry.terraform.io/v1/providers/guance/guance/versions) are the details. +[Here](https://registry.terraform.io/v1/providers/GuanceCloud/guance/versions) are the details. ## Requirements diff --git a/docs/data-sources/members.md b/docs/data-sources/members.md index 4340556..aede058 100644 --- a/docs/data-sources/members.md +++ b/docs/data-sources/members.md @@ -31,16 +31,16 @@ graph LR ### Optional -- `filter` (Attributes List) The list of the resource (see [below for nested schema](#nestedatt--filter)) +- `filters` (Attributes List) The list of the resource (see [below for nested schema](#nestedatt--filters)) - `max_results` (Number) The max results count of the resource will be returned. ### Read-Only -- `id` (String) Identifier of the resource. +- `id` (String) The hasd id of the resource. - `items` (Attributes List) The list of the resource (see [below for nested schema](#nestedatt--items)) - -### Nested Schema for `filter` + +### Nested Schema for `filters` Required: @@ -54,11 +54,11 @@ Required: Optional: - `email` (String) Email -- `role` (String) Role +- `role` (String) Role, value must be one of: *owner*, *wsAdmin*, *general*, *readOnly*, other value will be ignored. Read-Only: -- `created_at` (String) Timestamp of the last Terraform update of the order. -- `id` (String) Numeric identifier of the order. +- `created_at` (String) The RFC3339/ISO8601 time string of resource created at. +- `id` (String) The Guance Resource Name (GRN) of cloud resource. diff --git a/docs/index.md b/docs/index.md index 97a0df3..b86e5cf 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,12 +3,77 @@ page_title: "guance Provider" subcategory: "" description: |- - Interact with Guance Cloud. + Terraform Provider: Guance + The Guance Provider provides resources to manage Guance Cloud https://en.guance.com/ resources. + To learn the basics of Terraform using this provider, follow the hands-on get started tutorials. + Interested in the provider's latest features, or want to make sure you're up to date? Check out the changelog for version information and release notes. + Authenticating to Guance Cloud + Terraform supports a number of different methods for authenticating to Guance Cloud: + Workspace Key ID https://console.guance.com/workspace/apiManage + Usage + ```terraform + We strongly recommend using the required_providers block to set the + Guance Cloud Provider source and version being used + terraform { + required_version = ">=0.12" + required_providers { + guance = { + source = "GuanceCloud/guance" + version = "=0.0.4" + } + } + } + // We also recommend use secret environment variables to set the provider, + // Such as GUANCEACCESSTOKEN and GUANCEREGION + provider "guance" { + # accesstoken = "your access token, recommend store in environment variable" + region = "hangzhou" + } + ``` + More Examples --- # guance Provider -Interact with Guance Cloud. +# Terraform Provider: Guance + +The Guance Provider provides resources to manage [Guance Cloud](https://en.guance.com/) resources. + +To learn the basics of Terraform using this provider, follow the hands-on get started tutorials. + +Interested in the provider's latest features, or want to make sure you're up to date? Check out the changelog for version information and release notes. + +## Authenticating to Guance Cloud + +Terraform supports a number of different methods for authenticating to Guance Cloud: + +* [Workspace Key ID](https://console.guance.com/workspace/apiManage) + +## Usage + +```terraform +# We strongly recommend using the required_providers block to set the +# Guance Cloud Provider source and version being used +terraform { + required_version = ">=0.12" + + required_providers { + guance = { + source = "GuanceCloud/guance" + version = "=0.0.4" + } + } +} + +// We also recommend use secret environment variables to set the provider, +// Such as GUANCE_ACCESS_TOKEN and GUANCE_REGION +provider "guance" { + # access_token = "your access token, recommend store in environment variable" + region = "hangzhou" +} +``` + +## More Examples @@ -17,5 +82,5 @@ Interact with Guance Cloud. ### Optional -- `region` (String) Region for Guance Cloud API. May also be provided via GUANCE_REGION environment variable. -- `token` (String, Sensitive) Access token for Guance Cloud API. May also be provided via GUANCE_TOKEN environment variable. +- `access_token` (String, Sensitive) Access token for Guance Cloud API. May also be provided via GUANCE_ACCESS_TOKEN environment variable. Get an Key ID from [Guance Cloud](https://console.guance.com/workspace/apiManage) as access token. +- `region` (String) Region for Guance Cloud API. May also be provided via GUANCE_REGION environment variable. See [GitHub](https://github.com/GuanceCloud/terraform-provider-guance) for a list of available regions. diff --git a/docs/resources/alertpolicy.md b/docs/resources/alertpolicy.md index e796792..8ada8f4 100644 --- a/docs/resources/alertpolicy.md +++ b/docs/resources/alertpolicy.md @@ -30,7 +30,7 @@ description: |- type = string } data "guance_members" "demo" { - filter = [ + filters = [ { name = "email" values = [var.email] @@ -123,7 +123,7 @@ variable "email" { } data "guance_members" "demo" { - filter = [ + filters = [ { name = "email" values = [var.email] @@ -194,15 +194,15 @@ resource "guance_alertpolicy" "demo" { ### Read-Only -- `created_at` (String) Timestamp of the last Terraform update of the order. -- `id` (String) Numeric identifier of the order. +- `created_at` (String) The RFC3339/ISO8601 time string of resource created at. +- `id` (String) The Guance Resource Name (GRN) of cloud resource. ### Nested Schema for `alert_targets` Required: -- `type` (String) Alert type +- `type` (String) Alert type, value must be one of: *member_group*, *notification*, other value will be ignored. Optional: diff --git a/docs/resources/blacklist.md b/docs/resources/blacklist.md new file mode 100644 index 0000000..887c2df --- /dev/null +++ b/docs/resources/blacklist.md @@ -0,0 +1,104 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "guance_blacklist Resource - guance" +subcategory: "" +description: |- + Black List + Guance Cloud supports filtering data that meets the conditions by setting a blacklist. + After configuring the blacklist, the data that meets the conditions will no longer be reported to the Guance Cloud + workspace, helping you save data storage costs. + Create + The first let me create a resource. We will send the create operation to the resource management service + ```terraform + resource "guance_blacklist" "demo" { + source = { + type = "logging" + name = "nginx" + } + filter_rules = [ + { + name = "foo" + operation = "in" + condition = "and" + values = ["oac-*"] + } + ] + } + ``` +--- + +# guance_blacklist (Resource) + +# Black List + +Guance Cloud supports filtering data that meets the conditions by setting a blacklist. + +After configuring the blacklist, the data that meets the conditions will no longer be reported to the Guance Cloud +workspace, helping you save data storage costs. + +## Create + +The first let me create a resource. We will send the create operation to the resource management service + +```terraform +resource "guance_blacklist" "demo" { + source = { + type = "logging" + name = "nginx" + } + + filter_rules = [ + { + name = "foo" + operation = "in" + condition = "and" + values = ["oac-*"] + } + ] +} +``` + + + + +## Schema + +### Required + +- `source` (Attributes) Source (see [below for nested schema](#nestedatt--source)) + +### Optional + +- `filter_rules` (Attributes List) Filters (see [below for nested schema](#nestedatt--filter_rules)) + +### Read-Only + +- `created_at` (String) The RFC3339/ISO8601 time string of resource created at. +- `id` (String) The Guance Resource Name (GRN) of cloud resource. + + +### Nested Schema for `source` + +Required: + +- `type` (String) Source Type, value must be one of: *logging*, *object*, *custom_object*, *network*, *tracing*, *rum*, *security*, *keyevent*, *metric*, other value will be ignored. + +Optional: + +- `name` (String) Source + + + +### Nested Schema for `filter_rules` + +Required: + +- `condition` (String) Condition, represented by DQL +- `name` (String) Name +- `operation` (String) Operation, value must be one of: *in*, *not in*, *match*, *not match*, other value will be ignored. + +Optional: + +- `values` (List of String) Values + + diff --git a/docs/resources/dashboard.md b/docs/resources/dashboard.md index a8e5c80..86d2bc2 100644 --- a/docs/resources/dashboard.md +++ b/docs/resources/dashboard.md @@ -4,15 +4,20 @@ page_title: "guance_dashboard Resource - guance" subcategory: "" description: |- Dashboard - WORKING IN PROGRESS - A dashboard is a collection of visualizations that you can use to monitor the health of your systems and applications. Dashboards are made up of one or more panels, which are the visualizations themselves. Each panel displays a single metric or a single aggregation of metrics. - Dashboards are a great way to visualize your data and monitor your systems. You can use them to track metrics over time, and to quickly see how your systems are performing. You can also use them to compare metrics from different systems and applications. - Guance Cloud's dashboard is used to clearly show the range in which the metric data values are located. It is suitable for slicing messy data into points. + A dashboard is a collection of visualizations that you can use to monitor the health of your systems and applications. + Dashboards are made up of one or more panels, which are the visualizations themselves. Each panel displays a single + metric or a single aggregation of metrics. + Dashboards are a great way to visualize your data and monitor your systems. You can use them to track metrics over time, + and to quickly see how your systems are performing. You can also use them to compare metrics from different systems and + applications. + Guance Cloud's dashboard is used to clearly show the range in which the metric data values are located. It is suitable + for slicing messy data into points. Create The first let me create a resource. We will send the create operation to the resource management service terraform resource "guance_dashboard" "demo" { - name = "oac-demo" + name = "oac-demo" + manifest = file("${path.module}/dashboard.json") } --- @@ -20,13 +25,16 @@ description: |- # Dashboard -**WORKING IN PROGRESS** +A dashboard is a collection of visualizations that you can use to monitor the health of your systems and applications. +Dashboards are made up of one or more panels, which are the visualizations themselves. Each panel displays a single +metric or a single aggregation of metrics. -A dashboard is a collection of visualizations that you can use to monitor the health of your systems and applications. Dashboards are made up of one or more panels, which are the visualizations themselves. Each panel displays a single metric or a single aggregation of metrics. +Dashboards are a great way to visualize your data and monitor your systems. You can use them to track metrics over time, +and to quickly see how your systems are performing. You can also use them to compare metrics from different systems and +applications. -Dashboards are a great way to visualize your data and monitor your systems. You can use them to track metrics over time, and to quickly see how your systems are performing. You can also use them to compare metrics from different systems and applications. - -Guance Cloud's dashboard is used to clearly show the range in which the metric data values are located. It is suitable for slicing messy data into points. +Guance Cloud's dashboard is used to clearly show the range in which the metric data values are located. It is suitable +for slicing messy data into points. ## Create @@ -34,7 +42,8 @@ The first let me create a resource. We will send the create operation to the res ```terraform resource "guance_dashboard" "demo" { - name = "oac-demo" + name = "oac-demo" + manifest = file("${path.module}/dashboard.json") } ``` @@ -45,163 +54,12 @@ resource "guance_dashboard" "demo" { ### Required +- `manifest` (String) Dashboard Manifest - `name` (String) Dashboard Name -### Optional - -- `extend` (String) Dashboard Extend -- `mapping` (Attributes List) Dashboard Mapping (see [below for nested schema](#nestedatt--mapping)) -- `tags` (List of String) Dashboard Tag Names -- `template` (Attributes) Dashboard Template Info (see [below for nested schema](#nestedatt--template)) - ### Read-Only -- `created_at` (String) Timestamp of the last Terraform update of the order. -- `id` (String) Numeric identifier of the order. - - -### Nested Schema for `mapping` - -Required: - -- `class` (String) Class Name -- `datasource` (String) Data Source -- `field` (String) Field Name -- `mapping` (String) Mapping Field Name - - - -### Nested Schema for `template` - -Required: - -- `title` (String) Dashboard Title - -Optional: - -- `dashboard` (Attributes) Dashboard Info (see [below for nested schema](#nestedatt--template--dashboard)) -- `icon_set` (Attributes) Dashboard Icon Set (see [below for nested schema](#nestedatt--template--icon_set)) -- `main` (Attributes) Dashboard Main (see [below for nested schema](#nestedatt--template--main)) -- `summary` (String) Dashboard Summary - - -### Nested Schema for `template.dashboard` - -Optional: - -- `extend` (String) Dashboard Extend -- `mapping` (Attributes List) Dashboard Mapping (see [below for nested schema](#nestedatt--template--dashboard--mapping)) - - -### Nested Schema for `template.dashboard.mapping` - -Required: - -- `class` (String) Class Name -- `datasource` (String) Data Source -- `field` (String) Field Name -- `mapping` (String) Mapping Field Name - - - - -### Nested Schema for `template.icon_set` - -Optional: - -- `md` (String) Middle Icon -- `sm` (String) Small Icon - - - -### Nested Schema for `template.main` - -Required: - -- `type` (String) Dashboard Type - -Optional: - -- `charts` (Attributes List) Dashboard Charts (see [below for nested schema](#nestedatt--template--main--charts)) -- `groups` (List of String) Dashboard Groups -- `vars` (Attributes List) Dashboard Vars (see [below for nested schema](#nestedatt--template--main--vars)) - - -### Nested Schema for `template.main.charts` - -Required: - -- `name` (String) Chart Name -- `type` (String) Chart Type - -Optional: - -- `group` (String) Chart Group -- `pos` (Attributes) Chart Position Info (see [below for nested schema](#nestedatt--template--main--charts--pos)) -- `queries` (Attributes List) Chart Query Info (see [below for nested schema](#nestedatt--template--main--charts--queries)) - - -### Nested Schema for `template.main.charts.queries` - -Required: - -- `h` (Number) Chart Height -- `i` (String) TODO: What is i? -- `w` (Number) Chart Width -- `x` (Number) Chart X -- `y` (Number) Chart Y - - - -### Nested Schema for `template.main.charts.queries` - -Required: - -- `checked` (Boolean) Checked -- `datasource` (String) Datasource -- `qtype` (String) Query Type -- `query` (Attributes) Query (see [below for nested schema](#nestedatt--template--main--charts--queries--query)) - -Optional: - -- `unit` (String) Unit - - -### Nested Schema for `template.main.charts.queries.query` - -Required: - -- `density` (String) Density -- `filter` (Attributes List) Filter (see [below for nested schema](#nestedatt--template--main--charts--queries--query--filter)) -- `group_by` (String) Group By -- `group_by_time` (String) Group By Time -- `q` (String) Query - - -### Nested Schema for `template.main.charts.queries.query.q` - -Required: - -- `logic` (String) Logic -- `name` (String) Field Name -- `op` (String) Operator -- `value` (String) Value - - - - - - -### Nested Schema for `template.main.vars` - -Required: - -- `name` (String) Var Name -- `type` (String) Var Type -- `value` (String) Var Value - -Optional: - -- `label` (String) Var Label +- `created_at` (String) The RFC3339/ISO8601 time string of resource created at. +- `id` (String) The Guance Resource Name (GRN) of cloud resource. diff --git a/docs/resources/membergroup.md b/docs/resources/membergroup.md index 2528b43..fa856c3 100644 --- a/docs/resources/membergroup.md +++ b/docs/resources/membergroup.md @@ -21,7 +21,7 @@ description: |- type = string } data "guance_members" "demo" { - filter = [ + filters = [ { name = "email" values = [var.email] @@ -64,7 +64,7 @@ variable "email" { } data "guance_members" "demo" { - filter = [ + filters = [ { name = "email" values = [var.email] @@ -93,7 +93,7 @@ resource "guance_membergroup" "demo" { ### Read-Only -- `created_at` (String) Timestamp of the last Terraform update of the order. -- `id` (String) Numeric identifier of the order. +- `created_at` (String) The RFC3339/ISO8601 time string of resource created at. +- `id` (String) The Guance Resource Name (GRN) of cloud resource. diff --git a/docs/resources/monitor.md b/docs/resources/monitor.md index 55362e6..b161b7b 100644 --- a/docs/resources/monitor.md +++ b/docs/resources/monitor.md @@ -4,10 +4,14 @@ page_title: "guance_monitor Resource - guance" subcategory: "" description: |- Monitor - WORKING IN PROGRESS - A monitor is a set of checks that you can run against your data. A monitor watches your data over time and alerts you when certain conditions are met. For example, you can create a monitor that watches the average response time of your website and alerts you when the response time is greater than 1 second. - Monitors are made up of one or more checks. A check is a single test that you can run against your data. For example, you can create a check that watches the average response time of your website. You can also create a check that watches the percentage of 5xx errors in your logs. - Guance Cloud supports defining monitors, users can customize the configuration of detection rules and trigger conditions, and open the monitors to receive related alarm events triggered by the detection rules. + A monitor is a set of checks that you can run against your data. A monitor watches your data over time and alerts you + when certain conditions are met. For example, you can create a monitor that watches the average response time of your + website and alerts you when the response time is greater than 1 second. + Monitors are made up of one or more checks. A check is a single test that you can run against your data. For example, + you can create a check that watches the average response time of your website. You can also create a check that watches + the percentage of 5xx errors in your logs. + Guance Cloud supports defining monitors, users can customize the configuration of detection rules and trigger + conditions, and open the monitors to receive related alarm events triggered by the detection rules. Relationships: ```mermaid graph LR @@ -15,23 +19,67 @@ description: |- ``` Create The first let me create a resource. We will send the create operation to the resource management service - terraform - resource "guance_monitor" "demo" { - name = "oac-demo" + ```terraform + variable "email" { + type = string } + data "guance_members" "demo" { + filters = [ + { + name = "email" + values = [var.email] + } + ] + } + resource "guancemembergroup" "demo" { + name = "oac-demo" + memberids = data.guance_members.demo.items[*].id + } + resource "guancealertpolicy" "demo" { + name = "oac-demo" + silenttimeout = "1h" + statuses = [ + "critical", + "error", + "warning", + "info", + "ok", + "nodata", + "nodataok", + "nodataas_ok", + ] + alerttargets = [ + { + type = "membergroup" + membergroup = { + id = guancemembergroup.demo.id + } + }, + ] + } + resource "guancemonitor" "demo" { + manifest = file("${path.module}/monitor.json") + alertpolicy = { + id = guance_alertpolicy.demo.id + } + } + ``` --- # guance_monitor (Resource) # Monitor -**WORKING IN PROGRESS** +A monitor is a set of checks that you can run against your data. A monitor watches your data over time and alerts you +when certain conditions are met. For example, you can create a monitor that watches the average response time of your +website and alerts you when the response time is greater than 1 second. -A monitor is a set of checks that you can run against your data. A monitor watches your data over time and alerts you when certain conditions are met. For example, you can create a monitor that watches the average response time of your website and alerts you when the response time is greater than 1 second. +Monitors are made up of one or more checks. A check is a single test that you can run against your data. For example, +you can create a check that watches the average response time of your website. You can also create a check that watches +the percentage of 5xx errors in your logs. -Monitors are made up of one or more checks. A check is a single test that you can run against your data. For example, you can create a check that watches the average response time of your website. You can also create a check that watches the percentage of 5xx errors in your logs. - -Guance Cloud supports defining monitors, users can customize the configuration of detection rules and trigger conditions, and open the monitors to receive related alarm events triggered by the detection rules. +Guance Cloud supports defining monitors, users can customize the configuration of detection rules and trigger +conditions, and open the monitors to receive related alarm events triggered by the detection rules. Relationships: @@ -46,645 +94,89 @@ A[Monitor] --> B[Alert Policy] --> C[Notification] The first let me create a resource. We will send the create operation to the resource management service ```terraform -resource "guance_monitor" "demo" { - name = "oac-demo" +variable "email" { + type = string } -``` - - - - -## Schema - -### Optional - -- `dashboard_id` (String) -- `script` (Attributes) (see [below for nested schema](#nestedatt--script)) - -### Read-Only - -- `created_at` (String) Timestamp of the last Terraform update of the order. -- `id` (String) Numeric identifier of the order. - - -### Nested Schema for `script` - -Optional: - -- `apm_check` (Attributes) APM check (see [below for nested schema](#nestedatt--script--apm_check)) -- `cloud_dial_check` (Attributes) cloud dial check (see [below for nested schema](#nestedatt--script--cloud_dial_check)) -- `logging_check` (Attributes) logging check (see [below for nested schema](#nestedatt--script--logging_check)) -- `mutations_check` (Attributes) mutations check (see [below for nested schema](#nestedatt--script--mutations_check)) -- `process_check` (Attributes) process check (see [below for nested schema](#nestedatt--script--process_check)) -- `range_check` (Attributes) range check (see [below for nested schema](#nestedatt--script--range_check)) -- `rum_check` (Attributes) RUM check (see [below for nested schema](#nestedatt--script--rum_check)) -- `security_check` (Attributes) security check (see [below for nested schema](#nestedatt--script--security_check)) -- `senior_check` (Attributes) senior check (see [below for nested schema](#nestedatt--script--senior_check)) -- `simple_check` (Attributes) simple check (see [below for nested schema](#nestedatt--script--simple_check)) -- `type` (String) check method type -- `water_level_check` (Attributes) water level check (see [below for nested schema](#nestedatt--script--water_level_check)) - - -### Nested Schema for `script.apm_check` - -Optional: - -- `checker` (Attributes) condition configuration for checking (see [below for nested schema](#nestedatt--script--apm_check--checker)) -- `every` (String) check frequency -- `interval` (Number) Query interval -- `message` (String) event message -- `name` (String) check item name -- `no_data_interval` (Number) no data interval -- `recover_need_period_count` (Number) recover need period count -- `targets` (Attributes List) targets for checking (see [below for nested schema](#nestedatt--script--apm_check--targets)) -- `title` (String) event title - - -### Nested Schema for `script.apm_check.checker` - -Optional: - -- `rules` (Attributes List) rules (see [below for nested schema](#nestedatt--script--apm_check--checker--rules)) - - -### Nested Schema for `script.apm_check.checker.rules` - -Optional: - -- `check_count` (Number) [water level/mutation parameter] continuous abnormal point number -- `check_percent` (Number) [interval parameter] abnormal percentage threshold -- `condition_logic` (String) condition logic -- `conditions` (Attributes List) conditions (see [below for nested schema](#nestedatt--script--apm_check--checker--rules--conditions)) -- `direction` (String) [interval/water level/mutation parameter] check direction -- `period_num` (Number) [interval/water level/mutation parameter] only check the latest data point number -- `status` (String) Fit the condition, the output event's status. The value is the same as the event's status -- `strength` (Number) [water level/mutation parameter] strength - - -### Nested Schema for `script.apm_check.checker.rules.conditions` - -Optional: - -- `alias` (String) alias of target -- `operands` (List of String) operands -- `operator` (String) operator - - - - - -### Nested Schema for `script.apm_check.targets` - -Optional: - -- `alias` (String) alias -- `dql` (String) dql - - - - -### Nested Schema for `script.cloud_dial_check` - -Optional: - -- `checker` (Attributes) condition configuration for checking (see [below for nested schema](#nestedatt--script--cloud_dial_check--checker)) -- `every` (String) check frequency -- `interval` (Number) Query interval -- `message` (String) event message -- `name` (String) check item name -- `no_data_interval` (Number) no data interval -- `recover_need_period_count` (Number) recover need period count -- `targets` (Attributes List) targets for checking (see [below for nested schema](#nestedatt--script--cloud_dial_check--targets)) -- `title` (String) event title - - -### Nested Schema for `script.cloud_dial_check.checker` - -Optional: - -- `rules` (Attributes List) rules (see [below for nested schema](#nestedatt--script--cloud_dial_check--checker--rules)) - - -### Nested Schema for `script.cloud_dial_check.checker.rules` - -Optional: - -- `check_count` (Number) [water level/mutation parameter] continuous abnormal point number -- `check_percent` (Number) [interval parameter] abnormal percentage threshold -- `condition_logic` (String) condition logic -- `conditions` (Attributes List) conditions (see [below for nested schema](#nestedatt--script--cloud_dial_check--checker--rules--conditions)) -- `direction` (String) [interval/water level/mutation parameter] check direction -- `period_num` (Number) [interval/water level/mutation parameter] only check the latest data point number -- `status` (String) Fit the condition, the output event's status. The value is the same as the event's status -- `strength` (Number) [water level/mutation parameter] strength - - -### Nested Schema for `script.cloud_dial_check.checker.rules.conditions` - -Optional: - -- `alias` (String) alias of target -- `operands` (List of String) operands -- `operator` (String) operator - - - - - -### Nested Schema for `script.cloud_dial_check.targets` - -Optional: - -- `alias` (String) alias -- `dql` (String) dql - - - - -### Nested Schema for `script.logging_check` - -Optional: - -- `checker` (Attributes) condition configuration for checking (see [below for nested schema](#nestedatt--script--logging_check--checker)) -- `every` (String) check frequency -- `interval` (Number) Query interval -- `message` (String) event message -- `name` (String) check item name -- `no_data_interval` (Number) no data interval -- `recover_need_period_count` (Number) recover need period count -- `targets` (Attributes List) targets for checking (see [below for nested schema](#nestedatt--script--logging_check--targets)) -- `title` (String) event title - - -### Nested Schema for `script.logging_check.checker` - -Optional: - -- `rules` (Attributes List) rules (see [below for nested schema](#nestedatt--script--logging_check--checker--rules)) - - -### Nested Schema for `script.logging_check.checker.rules` - -Optional: - -- `check_count` (Number) [water level/mutation parameter] continuous abnormal point number -- `check_percent` (Number) [interval parameter] abnormal percentage threshold -- `condition_logic` (String) condition logic -- `conditions` (Attributes List) conditions (see [below for nested schema](#nestedatt--script--logging_check--checker--rules--conditions)) -- `direction` (String) [interval/water level/mutation parameter] check direction -- `period_num` (Number) [interval/water level/mutation parameter] only check the latest data point number -- `status` (String) Fit the condition, the output event's status. The value is the same as the event's status -- `strength` (Number) [water level/mutation parameter] strength - - -### Nested Schema for `script.logging_check.checker.rules.conditions` - -Optional: - -- `alias` (String) alias of target -- `operands` (List of String) operands -- `operator` (String) operator - - - - - -### Nested Schema for `script.logging_check.targets` - -Optional: - -- `alias` (String) alias -- `dql` (String) dql - - - - -### Nested Schema for `script.mutations_check` - -Optional: - -- `checker` (Attributes) condition configuration for checking (see [below for nested schema](#nestedatt--script--mutations_check--checker)) -- `every` (String) check frequency -- `interval` (Number) Query interval -- `message` (String) event message -- `name` (String) check item name -- `no_data_interval` (Number) no data interval -- `recover_need_period_count` (Number) recover need period count -- `targets` (Attributes List) targets for checking (see [below for nested schema](#nestedatt--script--mutations_check--targets)) -- `title` (String) event title - - -### Nested Schema for `script.mutations_check.checker` - -Optional: - -- `rules` (Attributes List) rules (see [below for nested schema](#nestedatt--script--mutations_check--checker--rules)) - - -### Nested Schema for `script.mutations_check.checker.rules` - -Optional: - -- `check_count` (Number) [water level/mutation parameter] continuous abnormal point number -- `check_percent` (Number) [interval parameter] abnormal percentage threshold -- `condition_logic` (String) condition logic -- `conditions` (Attributes List) conditions (see [below for nested schema](#nestedatt--script--mutations_check--checker--rules--conditions)) -- `direction` (String) [interval/water level/mutation parameter] check direction -- `period_num` (Number) [interval/water level/mutation parameter] only check the latest data point number -- `status` (String) Fit the condition, the output event's status. The value is the same as the event's status -- `strength` (Number) [water level/mutation parameter] strength - - -### Nested Schema for `script.mutations_check.checker.rules.conditions` - -Optional: - -- `alias` (String) alias of target -- `operands` (List of String) operands -- `operator` (String) operator - - - - - -### Nested Schema for `script.mutations_check.targets` - -Optional: - -- `alias` (String) alias -- `dql` (String) dql - - - - -### Nested Schema for `script.process_check` - -Optional: - -- `checker` (Attributes) condition configuration for checking (see [below for nested schema](#nestedatt--script--process_check--checker)) -- `every` (String) check frequency -- `interval` (Number) Query interval -- `message` (String) event message -- `name` (String) check item name -- `no_data_interval` (Number) no data interval -- `recover_need_period_count` (Number) recover need period count -- `targets` (Attributes List) targets for checking (see [below for nested schema](#nestedatt--script--process_check--targets)) -- `title` (String) event title - - -### Nested Schema for `script.process_check.checker` - -Optional: - -- `rules` (Attributes List) rules (see [below for nested schema](#nestedatt--script--process_check--checker--rules)) - - -### Nested Schema for `script.process_check.checker.rules` - -Optional: - -- `check_count` (Number) [water level/mutation parameter] continuous abnormal point number -- `check_percent` (Number) [interval parameter] abnormal percentage threshold -- `condition_logic` (String) condition logic -- `conditions` (Attributes List) conditions (see [below for nested schema](#nestedatt--script--process_check--checker--rules--conditions)) -- `direction` (String) [interval/water level/mutation parameter] check direction -- `period_num` (Number) [interval/water level/mutation parameter] only check the latest data point number -- `status` (String) Fit the condition, the output event's status. The value is the same as the event's status -- `strength` (Number) [water level/mutation parameter] strength - - -### Nested Schema for `script.process_check.checker.rules.conditions` -Optional: - -- `alias` (String) alias of target -- `operands` (List of String) operands -- `operator` (String) operator - - - - - -### Nested Schema for `script.process_check.targets` - -Optional: - -- `alias` (String) alias -- `dql` (String) dql - - - - -### Nested Schema for `script.range_check` - -Optional: - -- `checker` (Attributes) condition configuration for checking (see [below for nested schema](#nestedatt--script--range_check--checker)) -- `every` (String) check frequency -- `interval` (Number) Query interval -- `message` (String) event message -- `name` (String) check item name -- `no_data_interval` (Number) no data interval -- `recover_need_period_count` (Number) recover need period count -- `targets` (Attributes List) targets for checking (see [below for nested schema](#nestedatt--script--range_check--targets)) -- `title` (String) event title - - -### Nested Schema for `script.range_check.checker` - -Optional: - -- `rules` (Attributes List) rules (see [below for nested schema](#nestedatt--script--range_check--checker--rules)) - - -### Nested Schema for `script.range_check.checker.rules` - -Optional: - -- `check_count` (Number) [water level/mutation parameter] continuous abnormal point number -- `check_percent` (Number) [interval parameter] abnormal percentage threshold -- `condition_logic` (String) condition logic -- `conditions` (Attributes List) conditions (see [below for nested schema](#nestedatt--script--range_check--checker--rules--conditions)) -- `direction` (String) [interval/water level/mutation parameter] check direction -- `period_num` (Number) [interval/water level/mutation parameter] only check the latest data point number -- `status` (String) Fit the condition, the output event's status. The value is the same as the event's status -- `strength` (Number) [water level/mutation parameter] strength - - -### Nested Schema for `script.range_check.checker.rules.conditions` - -Optional: - -- `alias` (String) alias of target -- `operands` (List of String) operands -- `operator` (String) operator - - - - - -### Nested Schema for `script.range_check.targets` - -Optional: - -- `alias` (String) alias -- `dql` (String) dql - - - - -### Nested Schema for `script.rum_check` - -Optional: - -- `checker` (Attributes) condition configuration for checking (see [below for nested schema](#nestedatt--script--rum_check--checker)) -- `every` (String) check frequency -- `interval` (Number) Query interval -- `message` (String) event message -- `name` (String) check item name -- `no_data_interval` (Number) no data interval -- `recover_need_period_count` (Number) recover need period count -- `targets` (Attributes List) targets for checking (see [below for nested schema](#nestedatt--script--rum_check--targets)) -- `title` (String) event title - - -### Nested Schema for `script.rum_check.checker` - -Optional: - -- `rules` (Attributes List) rules (see [below for nested schema](#nestedatt--script--rum_check--checker--rules)) - - -### Nested Schema for `script.rum_check.checker.rules` - -Optional: - -- `check_count` (Number) [water level/mutation parameter] continuous abnormal point number -- `check_percent` (Number) [interval parameter] abnormal percentage threshold -- `condition_logic` (String) condition logic -- `conditions` (Attributes List) conditions (see [below for nested schema](#nestedatt--script--rum_check--checker--rules--conditions)) -- `direction` (String) [interval/water level/mutation parameter] check direction -- `period_num` (Number) [interval/water level/mutation parameter] only check the latest data point number -- `status` (String) Fit the condition, the output event's status. The value is the same as the event's status -- `strength` (Number) [water level/mutation parameter] strength - - -### Nested Schema for `script.rum_check.checker.rules.conditions` - -Optional: - -- `alias` (String) alias of target -- `operands` (List of String) operands -- `operator` (String) operator - - - - - -### Nested Schema for `script.rum_check.targets` - -Optional: - -- `alias` (String) alias -- `dql` (String) dql - - - - -### Nested Schema for `script.security_check` - -Optional: - -- `checker` (Attributes) condition configuration for checking (see [below for nested schema](#nestedatt--script--security_check--checker)) -- `every` (String) check frequency -- `interval` (Number) Query interval -- `message` (String) event message -- `name` (String) check item name -- `no_data_interval` (Number) no data interval -- `recover_need_period_count` (Number) recover need period count -- `targets` (Attributes List) targets for checking (see [below for nested schema](#nestedatt--script--security_check--targets)) -- `title` (String) event title - - -### Nested Schema for `script.security_check.checker` - -Optional: - -- `rules` (Attributes List) rules (see [below for nested schema](#nestedatt--script--security_check--checker--rules)) - - -### Nested Schema for `script.security_check.checker.rules` - -Optional: - -- `check_count` (Number) [water level/mutation parameter] continuous abnormal point number -- `check_percent` (Number) [interval parameter] abnormal percentage threshold -- `condition_logic` (String) condition logic -- `conditions` (Attributes List) conditions (see [below for nested schema](#nestedatt--script--security_check--checker--rules--conditions)) -- `direction` (String) [interval/water level/mutation parameter] check direction -- `period_num` (Number) [interval/water level/mutation parameter] only check the latest data point number -- `status` (String) Fit the condition, the output event's status. The value is the same as the event's status -- `strength` (Number) [water level/mutation parameter] strength - - -### Nested Schema for `script.security_check.checker.rules.conditions` - -Optional: - -- `alias` (String) alias of target -- `operands` (List of String) operands -- `operator` (String) operator - - - - - -### Nested Schema for `script.security_check.targets` - -Optional: - -- `alias` (String) alias -- `dql` (String) dql - - - - -### Nested Schema for `script.senior_check` - -Required: - -- `check_funcs` (Attributes List) check functions (see [below for nested schema](#nestedatt--script--senior_check--check_funcs)) -- `every` (String) check frequency -- `message` (String) event message -- `name` (String) rule name -- `title` (String) event title -- `type` (String) rule type - - -### Nested Schema for `script.senior_check.check_funcs` - -Required: - -- `func_id` (String) function ID - -Optional: - -- `kwargs` (String) parameters - - - - -### Nested Schema for `script.simple_check` - -Optional: - -- `checker` (Attributes) condition configuration for checking (see [below for nested schema](#nestedatt--script--simple_check--checker)) -- `every` (String) check frequency -- `interval` (Number) Query interval -- `message` (String) event message -- `name` (String) check item name -- `no_data_interval` (Number) no data interval -- `recover_need_period_count` (Number) recover need period count -- `targets` (Attributes List) targets for checking (see [below for nested schema](#nestedatt--script--simple_check--targets)) -- `title` (String) event title - - -### Nested Schema for `script.simple_check.checker` - -Optional: - -- `rules` (Attributes List) rules (see [below for nested schema](#nestedatt--script--simple_check--checker--rules)) - - -### Nested Schema for `script.simple_check.checker.rules` - -Optional: - -- `check_count` (Number) [water level/mutation parameter] continuous abnormal point number -- `check_percent` (Number) [interval parameter] abnormal percentage threshold -- `condition_logic` (String) condition logic -- `conditions` (Attributes List) conditions (see [below for nested schema](#nestedatt--script--simple_check--checker--rules--conditions)) -- `direction` (String) [interval/water level/mutation parameter] check direction -- `period_num` (Number) [interval/water level/mutation parameter] only check the latest data point number -- `status` (String) Fit the condition, the output event's status. The value is the same as the event's status -- `strength` (Number) [water level/mutation parameter] strength - - -### Nested Schema for `script.simple_check.checker.rules.conditions` - -Optional: - -- `alias` (String) alias of target -- `operands` (List of String) operands -- `operator` (String) operator - - - - - -### Nested Schema for `script.simple_check.targets` - -Optional: +data "guance_members" "demo" { + filters = [ + { + name = "email" + values = [var.email] + } + ] +} -- `alias` (String) alias -- `dql` (String) dql +resource "guance_membergroup" "demo" { + name = "oac-demo" + member_ids = data.guance_members.demo.items[*].id +} +resource "guance_alertpolicy" "demo" { + name = "oac-demo" + silent_timeout = "1h" + + statuses = [ + "critical", + "error", + "warning", + "info", + "ok", + "nodata", + "nodata_ok", + "nodata_as_ok", + ] + + alert_targets = [ + { + type = "member_group" + member_group = { + id = guance_membergroup.demo.id + } + }, + ] +} +resource "guance_monitor" "demo" { + manifest = file("${path.module}/monitor.json") + alert_policy = { + id = guance_alertpolicy.demo.id + } +} +``` - -### Nested Schema for `script.water_level_check` -Optional: -- `checker` (Attributes) condition configuration for checking (see [below for nested schema](#nestedatt--script--water_level_check--checker)) -- `every` (String) check frequency -- `interval` (Number) Query interval -- `message` (String) event message -- `name` (String) check item name -- `no_data_interval` (Number) no data interval -- `recover_need_period_count` (Number) recover need period count -- `targets` (Attributes List) targets for checking (see [below for nested schema](#nestedatt--script--water_level_check--targets)) -- `title` (String) event title + +## Schema - -### Nested Schema for `script.water_level_check.checker` +### Required -Optional: +- `alert_policy` (Attributes) Alert Policy Configuration (see [below for nested schema](#nestedatt--alert_policy)) +- `manifest` (String) Monitor Configuration -- `rules` (Attributes List) rules (see [below for nested schema](#nestedatt--script--water_level_check--checker--rules)) +### Optional - -### Nested Schema for `script.water_level_check.checker.rules` +- `dashboard` (Attributes) Dashboard Configuration (see [below for nested schema](#nestedatt--dashboard)) -Optional: +### Read-Only -- `check_count` (Number) [water level/mutation parameter] continuous abnormal point number -- `check_percent` (Number) [interval parameter] abnormal percentage threshold -- `condition_logic` (String) condition logic -- `conditions` (Attributes List) conditions (see [below for nested schema](#nestedatt--script--water_level_check--checker--rules--conditions)) -- `direction` (String) [interval/water level/mutation parameter] check direction -- `period_num` (Number) [interval/water level/mutation parameter] only check the latest data point number -- `status` (String) Fit the condition, the output event's status. The value is the same as the event's status -- `strength` (Number) [water level/mutation parameter] strength +- `created_at` (String) The RFC3339/ISO8601 time string of resource created at. +- `id` (String) The Guance Resource Name (GRN) of cloud resource. - -### Nested Schema for `script.water_level_check.checker.rules.conditions` + +### Nested Schema for `alert_policy` Optional: -- `alias` (String) alias of target -- `operands` (List of String) operands -- `operator` (String) operator - - +- `id` (String) Alert Policy ID - -### Nested Schema for `script.water_level_check.targets` + +### Nested Schema for `dashboard` Optional: -- `alias` (String) alias -- `dql` (String) dql +- `id` (String) Dashboard ID diff --git a/docs/resources/mute.md b/docs/resources/mute.md index 805a426..e9e8b47 100644 --- a/docs/resources/mute.md +++ b/docs/resources/mute.md @@ -28,7 +28,7 @@ description: |- type = string } data "guance_members" "demo" { - filter = [ + filters = [ { name = "email" values = [var.email] @@ -131,7 +131,7 @@ description: |- } mute_tags = [ { - key = "host" + key = "host" value = "*" } ] @@ -176,7 +176,7 @@ variable "email" { } data "guance_members" "demo" { - filter = [ + filters = [ { name = "email" values = [var.email] @@ -287,10 +287,10 @@ resource "guance_mute" "demo" { week = "*" } } - + mute_tags = [ { - key = "host" + key = "host" value = "*" } ] @@ -313,15 +313,15 @@ resource "guance_mute" "demo" { ### Read-Only -- `created_at` (String) Timestamp of the last Terraform update of the order. -- `id` (String) Numeric identifier of the order. +- `created_at` (String) The RFC3339/ISO8601 time string of resource created at. +- `id` (String) The Guance Resource Name (GRN) of cloud resource. ### Nested Schema for `mute_ranges` Required: -- `type` (String) Mute Range Type +- `type` (String) Mute Range Type, value must be one of: *monitor*, *alert_policy*, other value will be ignored. Optional: @@ -368,7 +368,7 @@ Optional: Required: -- `type` (String) Notify Type +- `type` (String) Notify Type, value must be one of: *member_group*, *notification*, other value will be ignored. Optional: diff --git a/docs/resources/notification.md b/docs/resources/notification.md index 02fd780..cc7e7d0 100644 --- a/docs/resources/notification.md +++ b/docs/resources/notification.md @@ -83,7 +83,7 @@ resource "guance_notification" "demo" { ### Required - `name` (String) Notification object name -- `type` (String) Trigger rule type +- `type` (String) Trigger rule type, value must be one of: *ding_talk_robot*, *http_request*, *wechat_robot*, *mail_group*, *feishu_robot*, *sms*, other value will be ignored. ### Optional @@ -96,8 +96,8 @@ resource "guance_notification" "demo" { ### Read-Only -- `created_at` (String) Timestamp of the last Terraform update of the order. -- `id` (String) Numeric identifier of the order. +- `created_at` (String) The RFC3339/ISO8601 time string of resource created at. +- `id` (String) The Guance Resource Name (GRN) of cloud resource. ### Nested Schema for `ding_talk_robot` diff --git a/docs/resources/pipeline.md b/docs/resources/pipeline.md index a7fd281..432bc55 100644 --- a/docs/resources/pipeline.md +++ b/docs/resources/pipeline.md @@ -4,20 +4,22 @@ page_title: "guance_pipeline Resource - guance" subcategory: "" description: |- Pipeline - Pipeline is a data processing language that Observability Cloud provides. Pipeline supports text parsing of different formats of log data. + Pipeline is a data processing language that Observability Cloud provides. Pipeline supports text parsing of different + formats of log data. By writing a pipeline script, you can customize the structure of the log and use the cut fields as attributes. - By cutting out the attribute fields, we can quickly filter the relevant logs and perform data association analysis to help us quickly locate and solve problems. + By cutting out the attribute fields, we can quickly filter the relevant logs and perform data association analysis to + help us quickly locate and solve problems. Create The first let me create a resource. We will send the create operation to the resource management service ```terraform resource "guancepipeline" "demo" { - name = "oac-demo" + name = "oac-demo" category = "logging" - source = [ + source = [ "nginx" ] isdefault = false - is_force = false + is_force = false content = < B[Alert Policy] --> C[Notification] The first let me create a resource. We will send the create operation to the resource management service ```terraform +variable "email" { + type = string +} + +data "guance_members" "demo" { + filters = [ + { + name = "email" + values = [var.email] + } + ] +} + +resource "guance_membergroup" "demo" { + name = "oac-demo" + member_ids = data.guance_members.demo.items[*].id +} + +resource "guance_alertpolicy" "demo" { + name = "oac-demo" + silent_timeout = "1h" + + statuses = [ + "critical", + "error", + "warning", + "info", + "ok", + "nodata", + "nodata_ok", + "nodata_as_ok", + ] + + alert_targets = [ + { + type = "member_group" + member_group = { + id = guance_membergroup.demo.id + } + }, + ] +} + resource "guance_monitor" "demo" { - name = "oac-demo" + manifest = file("${path.module}/monitor.json") + alert_policy = { + id = guance_alertpolicy.demo.id + } } ``` diff --git a/examples/monitor/main.tf b/examples/monitor/main.tf index 34e8ddc..3fa9532 100644 --- a/examples/monitor/main.tf +++ b/examples/monitor/main.tf @@ -1,3 +1,49 @@ +variable "email" { + type = string +} + +data "guance_members" "demo" { + filters = [ + { + name = "email" + values = [var.email] + } + ] +} + +resource "guance_membergroup" "demo" { + name = "oac-demo" + member_ids = data.guance_members.demo.items[*].id +} + +resource "guance_alertpolicy" "demo" { + name = "oac-demo" + silent_timeout = "1h" + + statuses = [ + "critical", + "error", + "warning", + "info", + "ok", + "nodata", + "nodata_ok", + "nodata_as_ok", + ] + + alert_targets = [ + { + type = "member_group" + member_group = { + id = guance_membergroup.demo.id + } + }, + ] +} + resource "guance_monitor" "demo" { - name = "oac-demo" + manifest = file("${path.module}/monitor.json") + alert_policy = { + id = guance_alertpolicy.demo.id + } } diff --git a/examples/monitor/monitor.json b/examples/monitor/monitor.json new file mode 100644 index 0000000..ce3b431 --- /dev/null +++ b/examples/monitor/monitor.json @@ -0,0 +1,140 @@ +{ + "extend": { + "funcName": "", + "querylist": [ + { + "datasource": "dataflux", + "qtype": "dql", + "query": { + "children": [ + { + "alias": "", + "code": "A", + "dataSource": "aerospike", + "field": "namespace_memory_free_pct", + "fieldFunc": "last", + "fieldType": "float", + "groupBy": [ + "ns" + ], + "groupByTime": "", + "namespace": "metric", + "q": "M::`aerospike`:(LAST(`namespace_memory_free_pct`)) BY `ns`", + "type": "simple" + } + ], + "code": "Result", + "expression": "100-A", + "funcList": [], + "q": "eval(100-A, A=\"M::`aerospike`:(LAST(`namespace_memory_free_pct`)) BY `ns`\")", + "type": "expression" + }, + "uuid": "19cf2077-8b02-4e0e-b5f8-6a4af19b8ffc" + } + ], + "rules": [ + { + "conditionLogic": "and", + "conditions": [ + { + "alias": "Result", + "operands": [ + "85" + ], + "operator": ">=" + } + ], + "status": "critical" + }, + { + "conditionLogic": "and", + "conditions": [ + { + "alias": "Result", + "operands": [ + "80" + ], + "operator": ">=" + } + ], + "status": "error" + }, + { + "conditionLogic": "and", + "conditions": [ + { + "alias": "Result", + "operands": [ + "60" + ], + "operator": ">=" + } + ], + "status": "warning" + } + ] + }, + "is_disable": false, + "jsonScript": { + "checkerOpt": { + "rules": [ + { + "conditionLogic": "and", + "conditions": [ + { + "alias": "Result", + "operands": [ + "85" + ], + "operator": ">=" + } + ], + "status": "critical" + }, + { + "conditionLogic": "and", + "conditions": [ + { + "alias": "Result", + "operands": [ + "80" + ], + "operator": ">=" + } + ], + "status": "error" + }, + { + "conditionLogic": "and", + "conditions": [ + { + "alias": "Result", + "operands": [ + "60" + ], + "operator": ">=" + } + ], + "status": "warning" + } + ] + }, + "every": "1m", + "groupBy": [ + "ns" + ], + "interval": 300, + "message": ">等级:{{df_status}} \n>集群:{{cluster_name}} \n>空间:{{ns}} \n{% if df_status != 'ok' %}>状态:告警发生\n>内容:Aerospike 集群【{{cluster_name}}】 空间【 {{ ns }}】的 Memory 使用率过高,当前使用率为: {{ Result }} %。\n {% else %}>状态:告警恢复\n>内容:Aerospike 集群【{{cluster_name}}】 空间【 {{ ns }}】的 Memory 告警恢复,当前使用率为: {{ Result }} %。\n{% endif %}", + "recoverNeedPeriodCount": 5, + "targets": [ + { + "alias": "Result", + "dql": "eval(100-A, A=\"M::`aerospike`:(LAST(`namespace_memory_free_pct`)) BY `ns`\")" + } + ], + "title": "Aerospike 集群【{{cluster_name}}】空间【{{ ns }}】 的 Memory 使用率过高", + "type": "simpleCheck" + }, + "monitorName": "默认分组" +} + diff --git a/examples/mute/.terraform.lock.hcl b/examples/mute/.terraform.lock.hcl new file mode 100644 index 0000000..590bf60 --- /dev/null +++ b/examples/mute/.terraform.lock.hcl @@ -0,0 +1,24 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/guancecloud/guance" { + version = "0.0.3" + hashes = [ + "h1:ktsr/yAbJ0smNKxFo541ICG30yi57oiiVO7shzN6iiE=", + "zh:0b5cce1ce6178851af1210cdd59db4ac244dcd9f43fa22dd84e9738779a4e5c9", + "zh:0fb228b88c3d5de5b9a86697e36411df2339e2995a495287cbcae06f785e5024", + "zh:2805245d5c113146b450c99c9044e9c6262557c5610438e2c4bc608805a0a99b", + "zh:4428b5b09cbf3d3ac5a131f52e41914a3c7e6034a3c3a62b5992a12f5ac7dbd6", + "zh:4930d1af6f288099306f1603f612bda272ae19c0ea55f6b5f3865d415e1e66db", + "zh:5e151c456aa0f6f8e6ad39799ec116e96d4c61227e40cb6a43e5ff06a5e641f5", + "zh:6d4c1d64fc1cc0cfac68197193f806f5c51e2630023ce29514279475499d5de3", + "zh:6dfc5c6d2a89a6ca3e760d2cca269a2d92a2b6a00f615573716bf5b0aa4c12d0", + "zh:791430b33ba76bef79b185eec55a603b54015942971efc645fce6ba4435f8823", + "zh:890df766e9b839623b1f0437355032a3c006226a6c200cd911e15ee1a9014e9f", + "zh:949e331f05c15fc5469e9334d05598a26a580e32b83b2bf5a5478c42dc21eea5", + "zh:9902a214c1f27effb813221fc793c804958a5a7d35f6def68b3f34e31a7a9a29", + "zh:b72f74aff05da1086bb79fa68e8071f0f154e6a092f44c0d784919183e14f9f1", + "zh:dd26785f6d8a5913351c2906e236156bbbd54a514dbb9b1c0c2356546432418d", + "zh:f7453f2db7bfdb2be9619dbaf63f38de228e939022a68ad75aef2ab71b4106da", + ] +} diff --git a/examples/mute/README.md b/examples/mute/README.md index da36df4..636a14f 100644 --- a/examples/mute/README.md +++ b/examples/mute/README.md @@ -33,7 +33,7 @@ variable "email" { } data "guance_members" "demo" { - filter = [ + filters = [ { name = "email" values = [var.email] @@ -144,10 +144,10 @@ resource "guance_mute" "demo" { week = "*" } } - + mute_tags = [ { - key = "host" + key = "host" value = "*" } ] diff --git a/examples/mute/main.tf b/examples/mute/main.tf index d1a2c63..191121a 100644 --- a/examples/mute/main.tf +++ b/examples/mute/main.tf @@ -11,7 +11,7 @@ variable "email" { } data "guance_members" "demo" { - filter = [ + filters = [ { name = "email" values = [var.email] @@ -122,10 +122,10 @@ resource "guance_mute" "demo" { week = "*" } } - + mute_tags = [ { - key = "host" + key = "host" value = "*" } ] diff --git a/examples/pipeline/README.md b/examples/pipeline/README.md index c358dd4..4948cb9 100644 --- a/examples/pipeline/README.md +++ b/examples/pipeline/README.md @@ -1,10 +1,12 @@ # Pipeline -Pipeline is a data processing language that Observability Cloud provides. Pipeline supports text parsing of different formats of log data. +Pipeline is a data processing language that Observability Cloud provides. Pipeline supports text parsing of different +formats of log data. By writing a pipeline script, you can customize the structure of the log and use the cut fields as attributes. -By cutting out the attribute fields, we can quickly filter the relevant logs and perform data association analysis to help us quickly locate and solve problems. +By cutting out the attribute fields, we can quickly filter the relevant logs and perform data association analysis to +help us quickly locate and solve problems. ## Create @@ -12,13 +14,13 @@ The first let me create a resource. We will send the create operation to the res ```terraform resource "guance_pipeline" "demo" { - name = "oac-demo" + name = "oac-demo" category = "logging" - source = [ + source = [ "nginx" ] is_default = false - is_force = false + is_force = false content = < +func NewBlackListResource() resource.Resource { + return &blackListResource{} +} + +// blackListResource is the resource implementation. +type blackListResource struct { + client *sdk.Client[sdk.Resource] +} + +// Schema defines the schema for the data source. +func (r *blackListResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = resourceSchema +} + +// Configure adds the provider configured client to the data source. +func (r *blackListResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + r.client = req.ProviderData.(*sdk.Client[sdk.Resource]) +} + +// Metadata returns the data source type name. +func (r *blackListResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_blacklist" +} + +// Create creates the resource and sets the initial Terraform state. +func (r *blackListResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + // Retrieve values from plan + var plan blackListResourceModel + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + if err := r.client.Create(ctx, &plan); err != nil { + resp.Diagnostics.AddError( + "Error creating blackList", + "Could not create blackList, unexpected error: "+err.Error(), + ) + return + } + + if err := r.client.Read(ctx, &plan); err != nil { + resp.Diagnostics.AddError( + "Error creating blackList", + "Could not create blackList, unexpected error: "+err.Error(), + ) + return + } + + // Set state to fully populated data + diags = resp.State.Set(ctx, plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +// Read refreshes the Terraform state with the latest data. +func (r *blackListResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + // Get current state + var state blackListResourceModel + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + if err := r.client.Read(ctx, &state); err != nil { + resp.Diagnostics.AddError( + "Error reading blackList", + "Could not read blackList, unexpected error: "+err.Error(), + ) + return + } + + // Set refreshed state + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +// Update updates the resource and sets the updated Terraform state on success. +func (r *blackListResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + // Retrieve values from plan + var plan blackListResourceModel + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + if err := r.client.Read(ctx, &plan); err != nil { + resp.Diagnostics.AddError( + "Error creating blackList", + "Could not create blackList, unexpected error: "+err.Error(), + ) + return + } + + // Set state to fully populated data + diags = resp.State.Set(ctx, plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +// Delete deletes the resource and removes the Terraform state on success. +func (r *blackListResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + // Retrieve values from state + var state blackListResourceModel + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // Delete existing blackList + if err := r.client.Delete(ctx, &state); err != nil { + resp.Diagnostics.AddError( + "Error deleting blackList", + "Could not delete blackList, unexpected error: "+err.Error(), + ) + return + } +} + +func (r *blackListResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + // Retrieve import ID and save to id attribute + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} diff --git a/internal/resources/blacklist/schema.go b/internal/resources/blacklist/schema.go new file mode 100644 index 0000000..c3cdcfb --- /dev/null +++ b/internal/resources/blacklist/schema.go @@ -0,0 +1,121 @@ +// Code generated by Guance Cloud Code Generation Pipeline. DO NOT EDIT. + +package blacklist + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +var resourceSchema = schema.Schema{ + Description: "BlackList", + MarkdownDescription: resourceDocument, + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Description: "The Guance Resource Name (GRN) of cloud resource.", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + + "created_at": schema.StringAttribute{ + Description: "The RFC3339/ISO8601 time string of resource created at.", + Computed: true, + }, + + "source": schema.SingleNestedAttribute{ + Description: "Source", + + Required: true, + Attributes: schemaSource, + }, + + "filter_rules": schema.ListNestedAttribute{ + Description: "Filters", + + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: schemaFilter, + }, + }, + }, +} + +// schemaFilter maps the resource schema data. +var schemaFilter = map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Description: "Name", + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + + "operation": schema.StringAttribute{ + Description: "Operation", + + MarkdownDescription: ` + Operation, value must be one of: *in*, *not in*, *match*, *not match*, other value will be ignored. + `, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("in", "not in", "match", "not match"), + }, + }, + + "condition": schema.StringAttribute{ + Description: "Condition, represented by DQL", + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + + "values": schema.ListAttribute{ + Description: "Values", + + Optional: true, + ElementType: types.StringType, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, + }, +} + +// schemaSource maps the resource schema data. +var schemaSource = map[string]schema.Attribute{ + "type": schema.StringAttribute{ + Description: "Source Type", + + MarkdownDescription: ` + Source Type, value must be one of: *logging*, *object*, *custom_object*, *network*, *tracing*, *rum*, *security*, *keyevent*, *metric*, other value will be ignored. + `, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("logging", "object", "custom_object", "network", "tracing", "rum", "security", "keyevent", "metric"), + }, + }, + + "name": schema.StringAttribute{ + Description: "Source", + + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, +} diff --git a/internal/resources/dashboard/README.md b/internal/resources/dashboard/README.md index 381a229..476445b 100644 --- a/internal/resources/dashboard/README.md +++ b/internal/resources/dashboard/README.md @@ -1,12 +1,15 @@ # Dashboard -**WORKING IN PROGRESS** +A dashboard is a collection of visualizations that you can use to monitor the health of your systems and applications. +Dashboards are made up of one or more panels, which are the visualizations themselves. Each panel displays a single +metric or a single aggregation of metrics. -A dashboard is a collection of visualizations that you can use to monitor the health of your systems and applications. Dashboards are made up of one or more panels, which are the visualizations themselves. Each panel displays a single metric or a single aggregation of metrics. +Dashboards are a great way to visualize your data and monitor your systems. You can use them to track metrics over time, +and to quickly see how your systems are performing. You can also use them to compare metrics from different systems and +applications. -Dashboards are a great way to visualize your data and monitor your systems. You can use them to track metrics over time, and to quickly see how your systems are performing. You can also use them to compare metrics from different systems and applications. - -Guance Cloud's dashboard is used to clearly show the range in which the metric data values are located. It is suitable for slicing messy data into points. +Guance Cloud's dashboard is used to clearly show the range in which the metric data values are located. It is suitable +for slicing messy data into points. ## Create @@ -14,6 +17,7 @@ The first let me create a resource. We will send the create operation to the res ```terraform resource "guance_dashboard" "demo" { - name = "oac-demo" + name = "oac-demo" + manifest = file("${path.module}/dashboard.json") } ``` diff --git a/internal/resources/dashboard/model.go b/internal/resources/dashboard/model.go index c5fe6e6..4a8af1f 100644 --- a/internal/resources/dashboard/model.go +++ b/internal/resources/dashboard/model.go @@ -10,13 +10,10 @@ import ( // dashboardResourceModel maps the resource schema data. type dashboardResourceModel struct { - ID types.String `tfsdk:"id"` - CreatedAt types.String `tfsdk:"created_at"` - Name types.String `tfsdk:"name"` - Extend types.String `tfsdk:"extend"` - Mapping []*Mapping `tfsdk:"mapping"` - Tags []types.String `tfsdk:"tags"` - Template *Template `tfsdk:"template"` + ID types.String `tfsdk:"id"` + CreatedAt types.String `tfsdk:"created_at"` + Name types.String `tfsdk:"name"` + Manifest types.String `tfsdk:"manifest"` } // GetId returns the ID of the resource. @@ -38,92 +35,3 @@ func (m *dashboardResourceModel) GetResourceType() string { func (m *dashboardResourceModel) SetCreatedAt(t string) { m.CreatedAt = types.StringValue(t) } - -// Chart maps the resource schema data. -type Chart struct { - Name types.String `tfsdk:"name"` - Type types.String `tfsdk:"type"` - Group types.String `tfsdk:"group"` - Pos *ChartPos `tfsdk:"pos"` - Queries []*ChartQuery `tfsdk:"queries"` -} - -// ChartPos maps the resource schema data. -type ChartPos struct { - I types.String `tfsdk:"i"` - X types.Int64 `tfsdk:"x"` - Y types.Int64 `tfsdk:"y"` - W types.Int64 `tfsdk:"w"` - H types.Int64 `tfsdk:"h"` -} - -// ChartQuery maps the resource schema data. -type ChartQuery struct { - Checked types.Bool `tfsdk:"checked"` - Datasource types.String `tfsdk:"datasource"` - Qtype types.String `tfsdk:"qtype"` - Query *Query `tfsdk:"query"` - Unit types.String `tfsdk:"unit"` -} - -// IconSet maps the resource schema data. -type IconSet struct { - Sm types.String `tfsdk:"sm"` - Md types.String `tfsdk:"md"` -} - -// Main maps the resource schema data. -type Main struct { - Type types.String `tfsdk:"type"` - Vars []*Var `tfsdk:"vars"` - Groups []types.String `tfsdk:"groups"` - Charts []*Chart `tfsdk:"charts"` -} - -// Mapping maps the resource schema data. -type Mapping struct { - Class types.String `tfsdk:"class"` - Field types.String `tfsdk:"field"` - Mapping types.String `tfsdk:"mapping"` - Datasource types.String `tfsdk:"datasource"` -} - -// Query maps the resource schema data. -type Query struct { - Density types.String `tfsdk:"density"` - Filter []*QueryFilter `tfsdk:"filter"` - GroupBy types.String `tfsdk:"group_by"` - GroupByTime types.String `tfsdk:"group_by_time"` - Q types.String `tfsdk:"q"` -} - -// QueryFilter maps the resource schema data. -type QueryFilter struct { - Logic types.String `tfsdk:"logic"` - Name types.String `tfsdk:"name"` - Op types.String `tfsdk:"op"` - Value types.String `tfsdk:"value"` -} - -// Template maps the resource schema data. -type Template struct { - Title types.String `tfsdk:"title"` - Summary types.String `tfsdk:"summary"` - Dashboard *TemplateDashboard `tfsdk:"dashboard"` - IconSet *IconSet `tfsdk:"icon_set"` - Main *Main `tfsdk:"main"` -} - -// TemplateDashboard maps the resource schema data. -type TemplateDashboard struct { - Extend types.String `tfsdk:"extend"` - Mapping []*Mapping `tfsdk:"mapping"` -} - -// Var maps the resource schema data. -type Var struct { - Name types.String `tfsdk:"name"` - Type types.String `tfsdk:"type"` - Value types.String `tfsdk:"value"` - Label types.String `tfsdk:"label"` -} diff --git a/internal/resources/dashboard/schema.go b/internal/resources/dashboard/schema.go index d44a04a..d1c564e 100644 --- a/internal/resources/dashboard/schema.go +++ b/internal/resources/dashboard/schema.go @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" - "github.com/hashicorp/terraform-plugin-framework/types" ) var resourceSchema = schema.Schema{ @@ -14,7 +13,7 @@ var resourceSchema = schema.Schema{ MarkdownDescription: resourceDocument, Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ - Description: "Numeric identifier of the order.", + Description: "The Guance Resource Name (GRN) of cloud resource.", Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -22,337 +21,26 @@ var resourceSchema = schema.Schema{ }, "created_at": schema.StringAttribute{ - Description: "Timestamp of the last Terraform update of the order.", + Description: "The RFC3339/ISO8601 time string of resource created at.", Computed: true, }, "name": schema.StringAttribute{ Description: "Dashboard Name", - Required: true, - }, - - "extend": schema.StringAttribute{ - Description: "Dashboard Extend", - - Optional: true, - }, - - "mapping": schema.ListNestedAttribute{ - Description: "Dashboard Mapping", - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaMapping, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, - "tags": schema.ListAttribute{ - Description: "Dashboard Tag Names", - - Optional: true, - ElementType: types.StringType, - }, - - "template": schema.SingleNestedAttribute{ - Description: "Dashboard Template Info", - - Optional: true, - Attributes: schemaTemplate, - }, - }, -} - -// schemaChart maps the resource schema data. -var schemaChart = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "Chart Name", - Required: true, - }, - - "type": schema.StringAttribute{ - Description: "Chart Type", - Required: true, - }, - - "group": schema.StringAttribute{ - Description: "Chart Group", - - Optional: true, - }, - - "pos": schema.SingleNestedAttribute{ - Description: "Chart Position Info", - - Optional: true, - Attributes: schemaChartPos, - }, - - "queries": schema.ListNestedAttribute{ - Description: "Chart Query Info", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaChartQuery, - }, - }, -} - -// schemaChartPos maps the resource schema data. -var schemaChartPos = map[string]schema.Attribute{ - "i": schema.StringAttribute{ - Description: "TODO: What is i?", - Required: true, - }, - - "x": schema.Int64Attribute{ - Description: "Chart X", - Required: true, - }, - - "y": schema.Int64Attribute{ - Description: "Chart Y", - Required: true, - }, - - "w": schema.Int64Attribute{ - Description: "Chart Width", - Required: true, - }, - - "h": schema.Int64Attribute{ - Description: "Chart Height", - Required: true, - }, -} - -// schemaChartQuery maps the resource schema data. -var schemaChartQuery = map[string]schema.Attribute{ - "checked": schema.BoolAttribute{ - Description: "Checked", - Required: true, - }, - - "datasource": schema.StringAttribute{ - Description: "Datasource", - Required: true, - }, - - "qtype": schema.StringAttribute{ - Description: "Query Type", - Required: true, - }, - - "query": schema.SingleNestedAttribute{ - Description: "Query", - Required: true, - Attributes: schemaQuery, - }, - - "unit": schema.StringAttribute{ - Description: "Unit", - - Optional: true, - }, -} - -// schemaIconSet maps the resource schema data. -var schemaIconSet = map[string]schema.Attribute{ - "sm": schema.StringAttribute{ - Description: "Small Icon", - - Optional: true, - }, - - "md": schema.StringAttribute{ - Description: "Middle Icon", - - Optional: true, - }, -} - -// schemaMain maps the resource schema data. -var schemaMain = map[string]schema.Attribute{ - "type": schema.StringAttribute{ - Description: "Dashboard Type", - Required: true, - }, - - "vars": schema.ListNestedAttribute{ - Description: "Dashboard Vars", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaVar, - }, - }, - - "groups": schema.ListAttribute{ - Description: "Dashboard Groups", - - Optional: true, - ElementType: types.StringType, - }, + "manifest": schema.StringAttribute{ + Description: "Dashboard Manifest", - "charts": schema.ListNestedAttribute{ - Description: "Dashboard Charts", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaChart, - }, - }, -} - -// schemaMapping maps the resource schema data. -var schemaMapping = map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Description: "Class Name", - Required: true, - }, - - "field": schema.StringAttribute{ - Description: "Field Name", - Required: true, - }, - - "mapping": schema.StringAttribute{ - Description: "Mapping Field Name", - Required: true, - }, - - "datasource": schema.StringAttribute{ - Description: "Data Source", - Required: true, - }, -} - -// schemaQuery maps the resource schema data. -var schemaQuery = map[string]schema.Attribute{ - "density": schema.StringAttribute{ - Description: "Density", - Required: true, - }, - - "filter": schema.ListNestedAttribute{ - Description: "Filter", - Required: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaQueryFilter, - }, - }, - - "group_by": schema.StringAttribute{ - Description: "Group By", - Required: true, - }, - - "group_by_time": schema.StringAttribute{ - Description: "Group By Time", - Required: true, - }, - - "q": schema.StringAttribute{ - Description: "Query", - Required: true, - }, -} - -// schemaQueryFilter maps the resource schema data. -var schemaQueryFilter = map[string]schema.Attribute{ - "logic": schema.StringAttribute{ - Description: "Logic", - Required: true, - }, - - "name": schema.StringAttribute{ - Description: "Field Name", - Required: true, - }, - - "op": schema.StringAttribute{ - Description: "Operator", - Required: true, - }, - - "value": schema.StringAttribute{ - Description: "Value", - Required: true, - }, -} - -// schemaTemplate maps the resource schema data. -var schemaTemplate = map[string]schema.Attribute{ - "title": schema.StringAttribute{ - Description: "Dashboard Title", - Required: true, - }, - - "summary": schema.StringAttribute{ - Description: "Dashboard Summary", - - Optional: true, - }, - - "dashboard": schema.SingleNestedAttribute{ - Description: "Dashboard Info", - - Optional: true, - Attributes: schemaTemplateDashboard, - }, - - "icon_set": schema.SingleNestedAttribute{ - Description: "Dashboard Icon Set", - - Optional: true, - Attributes: schemaIconSet, - }, - - "main": schema.SingleNestedAttribute{ - Description: "Dashboard Main", - - Optional: true, - Attributes: schemaMain, - }, -} - -// schemaTemplateDashboard maps the resource schema data. -var schemaTemplateDashboard = map[string]schema.Attribute{ - "extend": schema.StringAttribute{ - Description: "Dashboard Extend", - - Optional: true, - }, - - "mapping": schema.ListNestedAttribute{ - Description: "Dashboard Mapping", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaMapping, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, } - -// schemaVar maps the resource schema data. -var schemaVar = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "Var Name", - Required: true, - }, - - "type": schema.StringAttribute{ - Description: "Var Type", - Required: true, - }, - - "value": schema.StringAttribute{ - Description: "Var Value", - Required: true, - }, - - "label": schema.StringAttribute{ - Description: "Var Label", - - Optional: true, - }, -} diff --git a/internal/resources/membergroup/README.md b/internal/resources/membergroup/README.md index 6b9adb3..681a2d5 100644 --- a/internal/resources/membergroup/README.md +++ b/internal/resources/membergroup/README.md @@ -25,7 +25,7 @@ variable "email" { } data "guance_members" "demo" { - filter = [ + filters = [ { name = "email" values = [var.email] diff --git a/internal/resources/membergroup/schema.go b/internal/resources/membergroup/schema.go index 5d8be6d..20b7185 100644 --- a/internal/resources/membergroup/schema.go +++ b/internal/resources/membergroup/schema.go @@ -4,6 +4,7 @@ package membergroup import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" @@ -14,7 +15,7 @@ var resourceSchema = schema.Schema{ MarkdownDescription: resourceDocument, Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ - Description: "Numeric identifier of the order.", + Description: "The Guance Resource Name (GRN) of cloud resource.", Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -22,13 +23,17 @@ var resourceSchema = schema.Schema{ }, "created_at": schema.StringAttribute{ - Description: "Timestamp of the last Terraform update of the order.", + Description: "The RFC3339/ISO8601 time string of resource created at.", Computed: true, }, "name": schema.StringAttribute{ Description: "Name", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "member_ids": schema.ListAttribute{ @@ -36,6 +41,9 @@ var resourceSchema = schema.Schema{ Optional: true, ElementType: types.StringType, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, }, }, } diff --git a/internal/resources/monitor/README.md b/internal/resources/monitor/README.md index f8135f2..d487d5b 100644 --- a/internal/resources/monitor/README.md +++ b/internal/resources/monitor/README.md @@ -1,12 +1,15 @@ # Monitor -**WORKING IN PROGRESS** +A monitor is a set of checks that you can run against your data. A monitor watches your data over time and alerts you +when certain conditions are met. For example, you can create a monitor that watches the average response time of your +website and alerts you when the response time is greater than 1 second. -A monitor is a set of checks that you can run against your data. A monitor watches your data over time and alerts you when certain conditions are met. For example, you can create a monitor that watches the average response time of your website and alerts you when the response time is greater than 1 second. +Monitors are made up of one or more checks. A check is a single test that you can run against your data. For example, +you can create a check that watches the average response time of your website. You can also create a check that watches +the percentage of 5xx errors in your logs. -Monitors are made up of one or more checks. A check is a single test that you can run against your data. For example, you can create a check that watches the average response time of your website. You can also create a check that watches the percentage of 5xx errors in your logs. - -Guance Cloud supports defining monitors, users can customize the configuration of detection rules and trigger conditions, and open the monitors to receive related alarm events triggered by the detection rules. +Guance Cloud supports defining monitors, users can customize the configuration of detection rules and trigger +conditions, and open the monitors to receive related alarm events triggered by the detection rules. Relationships: @@ -21,7 +24,53 @@ A[Monitor] --> B[Alert Policy] --> C[Notification] The first let me create a resource. We will send the create operation to the resource management service ```terraform +variable "email" { + type = string +} + +data "guance_members" "demo" { + filters = [ + { + name = "email" + values = [var.email] + } + ] +} + +resource "guance_membergroup" "demo" { + name = "oac-demo" + member_ids = data.guance_members.demo.items[*].id +} + +resource "guance_alertpolicy" "demo" { + name = "oac-demo" + silent_timeout = "1h" + + statuses = [ + "critical", + "error", + "warning", + "info", + "ok", + "nodata", + "nodata_ok", + "nodata_as_ok", + ] + + alert_targets = [ + { + type = "member_group" + member_group = { + id = guance_membergroup.demo.id + } + }, + ] +} + resource "guance_monitor" "demo" { - name = "oac-demo" + manifest = file("${path.module}/monitor.json") + alert_policy = { + id = guance_alertpolicy.demo.id + } } ``` diff --git a/internal/resources/monitor/model.go b/internal/resources/monitor/model.go index becc431..3f0a04c 100644 --- a/internal/resources/monitor/model.go +++ b/internal/resources/monitor/model.go @@ -10,10 +10,11 @@ import ( // monitorResourceModel maps the resource schema data. type monitorResourceModel struct { - ID types.String `tfsdk:"id"` - CreatedAt types.String `tfsdk:"created_at"` - DashboardId types.String `tfsdk:"dashboard_id"` - Script *MonitorScript `tfsdk:"script"` + ID types.String `tfsdk:"id"` + CreatedAt types.String `tfsdk:"created_at"` + Manifest types.String `tfsdk:"manifest"` + AlertPolicy *AlertPolicy `tfsdk:"alert_policy"` + Dashboard *Dashboard `tfsdk:"dashboard"` } // GetId returns the ID of the resource. @@ -36,194 +37,12 @@ func (m *monitorResourceModel) SetCreatedAt(t string) { m.CreatedAt = types.StringValue(t) } -// APMCheck maps the resource schema data. -type APMCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Every types.String `tfsdk:"every"` - Interval types.Int64 `tfsdk:"interval"` - RecoverNeedPeriodCount types.Int64 `tfsdk:"recover_need_period_count"` - NoDataInterval types.Int64 `tfsdk:"no_data_interval"` - Targets []*Target `tfsdk:"targets"` - Checker *Checker `tfsdk:"checker"` +// AlertPolicy maps the resource schema data. +type AlertPolicy struct { + Id types.String `tfsdk:"id"` } -// CheckFunc maps the resource schema data. -type CheckFunc struct { - FuncId types.String `tfsdk:"func_id"` - Kwargs types.String `tfsdk:"kwargs"` -} - -// Checker maps the resource schema data. -type Checker struct { - Rules []*Rule `tfsdk:"rules"` -} - -// CloudDialCheck maps the resource schema data. -type CloudDialCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Every types.String `tfsdk:"every"` - Interval types.Int64 `tfsdk:"interval"` - RecoverNeedPeriodCount types.Int64 `tfsdk:"recover_need_period_count"` - NoDataInterval types.Int64 `tfsdk:"no_data_interval"` - Targets []*Target `tfsdk:"targets"` - Checker *Checker `tfsdk:"checker"` -} - -// Condition maps the resource schema data. -type Condition struct { - Alias types.String `tfsdk:"alias"` - Operator types.String `tfsdk:"operator"` - Operands []types.String `tfsdk:"operands"` -} - -// LoggingCheck maps the resource schema data. -type LoggingCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Every types.String `tfsdk:"every"` - Interval types.Int64 `tfsdk:"interval"` - RecoverNeedPeriodCount types.Int64 `tfsdk:"recover_need_period_count"` - NoDataInterval types.Int64 `tfsdk:"no_data_interval"` - Targets []*Target `tfsdk:"targets"` - Checker *Checker `tfsdk:"checker"` -} - -// MonitorScript maps the resource schema data. -type MonitorScript struct { - Type types.String `tfsdk:"type"` - SimpleCheck *SimpleCheck `tfsdk:"simple_check"` - SeniorCheck *SeniorCheck `tfsdk:"senior_check"` - LoggingCheck *LoggingCheck `tfsdk:"logging_check"` - MutationsCheck *MutationsCheck `tfsdk:"mutations_check"` - WaterLevelCheck *WaterLevelCheck `tfsdk:"water_level_check"` - RangeCheck *RangeCheck `tfsdk:"range_check"` - SecurityCheck *SecurityCheck `tfsdk:"security_check"` - ApmCheck *APMCheck `tfsdk:"apm_check"` - RumCheck *RUMCheck `tfsdk:"rum_check"` - ProcessCheck *ProcessCheck `tfsdk:"process_check"` - CloudDialCheck *CloudDialCheck `tfsdk:"cloud_dial_check"` -} - -// MutationsCheck maps the resource schema data. -type MutationsCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Every types.String `tfsdk:"every"` - Interval types.Int64 `tfsdk:"interval"` - RecoverNeedPeriodCount types.Int64 `tfsdk:"recover_need_period_count"` - NoDataInterval types.Int64 `tfsdk:"no_data_interval"` - Targets []*Target `tfsdk:"targets"` - Checker *Checker `tfsdk:"checker"` -} - -// ProcessCheck maps the resource schema data. -type ProcessCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Every types.String `tfsdk:"every"` - Interval types.Int64 `tfsdk:"interval"` - RecoverNeedPeriodCount types.Int64 `tfsdk:"recover_need_period_count"` - NoDataInterval types.Int64 `tfsdk:"no_data_interval"` - Targets []*Target `tfsdk:"targets"` - Checker *Checker `tfsdk:"checker"` -} - -// RUMCheck maps the resource schema data. -type RUMCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Every types.String `tfsdk:"every"` - Interval types.Int64 `tfsdk:"interval"` - RecoverNeedPeriodCount types.Int64 `tfsdk:"recover_need_period_count"` - NoDataInterval types.Int64 `tfsdk:"no_data_interval"` - Targets []*Target `tfsdk:"targets"` - Checker *Checker `tfsdk:"checker"` -} - -// RangeCheck maps the resource schema data. -type RangeCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Every types.String `tfsdk:"every"` - Interval types.Int64 `tfsdk:"interval"` - RecoverNeedPeriodCount types.Int64 `tfsdk:"recover_need_period_count"` - NoDataInterval types.Int64 `tfsdk:"no_data_interval"` - Targets []*Target `tfsdk:"targets"` - Checker *Checker `tfsdk:"checker"` -} - -// Rule maps the resource schema data. -type Rule struct { - Conditions []*Condition `tfsdk:"conditions"` - ConditionLogic types.String `tfsdk:"condition_logic"` - Status types.String `tfsdk:"status"` - Direction types.String `tfsdk:"direction"` - PeriodNum types.Int64 `tfsdk:"period_num"` - CheckPercent types.Int64 `tfsdk:"check_percent"` - CheckCount types.Int64 `tfsdk:"check_count"` - Strength types.Int64 `tfsdk:"strength"` -} - -// SecurityCheck maps the resource schema data. -type SecurityCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Every types.String `tfsdk:"every"` - Interval types.Int64 `tfsdk:"interval"` - RecoverNeedPeriodCount types.Int64 `tfsdk:"recover_need_period_count"` - NoDataInterval types.Int64 `tfsdk:"no_data_interval"` - Targets []*Target `tfsdk:"targets"` - Checker *Checker `tfsdk:"checker"` -} - -// SeniorCheck maps the resource schema data. -type SeniorCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Type types.String `tfsdk:"type"` - Every types.String `tfsdk:"every"` - CheckFuncs []*CheckFunc `tfsdk:"check_funcs"` -} - -// SimpleCheck maps the resource schema data. -type SimpleCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Every types.String `tfsdk:"every"` - Interval types.Int64 `tfsdk:"interval"` - RecoverNeedPeriodCount types.Int64 `tfsdk:"recover_need_period_count"` - NoDataInterval types.Int64 `tfsdk:"no_data_interval"` - Targets []*Target `tfsdk:"targets"` - Checker *Checker `tfsdk:"checker"` -} - -// Target maps the resource schema data. -type Target struct { - Alias types.String `tfsdk:"alias"` - Dql types.String `tfsdk:"dql"` -} - -// WaterLevelCheck maps the resource schema data. -type WaterLevelCheck struct { - Name types.String `tfsdk:"name"` - Title types.String `tfsdk:"title"` - Message types.String `tfsdk:"message"` - Every types.String `tfsdk:"every"` - Interval types.Int64 `tfsdk:"interval"` - RecoverNeedPeriodCount types.Int64 `tfsdk:"recover_need_period_count"` - NoDataInterval types.Int64 `tfsdk:"no_data_interval"` - Targets []*Target `tfsdk:"targets"` - Checker *Checker `tfsdk:"checker"` +// Dashboard maps the resource schema data. +type Dashboard struct { + Id types.String `tfsdk:"id"` } diff --git a/internal/resources/monitor/schema.go b/internal/resources/monitor/schema.go index 227670b..ba52927 100644 --- a/internal/resources/monitor/schema.go +++ b/internal/resources/monitor/schema.go @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" - "github.com/hashicorp/terraform-plugin-framework/types" ) var resourceSchema = schema.Schema{ @@ -14,7 +13,7 @@ var resourceSchema = schema.Schema{ MarkdownDescription: resourceDocument, Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ - Description: "Numeric identifier of the order.", + Description: "The Guance Resource Name (GRN) of cloud resource.", Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -22,870 +21,55 @@ var resourceSchema = schema.Schema{ }, "created_at": schema.StringAttribute{ - Description: "Timestamp of the last Terraform update of the order.", + Description: "The RFC3339/ISO8601 time string of resource created at.", Computed: true, }, - "dashboard_id": schema.StringAttribute{ - Description: "", + "manifest": schema.StringAttribute{ + Description: "Monitor Configuration", - Optional: true, - }, - - "script": schema.SingleNestedAttribute{ - Description: "", - - Optional: true, - Attributes: schemaMonitorScript, - }, - }, -} - -// schemaAPMCheck maps the resource schema data. -var schemaAPMCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "check item name", - - Optional: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - - Optional: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - - Optional: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", - - Optional: true, - }, - - "interval": schema.Int64Attribute{ - Description: "Query interval", - - Optional: true, - }, - - "recover_need_period_count": schema.Int64Attribute{ - Description: "recover need period count", - - Optional: true, - }, - - "no_data_interval": schema.Int64Attribute{ - Description: "no data interval", - - Optional: true, - }, - - "targets": schema.ListNestedAttribute{ - Description: "targets for checking", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaTarget, - }, - }, - - "checker": schema.SingleNestedAttribute{ - Description: "condition configuration for checking", - - Optional: true, - Attributes: schemaChecker, - }, -} - -// schemaCheckFunc maps the resource schema data. -var schemaCheckFunc = map[string]schema.Attribute{ - "func_id": schema.StringAttribute{ - Description: "function ID", - Required: true, - }, - - "kwargs": schema.StringAttribute{ - Description: "parameters", - - Optional: true, - }, -} - -// schemaChecker maps the resource schema data. -var schemaChecker = map[string]schema.Attribute{ - "rules": schema.ListNestedAttribute{ - Description: "rules", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaRule, - }, - }, -} - -// schemaCloudDialCheck maps the resource schema data. -var schemaCloudDialCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "check item name", - - Optional: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - - Optional: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - - Optional: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", - - Optional: true, - }, - - "interval": schema.Int64Attribute{ - Description: "Query interval", - - Optional: true, - }, - - "recover_need_period_count": schema.Int64Attribute{ - Description: "recover need period count", - - Optional: true, - }, - - "no_data_interval": schema.Int64Attribute{ - Description: "no data interval", - - Optional: true, - }, - - "targets": schema.ListNestedAttribute{ - Description: "targets for checking", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaTarget, - }, - }, - - "checker": schema.SingleNestedAttribute{ - Description: "condition configuration for checking", - - Optional: true, - Attributes: schemaChecker, - }, -} - -// schemaCondition maps the resource schema data. -var schemaCondition = map[string]schema.Attribute{ - "alias": schema.StringAttribute{ - Description: "alias of target", - - Optional: true, - }, - - "operator": schema.StringAttribute{ - Description: "operator", - - Optional: true, - }, - - "operands": schema.ListAttribute{ - Description: "operands", - - Optional: true, - ElementType: types.StringType, - }, -} - -// schemaLoggingCheck maps the resource schema data. -var schemaLoggingCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "check item name", - - Optional: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - - Optional: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - - Optional: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", - - Optional: true, - }, - - "interval": schema.Int64Attribute{ - Description: "Query interval", - - Optional: true, - }, - - "recover_need_period_count": schema.Int64Attribute{ - Description: "recover need period count", - - Optional: true, - }, - - "no_data_interval": schema.Int64Attribute{ - Description: "no data interval", - - Optional: true, - }, - - "targets": schema.ListNestedAttribute{ - Description: "targets for checking", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaTarget, - }, - }, - - "checker": schema.SingleNestedAttribute{ - Description: "condition configuration for checking", - - Optional: true, - Attributes: schemaChecker, - }, -} - -// schemaMonitorScript maps the resource schema data. -var schemaMonitorScript = map[string]schema.Attribute{ - "type": schema.StringAttribute{ - Description: "check method type", - - Optional: true, - }, - - "simple_check": schema.SingleNestedAttribute{ - Description: "simple check", - - Optional: true, - Attributes: schemaSimpleCheck, - }, - - "senior_check": schema.SingleNestedAttribute{ - Description: "senior check", - - Optional: true, - Attributes: schemaSeniorCheck, - }, - - "logging_check": schema.SingleNestedAttribute{ - Description: "logging check", - - Optional: true, - Attributes: schemaLoggingCheck, - }, - - "mutations_check": schema.SingleNestedAttribute{ - Description: "mutations check", - - Optional: true, - Attributes: schemaMutationsCheck, - }, - - "water_level_check": schema.SingleNestedAttribute{ - Description: "water level check", - - Optional: true, - Attributes: schemaWaterLevelCheck, - }, - - "range_check": schema.SingleNestedAttribute{ - Description: "range check", - - Optional: true, - Attributes: schemaRangeCheck, - }, - - "security_check": schema.SingleNestedAttribute{ - Description: "security check", - - Optional: true, - Attributes: schemaSecurityCheck, - }, - - "apm_check": schema.SingleNestedAttribute{ - Description: "APM check", - - Optional: true, - Attributes: schemaAPMCheck, - }, - - "rum_check": schema.SingleNestedAttribute{ - Description: "RUM check", - - Optional: true, - Attributes: schemaRUMCheck, - }, - - "process_check": schema.SingleNestedAttribute{ - Description: "process check", - - Optional: true, - Attributes: schemaProcessCheck, - }, - - "cloud_dial_check": schema.SingleNestedAttribute{ - Description: "cloud dial check", - - Optional: true, - Attributes: schemaCloudDialCheck, - }, -} - -// schemaMutationsCheck maps the resource schema data. -var schemaMutationsCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "check item name", - - Optional: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - - Optional: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - - Optional: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", - - Optional: true, - }, - - "interval": schema.Int64Attribute{ - Description: "Query interval", - - Optional: true, - }, - - "recover_need_period_count": schema.Int64Attribute{ - Description: "recover need period count", - - Optional: true, - }, - - "no_data_interval": schema.Int64Attribute{ - Description: "no data interval", - - Optional: true, - }, - - "targets": schema.ListNestedAttribute{ - Description: "targets for checking", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaTarget, - }, - }, - - "checker": schema.SingleNestedAttribute{ - Description: "condition configuration for checking", - - Optional: true, - Attributes: schemaChecker, - }, -} - -// schemaProcessCheck maps the resource schema data. -var schemaProcessCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "check item name", - - Optional: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - - Optional: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - - Optional: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", - - Optional: true, - }, - - "interval": schema.Int64Attribute{ - Description: "Query interval", - - Optional: true, - }, - - "recover_need_period_count": schema.Int64Attribute{ - Description: "recover need period count", - - Optional: true, - }, - - "no_data_interval": schema.Int64Attribute{ - Description: "no data interval", - - Optional: true, - }, - - "targets": schema.ListNestedAttribute{ - Description: "targets for checking", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaTarget, - }, - }, - - "checker": schema.SingleNestedAttribute{ - Description: "condition configuration for checking", - - Optional: true, - Attributes: schemaChecker, - }, -} - -// schemaRUMCheck maps the resource schema data. -var schemaRUMCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "check item name", - - Optional: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - - Optional: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - - Optional: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", - - Optional: true, - }, - - "interval": schema.Int64Attribute{ - Description: "Query interval", - - Optional: true, - }, - - "recover_need_period_count": schema.Int64Attribute{ - Description: "recover need period count", - - Optional: true, - }, - - "no_data_interval": schema.Int64Attribute{ - Description: "no data interval", - - Optional: true, - }, - - "targets": schema.ListNestedAttribute{ - Description: "targets for checking", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaTarget, - }, - }, - - "checker": schema.SingleNestedAttribute{ - Description: "condition configuration for checking", - - Optional: true, - Attributes: schemaChecker, - }, -} - -// schemaRangeCheck maps the resource schema data. -var schemaRangeCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "check item name", - - Optional: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - - Optional: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - - Optional: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", - - Optional: true, - }, - - "interval": schema.Int64Attribute{ - Description: "Query interval", - - Optional: true, - }, - - "recover_need_period_count": schema.Int64Attribute{ - Description: "recover need period count", - - Optional: true, - }, - - "no_data_interval": schema.Int64Attribute{ - Description: "no data interval", - - Optional: true, - }, - - "targets": schema.ListNestedAttribute{ - Description: "targets for checking", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaTarget, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, - }, - - "checker": schema.SingleNestedAttribute{ - Description: "condition configuration for checking", - - Optional: true, - Attributes: schemaChecker, - }, -} -// schemaRule maps the resource schema data. -var schemaRule = map[string]schema.Attribute{ - "conditions": schema.ListNestedAttribute{ - Description: "conditions", + "alert_policy": schema.SingleNestedAttribute{ + Description: "Alert Policy Configuration", - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaCondition, + Required: true, + Attributes: schemaAlertPolicy, }, - }, - - "condition_logic": schema.StringAttribute{ - Description: "condition logic", - - Optional: true, - }, - - "status": schema.StringAttribute{ - Description: "Fit the condition, the output event's status. The value is the same as the event's status", - - Optional: true, - }, - - "direction": schema.StringAttribute{ - Description: "[interval/water level/mutation parameter] check direction", - - Optional: true, - }, - - "period_num": schema.Int64Attribute{ - Description: "[interval/water level/mutation parameter] only check the latest data point number", - Optional: true, - }, - - "check_percent": schema.Int64Attribute{ - Description: "[interval parameter] abnormal percentage threshold", - - Optional: true, - }, - - "check_count": schema.Int64Attribute{ - Description: "[water level/mutation parameter] continuous abnormal point number", - - Optional: true, - }, - - "strength": schema.Int64Attribute{ - Description: "[water level/mutation parameter] strength", - - Optional: true, - }, -} + "dashboard": schema.SingleNestedAttribute{ + Description: "Dashboard Configuration", -// schemaSecurityCheck maps the resource schema data. -var schemaSecurityCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "check item name", - - Optional: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - - Optional: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - - Optional: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", - - Optional: true, - }, - - "interval": schema.Int64Attribute{ - Description: "Query interval", - - Optional: true, - }, - - "recover_need_period_count": schema.Int64Attribute{ - Description: "recover need period count", - - Optional: true, - }, - - "no_data_interval": schema.Int64Attribute{ - Description: "no data interval", - - Optional: true, - }, - - "targets": schema.ListNestedAttribute{ - Description: "targets for checking", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaTarget, - }, - }, - - "checker": schema.SingleNestedAttribute{ - Description: "condition configuration for checking", - - Optional: true, - Attributes: schemaChecker, - }, -} - -// schemaSeniorCheck maps the resource schema data. -var schemaSeniorCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "rule name", - Required: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - Required: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - Required: true, - }, - - "type": schema.StringAttribute{ - Description: "rule type", - Required: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", - Required: true, - }, - - "check_funcs": schema.ListNestedAttribute{ - Description: "check functions", - Required: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaCheckFunc, + Optional: true, + Attributes: schemaDashboard, }, }, } -// schemaSimpleCheck maps the resource schema data. -var schemaSimpleCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "check item name", - - Optional: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - - Optional: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - - Optional: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", +// schemaAlertPolicy maps the resource schema data. +var schemaAlertPolicy = map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Description: "Alert Policy ID", Optional: true, - }, - - "interval": schema.Int64Attribute{ - Description: "Query interval", - - Optional: true, - }, - - "recover_need_period_count": schema.Int64Attribute{ - Description: "recover need period count", - - Optional: true, - }, - - "no_data_interval": schema.Int64Attribute{ - Description: "no data interval", - - Optional: true, - }, - - "targets": schema.ListNestedAttribute{ - Description: "targets for checking", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaTarget, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, - - "checker": schema.SingleNestedAttribute{ - Description: "condition configuration for checking", - - Optional: true, - Attributes: schemaChecker, - }, } -// schemaTarget maps the resource schema data. -var schemaTarget = map[string]schema.Attribute{ - "alias": schema.StringAttribute{ - Description: "alias", - - Optional: true, - }, - - "dql": schema.StringAttribute{ - Description: "dql", +// schemaDashboard maps the resource schema data. +var schemaDashboard = map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Description: "Dashboard ID", Optional: true, - }, -} - -// schemaWaterLevelCheck maps the resource schema data. -var schemaWaterLevelCheck = map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "check item name", - - Optional: true, - }, - - "title": schema.StringAttribute{ - Description: "event title", - - Optional: true, - }, - - "message": schema.StringAttribute{ - Description: "event message", - - Optional: true, - }, - - "every": schema.StringAttribute{ - Description: "check frequency", - - Optional: true, - }, - - "interval": schema.Int64Attribute{ - Description: "Query interval", - - Optional: true, - }, - - "recover_need_period_count": schema.Int64Attribute{ - Description: "recover need period count", - - Optional: true, - }, - - "no_data_interval": schema.Int64Attribute{ - Description: "no data interval", - - Optional: true, - }, - - "targets": schema.ListNestedAttribute{ - Description: "targets for checking", - - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemaTarget, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, - - "checker": schema.SingleNestedAttribute{ - Description: "condition configuration for checking", - - Optional: true, - Attributes: schemaChecker, - }, } diff --git a/internal/resources/mute/README.md b/internal/resources/mute/README.md index da36df4..636a14f 100644 --- a/internal/resources/mute/README.md +++ b/internal/resources/mute/README.md @@ -33,7 +33,7 @@ variable "email" { } data "guance_members" "demo" { - filter = [ + filters = [ { name = "email" values = [var.email] @@ -144,10 +144,10 @@ resource "guance_mute" "demo" { week = "*" } } - + mute_tags = [ { - key = "host" + key = "host" value = "*" } ] diff --git a/internal/resources/mute/schema.go b/internal/resources/mute/schema.go index 2323201..326a487 100644 --- a/internal/resources/mute/schema.go +++ b/internal/resources/mute/schema.go @@ -3,9 +3,11 @@ package mute import ( + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" ) var resourceSchema = schema.Schema{ @@ -13,7 +15,7 @@ var resourceSchema = schema.Schema{ MarkdownDescription: resourceDocument, Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ - Description: "Numeric identifier of the order.", + Description: "The Guance Resource Name (GRN) of cloud resource.", Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -21,7 +23,7 @@ var resourceSchema = schema.Schema{ }, "created_at": schema.StringAttribute{ - Description: "Timestamp of the last Terraform update of the order.", + Description: "The RFC3339/ISO8601 time string of resource created at.", Computed: true, }, @@ -79,7 +81,17 @@ var resourceSchema = schema.Schema{ var schemaMuteRange = map[string]schema.Attribute{ "type": schema.StringAttribute{ Description: "Mute Range Type", - Required: true, + + MarkdownDescription: ` + Mute Range Type, value must be one of: *monitor*, *alert_policy*, other value will be ignored. + `, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("monitor", "alert_policy"), + }, }, "monitor": schema.SingleNestedAttribute{ @@ -101,7 +113,11 @@ var schemaMuteRange = map[string]schema.Attribute{ var schemaMuteRangeAlertPolicy = map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "Alert Policy ID", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } @@ -109,7 +125,11 @@ var schemaMuteRangeAlertPolicy = map[string]schema.Attribute{ var schemaMuteRangeMonitor = map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "Monitor ID", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } @@ -119,12 +139,18 @@ var schemaNotifyOptions = map[string]schema.Attribute{ Description: "Notify Message", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "before_time": schema.StringAttribute{ Description: "Notify Time", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } @@ -132,7 +158,17 @@ var schemaNotifyOptions = map[string]schema.Attribute{ var schemaNotifyTarget = map[string]schema.Attribute{ "type": schema.StringAttribute{ Description: "Notify Type", - Required: true, + + MarkdownDescription: ` + Notify Type, value must be one of: *member_group*, *notification*, other value will be ignored. + `, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("member_group", "notification"), + }, }, "member_group": schema.SingleNestedAttribute{ @@ -154,7 +190,11 @@ var schemaNotifyTarget = map[string]schema.Attribute{ var schemaNotifyTargetMemberGroup = map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "MemberGroup ID", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } @@ -162,7 +202,11 @@ var schemaNotifyTargetMemberGroup = map[string]schema.Attribute{ var schemaNotifyTargetNotification = map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "Notification ID", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } @@ -172,12 +216,18 @@ var schemaOnetimeOptions = map[string]schema.Attribute{ Description: "Start", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "end": schema.StringAttribute{ Description: "End", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } @@ -187,30 +237,45 @@ var schemaRepeatCrontabSet = map[string]schema.Attribute{ Description: "Min", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "hour": schema.StringAttribute{ Description: "Hour", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "day": schema.StringAttribute{ Description: "Day", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "month": schema.StringAttribute{ Description: "Month", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "week": schema.StringAttribute{ Description: "Week", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } @@ -220,24 +285,36 @@ var schemaRepeatOptions = map[string]schema.Attribute{ Description: "Start", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "end": schema.StringAttribute{ Description: "End", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "crontab_duration": schema.StringAttribute{ Description: "Crontab Duration", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "expire": schema.StringAttribute{ Description: "Repeat Expire", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "crontab": schema.SingleNestedAttribute{ @@ -252,11 +329,19 @@ var schemaRepeatOptions = map[string]schema.Attribute{ var schemaTag = map[string]schema.Attribute{ "key": schema.StringAttribute{ Description: "Tag", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "value": schema.StringAttribute{ Description: "Tag Value", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } diff --git a/internal/resources/notification/schema.go b/internal/resources/notification/schema.go index efa2de2..b0b3d79 100644 --- a/internal/resources/notification/schema.go +++ b/internal/resources/notification/schema.go @@ -3,9 +3,12 @@ package notification import ( + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -14,7 +17,7 @@ var resourceSchema = schema.Schema{ MarkdownDescription: resourceDocument, Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ - Description: "Numeric identifier of the order.", + Description: "The Guance Resource Name (GRN) of cloud resource.", Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -22,18 +25,32 @@ var resourceSchema = schema.Schema{ }, "created_at": schema.StringAttribute{ - Description: "Timestamp of the last Terraform update of the order.", + Description: "The RFC3339/ISO8601 time string of resource created at.", Computed: true, }, "name": schema.StringAttribute{ Description: "Notification object name", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "type": schema.StringAttribute{ Description: "Trigger rule type", - Required: true, + + MarkdownDescription: ` + Trigger rule type, value must be one of: *ding_talk_robot*, *http_request*, *wechat_robot*, *mail_group*, *feishu_robot*, *sms*, other value will be ignored. + `, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("ding_talk_robot", "http_request", "wechat_robot", "mail_group", "feishu_robot", "sms"), + }, }, "ding_talk_robot": schema.SingleNestedAttribute{ @@ -84,12 +101,20 @@ var resourceSchema = schema.Schema{ var schemaDingTalkRobot = map[string]schema.Attribute{ "webhook": schema.StringAttribute{ Description: "DingTalk Robot Call Address", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "secret": schema.StringAttribute{ Description: "DingTalk Robot Call Secret", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } @@ -97,12 +122,20 @@ var schemaDingTalkRobot = map[string]schema.Attribute{ var schemaFeishuRobot = map[string]schema.Attribute{ "webhook": schema.StringAttribute{ Description: "Feishu Robot Call Address", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "secret": schema.StringAttribute{ Description: "Feishu Robot Call Secret", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } @@ -110,7 +143,11 @@ var schemaFeishuRobot = map[string]schema.Attribute{ var schemaHTTPRequest = map[string]schema.Attribute{ "url": schema.StringAttribute{ Description: "HTTP Call Address", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } @@ -118,8 +155,12 @@ var schemaHTTPRequest = map[string]schema.Attribute{ var schemaMailGroup = map[string]schema.Attribute{ "to": schema.ListAttribute{ Description: "Member Account List", + Required: true, ElementType: types.StringType, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, }, } @@ -127,8 +168,12 @@ var schemaMailGroup = map[string]schema.Attribute{ var schemaSMS = map[string]schema.Attribute{ "to": schema.ListAttribute{ Description: "Phone Number List", + Required: true, ElementType: types.StringType, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, }, } @@ -136,6 +181,10 @@ var schemaSMS = map[string]schema.Attribute{ var schemaWeChatRobot = map[string]schema.Attribute{ "webhook": schema.StringAttribute{ Description: "Robot Call Address", - Required: true, + + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, } diff --git a/internal/resources/pipeline/README.md b/internal/resources/pipeline/README.md index c358dd4..4948cb9 100644 --- a/internal/resources/pipeline/README.md +++ b/internal/resources/pipeline/README.md @@ -1,10 +1,12 @@ # Pipeline -Pipeline is a data processing language that Observability Cloud provides. Pipeline supports text parsing of different formats of log data. +Pipeline is a data processing language that Observability Cloud provides. Pipeline supports text parsing of different +formats of log data. By writing a pipeline script, you can customize the structure of the log and use the cut fields as attributes. -By cutting out the attribute fields, we can quickly filter the relevant logs and perform data association analysis to help us quickly locate and solve problems. +By cutting out the attribute fields, we can quickly filter the relevant logs and perform data association analysis to +help us quickly locate and solve problems. ## Create @@ -12,13 +14,13 @@ The first let me create a resource. We will send the create operation to the res ```terraform resource "guance_pipeline" "demo" { - name = "oac-demo" + name = "oac-demo" category = "logging" - source = [ + source = [ "nginx" ] is_default = false - is_force = false + is_force = false content = <