Using gcp monitoring with recaptcha
TypeScriptTo integrate Google Cloud Monitoring with reCAPTCHA Enterprise, you typically need two main components:
-
reCAPTCHA Enterprise Key: This key will be used for reCAPTCHA Enterprise service, which provides a more integrated and automated approach to distinguish between human users and bots.
-
Google Cloud Monitoring: This component consists of different resources that work together to monitor your applications and services on Google Cloud.
Let's create this setup using Pulumi with Google Cloud (GCP) provider. You need the
gcp
package which includes both reCAPTCHA Enterprise and Monitoring components.We will perform the following steps in the Pulumi program:
- Create a reCAPTCHA Enterprise Key which will be used on your website or service to verify interactions.
- Set up a Monitoring Dashboard to visualize metrics.
- Establish a Monitoring Notification Channel to receive alerts.
First, I'll walk you through a Pulumi program written in TypeScript that accomplishes these tasks:
import * as gcp from "@pulumi/gcp"; // Set up the reCAPTCHA enterprise key const recaptchaKey = new gcp.recaptcha.EnterpriseKey("my-recaptcha-key", { displayName: "My reCAPTCHA Key", webSettings: { integrationType: "SCORE", challengeSecurityPreference: "USABILITY", // replace with your security preferences }, }); // Create a GCP Monitoring Dashboard for viewing recaptcha metrics const dashboard = new gcp.monitoring.Dashboard("my-dashboard", { dashboardJson: `{ "displayName": "reCAPTCHA Enterprise Dashboard", "gridLayout": { "columns": 2, "widgets": [ { "title": "Number of reCAPTCHA checks", "xyChart": { "dataSets": [{ "timeSeriesQuery": { "timeSeriesFilter": { "filter": "metric.type=\"recaptchaenterprise.googleapis.com/check_count\" resource.type=\"recaptcha_key\"", "aggregation": { "perSeriesAligner": "ALIGN_RATE" } } } }] } }, { "title": "reCAPTCHA Score Distribution", "xyChart": { "dataSets": [{ "timeSeriesQuery": { "timeSeriesFilter": { "filter": "metric.type=\"recaptchaenterprise.googleapis.com/token_properties/score\" resource.type=\"recaptcha_key\"", "aggregation": { "perSeriesAligner": "ALIGN_RATE" } } } }] } } ] } }` }); // Set up a Monitoring Notification Channel to receive alerts const notificationChannel = new gcp.monitoring.NotificationChannel("my-notification-channel", { displayName: "reCAPTCHA Alerts Channel", type: "email", labels: { "email_address": "your-alert-email@example.com", // replace with your email for alerts }, description: "This channel is used for recaptcha alerts" }); // Output the reCAPTCHA key name and Dashboard ID for reference export const recaptchaKeyName = recaptchaKey.name; export const monitoringDashboardId = dashboard.id;
This Pulumi program performs the following actions:
- It imports the necessary GCP module from the Pulumi library.
- It creates a reCAPTCHA Enterprise Key resource with display name and web settings that specify the integration type and security preference.
- It creates a new GCP Monitoring Dashboard resource configured with JSON that defines a couple of widgets to visualize the reCAPTCHA metrics such as "Number of reCAPTCHA checks" and "reCAPTCHA Score Distribution".
- It sets up an email notification channel for monitoring alerts, where alerts will be sent to the specified email address.
Please Note:
- You should replace
"your-alert-email@example.com"
with the email address you want alerts to be sent to. - The
challengeSecurityPreference
and other properties should be set according to your requirement for reCAPTCHA.
After running this Pulumi program with
pulumi up
, Pulumi will provision the specified resources in your GCP account.For more information and options for configuration, please refer to the Pulumi documentation for
gcp.recaptcha.EnterpriseKey
,gcp.monitoring.Dashboard
, andgcp.monitoring.NotificationChannel
.-