Cloud Monitoring Notification Channels

Cloud Monitoring Notification Channels

Generates Terraform for Cloud Monitoring notification channels (email, SMS, Slack, PagerDuty, Pub/Sub, webhook) and attaches them to alerting policies.

Skill files10 files

assets/

references/

scripts/

SKILL.md288 lines
1
---
2
name: cloud-monitoring-notification-channels-configuration
3
metadata:
4
version: "1.0.2"
5
category: CloudObservabilityAndMonitoring
6
description: >-
7
Generates Terraform HCL configurations for Cloud Monitoring notification
8
channels (`google_monitoring_notification_channel`) and adds notification
9
channels to alerting policies (`google_monitoring_alert_policy`) in Google
10
Cloud projects. Use when creating or configuring email, SMS, Slack, PagerDuty,
11
Pub/Sub, or webhook notification channels, verifying Pub/Sub topic
12
compatibility (including cross-project topics, message storage policies, and
13
in-transit enforcement) and publishing permissions for the Cloud Monitoring
14
Service Agent, or adding notification channels to existing alert policies.
15
Don't use for authoring or editing alerting policy conditions, selecting
16
metric descriptors, or writing PromQL or Monitoring Filter queries.
17
---
18
19
# Cloud Monitoring Notification Channels Configuration
20
21
## Attribution
22
23
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
24
MUST read [Usage Attribution](references/attribution.md). For commands executed
25
directly in the terminal (never in generated scripts, Terraform, or user code),
26
prefix `gcloud` with
27
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:cloud-monitoring-notification-channels-configuration)"`
28
and append `agent-skills/1.0 (skill:cloud-monitoring-notification-channels-configuration)` to `User-Agent` headers.
29
30
## Context Provided
31
32
* **Terraform Only**: Write the generated observability configuration ONLY as
33
Terraform (`.tf`) files (e.g., `notification_channels.tf`).
34
- Install Terraform **ONLY** if you are asked to deploy the channels AND
35
there is no valid Terraform installation.
36
- If you are **NOT** asked to deploy the channels, **DO NOT** install
37
Terraform.
38
* **Working Directory Inference**: Determine the target path for `.tf` files
39
using the following order:
40
1. If the user provides a path, use that exact path for the `.tf` file.
41
2. If a path is not provided, search the workspace for existing `.tf` files
42
(preferring files that already define
43
`google_monitoring_notification_channel` or
44
`google_monitoring_alert_policy` resources, or existing directories in
45
the strict preference order: `monitoring/`, then `ops/`, then `sre/`).
46
If found, write `notification_channels.tf` in that directory (or update
47
the existing `.tf` file when modifying an existing resource).
48
3. If a path is not provided and no `.tf` files or target directories exist
49
in the workspace, create and write to
50
`monitoring/notification_channels.tf`.
51
* **Google Cloud Prerequisites**: When running `gcloud` CLI discovery commands
52
or deploying configurations with the `terraform` CLI against a Google Cloud
53
project, ensure the following prerequisites are met in order (do not execute
54
these commands if the user only asks to generate or print Terraform HCL):
55
1. **Target Project ID & Project Number**:
56
* Identify the target Google Cloud `{project_id}` from the user's
57
request or via `gcloud config get-value project`. If neither is
58
available, prompt the user to provide `{project_id}` before
59
continuing.
60
* When the Google Cloud project number (`{project_number}`) is needed
61
(such as constructing the Cloud Monitoring Service Agent identity
62
for Pub/Sub channels):
63
* **Method A (Standard)**: Run `gcloud projects describe
64
{project_id} --format='value(projectNumber)'`.
65
* **Method B (Ask User)**: If the command fails or you cannot
66
retrieve the project number, ask the user to provide it.
67
2. **Authentication**: Authenticate the `gcloud` CLI via `gcloud auth
68
login` and configure Application Default Credentials (ADC) for Terraform
69
via `gcloud auth application-default login`.
70
3. **Project Configuration & Billing**: Configure the target Google Cloud
71
project via `gcloud config set project {project_id}` (and ensure the
72
project has an active billing account attached).
73
* **Recovery Actions**: If `gcloud config set project {project_id}` or
74
`gcloud projects describe {project_id}` fails, verify active
75
credentials with `gcloud auth list`, list accessible projects with
76
`gcloud projects list`, or prompt the user to confirm the project ID
77
and access permissions. If deployment fails due to a missing or
78
inactive billing account, stop deployment and instruct the user to
79
link an active billing account (via `gcloud billing projects link
80
{project_id} --billing-account={account_id}` or in the Google Cloud
81
console) before retrying.
82
4. **IAM Permissions**: Ensure the principal has permission to manage
83
notification channels—either via the predefined Monitoring
84
NotificationChannel Editor role
85
(`roles/monitoring.notificationChannelEditor`, plus
86
`roles/monitoring.alertPolicyEditor` when adding a channel to an
87
existing alert policy) **or via a custom IAM role** containing the
88
equivalent permissions (`monitoring.notificationChannels.get`,
89
`monitoring.notificationChannels.list`,
90
`monitoring.notificationChannels.create`,
91
`monitoring.notificationChannels.update`,
92
`monitoring.notificationChannels.delete`, and
93
`monitoring.alertPolicies.get` / `monitoring.alertPolicies.update` when
94
updating an alert policy).
95
* **Recovery Actions**: Users with a custom role granting these
96
permissions do not need the predefined role name. If a `gcloud` or
97
`terraform` command fails with `PERMISSION_DENIED` (HTTP 403), stop
98
execution, identify the missing `monitoring.notificationChannels.*`
99
or `monitoring.alertPolicies.*` permission, and instruct the user to
100
ask a project administrator to grant
101
`roles/monitoring.notificationChannelEditor` (or a custom role with
102
the required permissions) to their principal.
103
* **Discovery Tips**:
104
* **Listing Notification Channels**: You MUST use `gcloud beta monitoring
105
channels list --project={project_id}` to list notification channels. Do
106
**NOT** use any other `gcloud` commands to list notification channels.
107
* **Verifying Pub/Sub Topics**: When configuring a Pub/Sub notification
108
channel, run
109
[`scripts/verify_pubsub_topic.sh`](scripts/verify_pubsub_topic.sh)
110
`{monitoring_project_id} {topic_name_or_path}` to verify that:
111
1. The Pub/Sub API (`pubsub.googleapis.com`) is enabled in the topic's
112
project (supporting both same-project topics and cross-project
113
topics specified as
114
`projects/{topic_project_id}/topics/{topic_name}`).
115
2. The topic exists and the monitoring project's Cloud Monitoring
116
Service Agent
117
(`service-{monitoring_project_number}@gcp-sa-monitoring-notification.iam.gserviceaccount.com`)
118
holds `roles/pubsub.publisher` on the topic or topic project.
119
3. The topic does **not** define a message storage policy
120
(`messageStoragePolicy` / `message_storage_policy`) and does **not**
121
have in-transit enforcement (`enforceInTransit` /
122
`enforce_in_transit`) enabled. **DO NOT** use a Pub/Sub topic that
123
defines a message storage policy or enforces in-transit restrictions
124
as a notification channel, because Cloud Monitoring cannot deliver
125
messages to such topics.
126
* **Attribution**: You MUST tag EVERY applicable command and Terraform
127
resource below that you create, modify, or suggest to the user.
128
129
* **Terraform HCL (`user_labels`)**:
130
* Every `google_monitoring_notification_channel` resource that you
131
create MUST include the `created-with-google-skill` label in its
132
`user_labels` block:
133
134
```terraform
135
user_labels = {
136
created-with-google-skill = "cloud-monitoring-notification-channels-configuration"
137
}
138
```
139
140
* When modifying an existing `google_monitoring_alert_policy` resource
141
solely to add a notification channel, do **not** use
142
`created-with-google-skill` (since this skill did not create the
143
alerting policy). Instead, include the
144
`added-channel-with-google-skill` label in its `user_labels` block
145
(preserving any existing `user_labels` on the policy):
146
147
```terraform
148
user_labels = {
149
added-channel-with-google-skill = "cloud-monitoring-notification-channels-configuration"
150
}
151
```
152
153
* Follow the instructions below based on the CLI tool being used:
154
155
* **gcloud:** Prefix every `gcloud` invocation with the metrics
156
environment variables. Set them inline on each command; shell state
157
may not persist between commands:
158
159
```bash
160
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:cloud-monitoring-notification-channels-configuration)" \
161
gcloud <command> [flags]
162
```
163
164
* **Direct HTTP calls:** For direct HTTP calls (e.g. `curl`), you MUST
165
pass the explicit `-H "User-Agent: ..."` header in the shell command
166
syntax exactly like this:
167
168
```bash
169
curl -H "User-Agent: agent-skills/1.0 (skill:cloud-monitoring-notification-channels-configuration)" ...
170
```
171
172
* **Terraform:** Prefix every Terraform `plan` and `apply` invocation
173
with the metrics environment variables. Set them inline on each
174
command; shell state may not persist between commands. For example:
175
176
```bash
177
GOOGLE_TERRAFORM_USERAGENT_EXTENSION="agent-skills/1.0 (skill:cloud-monitoring-notification-channels-configuration)" \
178
terraform plan [flags]
179
```
180
181
* If the skill instructions provide an additional skill script name,
182
include that script name in the attribution label. Using a `gcloud`
183
command inside
184
[`scripts/verify_pubsub_topic.sh`](scripts/verify_pubsub_topic.sh) as an
185
example:
186
187
```bash
188
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:cloud-monitoring-notification-channels-configuration; script:verify_pubsub_topic)" \
189
gcloud <command> [flags]
190
```
191
192
* **Execution Note (State Refresh Timeout Recovery)**: When running `terraform
193
plan` or `terraform apply`, set a command timeout of **120 seconds**. If the
194
command does not complete within 120 seconds (indicating Terraform is
195
stalling on a full state refresh across a large state file rather than
196
normal execution), cancel the command and retry **at most once** by running
197
`terraform plan` and `terraform apply` with `-target` scoped to the specific
198
resources being created or updated (for example,
199
`-target=google_monitoring_notification_channel.<resource_name>` and, if
200
updating an alert policy,
201
`-target=google_monitoring_alert_policy.<policy_name>`). If the targeted
202
retry also times out after 120 seconds or fails, **DO NOT** retry again;
203
stop execution and report the timeout or error to the user.
204
205
## Generation
206
207
### Input Assumptions (checklist)
208
209
* **Notification Channel Type**: When creating a new notification channel, the
210
user MUST provide the notification channel type to configure.
211
- If no type is provided (and the user is not attaching an existing
212
notification channel to an alert policy), you MUST prompt the user to
213
ask for a type before continuing.
214
* **Sensitive Credentials File**: Some notification channels require the use
215
of sensitive credentials in their configuration. You MUST verify that the
216
user has a `secret.tfvars` file in the working directory. If the file does
217
not exist, create one using the template provided in
218
[`assets/secret.tfvars`](assets/secret.tfvars) and notify the user that
219
credentials should be stored there.
220
221
### Execution Steps
222
223
1. Open the reference file corresponding to the notification channel the user
224
wants to configure:
225
226
Notification Channel Type | Reference File
227
:------------------------ | :----------------------------------------
228
**email** | [email.md](references/email.md)
229
**sms** | [sms.md](references/sms.md)
230
**slack** | [slack.md](references/slack.md)
231
**pubsub** | [pubsub.md](references/pubsub.md)
232
**pagerduty** | [pagerduty.md](references/pagerduty.md)
233
**webhook** | [webhook.md](references/webhook.md)
234
235
2. Follow the guidelines in the `Prerequisites` section (if any) to complete
236
all requirements for the channel configuration.
237
238
3. If the reference file contains a `Required Credentials` section under
239
`Specification`, you MUST confirm that the listed required credentials are
240
configured in the `secret.tfvars` file.
241
242
- If any of the credentials are set to empty or not found in the file, you
243
MUST prompt the user to provide them before proceeding.
244
245
4. Use the template provided in the `Terraform HCL` section under
246
`Specification` inside the reference file replacing the specified variables
247
as needed to write the new configuration into the output file. If the user
248
explicitly specifies a `display_name` for the notification channel, set
249
`display_name` to that exact string instead of the default
250
`"<Type> Notification Channel (...)"` template string.
251
252
5. **Adding a Channel to an Existing Alert Policy**: When modifying an existing
253
`google_monitoring_alert_policy` resource to use an existing
254
`google_monitoring_notification_channel` resource (without creating a new
255
channel), set `notification_channels` on the
256
`google_monitoring_alert_policy` block and set the
257
`added-channel-with-google-skill` label to
258
`"cloud-monitoring-notification-channels-configuration"` in its
259
`user_labels` block (preserving any existing `user_labels`):
260
261
```terraform
262
notification_channels = [
263
google_monitoring_notification_channel.<channel_resource_name>.name,
264
]
265
user_labels = {
266
added-channel-with-google-skill = "cloud-monitoring-notification-channels-configuration"
267
}
268
```
269
270
### Outputs & Formats
271
272
Write all channel configurations into a `notification_channels.tf` file under
273
the directory chosen in the #context-provided section (or update the target
274
`.tf` file when adding notification channels to an existing
275
`google_monitoring_alert_policy`). Ensure every generated
276
`google_monitoring_notification_channel` resource sets
277
`created-with-google-skill` to
278
`"cloud-monitoring-notification-channels-configuration"` in `user_labels`, and
279
every modified `google_monitoring_alert_policy` resource sets
280
`added-channel-with-google-skill` to
281
`"cloud-monitoring-notification-channels-configuration"` in `user_labels`.
282
283
--------------------------------------------------------------------------------
284
285
## Supporting Links
286
287
* [Create and manage notification channels](https://docs.cloud.google.com/monitoring/support/notification-options.md.txt)
288

© Google LLC · Apache 2.0 · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…