From 1ff4a58b784c4f3e2f77aa08cfa485f62c605f7e Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 10 Aug 2020 09:44:14 -0700 Subject: [PATCH 01/23] draft send email alert --- content/v2.0/monitor-alert/send-email.md | 160 +++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 content/v2.0/monitor-alert/send-email.md diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md new file mode 100644 index 000000000..4324a406f --- /dev/null +++ b/content/v2.0/monitor-alert/send-email.md @@ -0,0 +1,160 @@ +--- +title: Send alert email +description: > + Send an alert email. +menu: + v2_0: + parent: Monitor & alert +weight: 104 +v2.0/tags: [alert, email, notifications, check] +related: + - /v2.0/monitor-alert/checks/ +--- + +Send an alert email using a third party service, such as SendGrid, AWS SES, or MailChimp. + +To send an alert email, do the following: + +1. [Create a check](/v2.0/monitor-alert/checks/create/#create-a-check-in-the-influxdb-ui) to identify the data to monitor and status to alert on. +2. Set up your preferred email service: + - **SendGrid**: See [Getting Started With the SendGrid API](https://sendgrid.com/docs/API_Reference/api_getting_started.html) and complete the prerequisites. + - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). + - **MailChimp**: +3. [Create an alert email task](#create-an-alert-email-task). + + {{% note %}} In the procedure below, we use the **Task UI** to create a task. Explore other ways to [create a task](/v2.0/process-data/manage-tasks/create-task/). + {{% /note %}} + +### Create an alert email task + +1. In the InfluxDB UI, select **Tasks** in the navigation menu on the left. + + {{< nav-icon "tasks" >}} + +2. Click **{{< icon "plus" >}} Create Task**, and then select **New Task**. +3. In the **Name** field, enter a descriptive name, for example, **Send alert email**, and then schedule how often to run the task, for example, every `10m`. For more detail, such as using cron syntax or including an offset, see [Task configuration options](/v2.0/process-data/task-options/). + +4. In the right panel, enter your **task script** with the **following detail**: + - Import the [Flux HTTP package](/v2.0/reference/flux/stdlib/http/). + - Specify the `_monitoring` bucket and `statuses` measurement. InfluxDB stores all [check](/v2.0/reference/glossary/#check) output data in this bucket and measurement. + - Specify the time range to monitor—use the same interval that the task is scheduled to run. + - Specify the `TARGET` as `EMAIL`. + - Specify the `_field_` as `_message`. + - Set the `_level` to alert on, for example, `crit`, `warn`, `info`, or `ok`. + +5. Use the `map()` function to specify the criteria to send an alert using `http.post()`. + +#### Examples - alert email task script + +##### SendGrid + +The example below uses the SendGrid API to send an alert email when more than 3 critical statuses occur within 10 minutes. + +``` +import "http" + +numberOfCrits = from(bucket: "_monitoring") + |> range(start: -10m) + |> filter(fn: (r) => (r["_measurement"] == "statuses")) + |> filter(fn: (r) => (r["TARGET"] == "EMAIL")) + |> filter(fn: (r) => (r["_field"] == "_message")) + |> filter(fn: (r) => (r["_level"] == "crit")) + |> count() + +numberOfCrits + |> map(fn: (r) => + (if r._value > 3 then {r with _value: http.post(url: "https://api.sendgrid.com/v3/mail/send", headers: {"Content-Type": "application/json", "Authorization": "Bearer "}, data: bytes(v: "{ + \"personalizations\": [{ + \"to\": [{ + \"email\": \”jane.doe@example.com\" + }], + \"subject\": \”InfluxData critical alert\" + }], + \"from\": { + \"email\": \"john.doe@example.com\" + }, + \"content\": [{ + \"type\": \"text/plain\", + \"value\": \”Example alert text\" + }] + }\""))} else {r with _value: 0})) + +``` + +##### AWS Simple Email Service (SES) + +The example below uses the AWS SES API v2 to send an alert email when more than 3 critical statuses occur within 10 minutes. + +{{% note}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html), [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html), + +We recommend signing your AWS API requests depend on https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html + +``` +import "http" + +numberOfCrits = from(bucket: "_monitoring") + |> range(start: -10m) + |> filter(fn: (r) => (r["_measurement"] == "statuses")) + |> filter(fn: (r) => (r["TARGET"] == "EMAIL")) + |> filter(fn: (r) => (r["_field"] == "_message")) + |> filter(fn: (r) => (r["_level"] == "crit")) + |> count() + +numberOfCrits + |> map(fn: (r) => + (if r._value > 3 then {r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", headers: {"Content-Type": "application/json", "Authorization": "AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE,SignedHeaders=Date;x-amz-date,Signature=9d63c3b5b7623d1fa3dc7fd1547313b9546c6d0fbbb6773a420613b7EXAMPLE"}, data: bytes(v: "{ + \"personalizations\": [{ + \"to\": [{ + \"email\": \”jane.doe@example.com\" + }], + \"subject\": \”InfluxData critical alert\" + }], + \"from\": { + \"email\": \"john.doe@example.com\" + }, + \"content\": [{ + \"type\": \"text/plain\", + \"value\": \”Example alert text\" + }] + }\""))} else {r with _value: 0})) + +``` + +##### AWS Simple Email Service (SES) + +The example below uses the AWS SES API v2 to send an alert email when more than 3 critical statuses occur within 10 minutes. + +{{% note}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html), [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html), + +We recommend signing your AWS API requests depend on https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html + +``` +import "http" + +numberOfCrits = from(bucket: "_monitoring") + |> range(start: -10m) + |> filter(fn: (r) => (r["_measurement"] == "statuses")) + |> filter(fn: (r) => (r["TARGET"] == "EMAIL")) + |> filter(fn: (r) => (r["_field"] == "_message")) + |> filter(fn: (r) => (r["_level"] == "crit")) + |> count() + +numberOfCrits + |> map(fn: (r) => + (if r._value > 3 then {r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", headers: {"Content-Type": "application/json", "Authorization": "AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE,SignedHeaders=Date;x-amz-date,Signature=9d63c3b5b7623d1fa3dc7fd1547313b9546c6d0fbbb6773a420613b7EXAMPLE"}, data: bytes(v: "{ + \"personalizations\": [{ + \"to\": [{ + \"email\": \”jane.doe@example.com\" + }], + \"subject\": \”InfluxData critical alert\" + }], + \"from\": { + \"email\": \"john.doe@example.com\" + }, + \"content\": [{ + \"type\": \"text/plain\", + \"value\": \”Example alert text\" + }] + }\""))} else {r with _value: 0})) + +``` From 3ab537fa365483c5088f356b84f33abd247515e9 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 10 Aug 2020 10:09:02 -0700 Subject: [PATCH 02/23] fix note --- content/v2.0/monitor-alert/send-email.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 4324a406f..9865f4452 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -15,7 +15,7 @@ Send an alert email using a third party service, such as SendGrid, AWS SES, or M To send an alert email, do the following: -1. [Create a check](/v2.0/monitor-alert/checks/create/#create-a-check-in-the-influxdb-ui) to identify the data to monitor and status to alert on. +1. [Create a check](/v2.0/monitor-alert/checks/create/#create-a-check-in-the-influxdb-ui) to identify the data to monitor and the status to alert on. 2. Set up your preferred email service: - **SendGrid**: See [Getting Started With the SendGrid API](https://sendgrid.com/docs/API_Reference/api_getting_started.html) and complete the prerequisites. - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). @@ -37,7 +37,7 @@ To send an alert email, do the following: 4. In the right panel, enter your **task script** with the **following detail**: - Import the [Flux HTTP package](/v2.0/reference/flux/stdlib/http/). - Specify the `_monitoring` bucket and `statuses` measurement. InfluxDB stores all [check](/v2.0/reference/glossary/#check) output data in this bucket and measurement. - - Specify the time range to monitor—use the same interval that the task is scheduled to run. + - Specify the time range to monitor; use the same interval that the task is scheduled to run. - Specify the `TARGET` as `EMAIL`. - Specify the `_field_` as `_message`. - Set the `_level` to alert on, for example, `crit`, `warn`, `info`, or `ok`. @@ -85,7 +85,8 @@ numberOfCrits The example below uses the AWS SES API v2 to send an alert email when more than 3 critical statuses occur within 10 minutes. -{{% note}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html), [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html), +{{% note %}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). +{{% /note %}} We recommend signing your AWS API requests depend on https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html From 74b00c9d970006f266d022c5ca64e9f536b724ea Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 10 Aug 2020 14:14:25 -0700 Subject: [PATCH 03/23] fix line 128 --- content/v2.0/monitor-alert/send-email.md | 30 ++++++++++-------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 9865f4452..c496d4f7b 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -18,9 +18,10 @@ To send an alert email, do the following: 1. [Create a check](/v2.0/monitor-alert/checks/create/#create-a-check-in-the-influxdb-ui) to identify the data to monitor and the status to alert on. 2. Set up your preferred email service: - **SendGrid**: See [Getting Started With the SendGrid API](https://sendgrid.com/docs/API_Reference/api_getting_started.html) and complete the prerequisites. - - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). - - **MailChimp**: -3. [Create an alert email task](#create-an-alert-email-task). + - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). {{% note %}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). +{{% /note %}} + - **MailJet**: See [Getting Started](https://dev.mailjet.com/email/guides/getting-started/) +3. [Create an alert email task](#create-an-alert-email-task) to call your email service and send an alert email. {{% note %}} In the procedure below, we use the **Task UI** to create a task. Explore other ways to [create a task](/v2.0/process-data/manage-tasks/create-task/). {{% /note %}} @@ -39,7 +40,7 @@ To send an alert email, do the following: - Specify the `_monitoring` bucket and `statuses` measurement. InfluxDB stores all [check](/v2.0/reference/glossary/#check) output data in this bucket and measurement. - Specify the time range to monitor; use the same interval that the task is scheduled to run. - Specify the `TARGET` as `EMAIL`. - - Specify the `_field_` as `_message`. + - Specify the `_field` as `_message`. - Set the `_level` to alert on, for example, `crit`, `warn`, `info`, or `ok`. 5. Use the `map()` function to specify the criteria to send an alert using `http.post()`. @@ -78,17 +79,14 @@ numberOfCrits \"value\": \”Example alert text\" }] }\""))} else {r with _value: 0})) - ``` ##### AWS Simple Email Service (SES) The example below uses the AWS SES API v2 to send an alert email when more than 3 critical statuses occur within 10 minutes. -{{% note %}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). -{{% /note %}} - -We recommend signing your AWS API requests depend on https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html +{{% note %}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). We recommend signing your AWS API requests using the [Signature Version 4 signing process](https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html). +{{% /note %}} ``` import "http" @@ -118,18 +116,15 @@ numberOfCrits \"value\": \”Example alert text\" }] }\""))} else {r with _value: 0})) - ``` -##### AWS Simple Email Service (SES) +##### Mailjet -The example below uses the AWS SES API v2 to send an alert email when more than 3 critical statuses occur within 10 minutes. +The example below uses the Mailjet Send API to send an alert email when more than 1 critical statuses occurs within 10 minutes. -{{% note}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html), [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html), +{{% note %}} To view your Mailjet API credentials, sign in to Mailjet and open the [API Key Management page](https://app.mailjet.com/account/api_keys). -We recommend signing your AWS API requests depend on https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html - -``` +```sh import "http" numberOfCrits = from(bucket: "_monitoring") @@ -142,7 +137,7 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => - (if r._value > 3 then {r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", headers: {"Content-Type": "application/json", "Authorization": "AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE,SignedHeaders=Date;x-amz-date,Signature=9d63c3b5b7623d1fa3dc7fd1547313b9546c6d0fbbb6773a420613b7EXAMPLE"}, data: bytes(v: "{ + (if r._value > 1 then {r with _value: http.post(url: "https://api.mailjet.com/v3.1/send", headers: {"Content-type": "application/json", Authorization: "Basic : Date: Mon, 10 Aug 2020 14:16:46 -0700 Subject: [PATCH 04/23] add closing note tag --- content/v2.0/monitor-alert/send-email.md | 1 + 1 file changed, 1 insertion(+) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index c496d4f7b..6e441a8d3 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -123,6 +123,7 @@ numberOfCrits The example below uses the Mailjet Send API to send an alert email when more than 1 critical statuses occurs within 10 minutes. {{% note %}} To view your Mailjet API credentials, sign in to Mailjet and open the [API Key Management page](https://app.mailjet.com/account/api_keys). +{{% /note %}} ```sh import "http" From 4258dd285632991686435643e2859da9d1bf7851 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 10 Aug 2020 15:35:05 -0700 Subject: [PATCH 05/23] update mailjet script --- content/v2.0/monitor-alert/send-email.md | 25 +++++++++--------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 6e441a8d3..6d7eaf35e 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -11,7 +11,7 @@ related: - /v2.0/monitor-alert/checks/ --- -Send an alert email using a third party service, such as SendGrid, AWS SES, or MailChimp. +Send an alert email using a third party service, such as SendGrid, AWS SES, or Mailjet. To send an alert email, do the following: @@ -19,8 +19,7 @@ To send an alert email, do the following: 2. Set up your preferred email service: - **SendGrid**: See [Getting Started With the SendGrid API](https://sendgrid.com/docs/API_Reference/api_getting_started.html) and complete the prerequisites. - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). {{% note %}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). -{{% /note %}} - - **MailJet**: See [Getting Started](https://dev.mailjet.com/email/guides/getting-started/) + - **Mailjet**: See [Getting Started](https://dev.mailjet.com/email/guides/getting-started/). 3. [Create an alert email task](#create-an-alert-email-task) to call your email service and send an alert email. {{% note %}} In the procedure below, we use the **Task UI** to create a task. Explore other ways to [create a task](/v2.0/process-data/manage-tasks/create-task/). @@ -139,18 +138,12 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => (if r._value > 1 then {r with _value: http.post(url: "https://api.mailjet.com/v3.1/send", headers: {"Content-type": "application/json", Authorization: "Basic :Hello, welcome to Mailjet!
}]}' + }\""))} else {r with _value: 0})) ``` From 3b2a48a681fcfa65f9069890d8574089085cab86 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 11 Aug 2020 17:40:14 -0700 Subject: [PATCH 06/23] add AWS SES and Mailjet as examples --- content/v2.0/monitor-alert/send-email.md | 170 ++++++++++++++++------- 1 file changed, 122 insertions(+), 48 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 6d7eaf35e..108c4ac12 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -11,19 +11,19 @@ related: - /v2.0/monitor-alert/checks/ --- -Send an alert email using a third party service, such as SendGrid, AWS SES, or Mailjet. - -To send an alert email, do the following: +Send an alert email using a third party service, such as SendGrid, AWS Simple Email Service (SES), Mailjet, or Mailgun. To send an alert email, complete the following steps: 1. [Create a check](/v2.0/monitor-alert/checks/create/#create-a-check-in-the-influxdb-ui) to identify the data to monitor and the status to alert on. -2. Set up your preferred email service: - - **SendGrid**: See [Getting Started With the SendGrid API](https://sendgrid.com/docs/API_Reference/api_getting_started.html) and complete the prerequisites. - - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). {{% note %}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). - - **Mailjet**: See [Getting Started](https://dev.mailjet.com/email/guides/getting-started/). +2. Set up your preferred email service (sign up, retrieve API key, and send test email): + - **SendGrid**: See [Getting Started With the SendGrid API](https://sendgrid.com/docs/API_Reference/api_getting_started.html) + - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). + - **Mailjet**: See [Getting Started](https://dev.mailjet.com/email/guides/getting-started/) + - **Mailgun**: See [Mailgun Signup](https://signup.mailgun.com/new/signup) 3. [Create an alert email task](#create-an-alert-email-task) to call your email service and send an alert email. - {{% note %}} In the procedure below, we use the **Task UI** to create a task. Explore other ways to [create a task](/v2.0/process-data/manage-tasks/create-task/). - {{% /note %}} + {{% note %}} + In the procedure below, we use the **Task UI** to create a task. Explore other ways to [create a task](/v2.0/process-data/manage-tasks/create-task/). + {{% /note %}} ### Create an alert email task @@ -34,45 +34,57 @@ To send an alert email, do the following: 2. Click **{{< icon "plus" >}} Create Task**, and then select **New Task**. 3. In the **Name** field, enter a descriptive name, for example, **Send alert email**, and then schedule how often to run the task, for example, every `10m`. For more detail, such as using cron syntax or including an offset, see [Task configuration options](/v2.0/process-data/task-options/). -4. In the right panel, enter your **task script** with the **following detail**: +4. In the right panel, enter the following detail in your **task script** (see [examples below](#examples)): - Import the [Flux HTTP package](/v2.0/reference/flux/stdlib/http/). + - (Optional) Store your API key as a secret for reuse. First, import the [Flux InfluxDB Secrets package](/v2.0/reference/flux/stdlib/secrets/), and then [add your API key as a secret](/v2.0/security/secrets/manage-secrets/add/). - Specify the `_monitoring` bucket and `statuses` measurement. InfluxDB stores all [check](/v2.0/reference/glossary/#check) output data in this bucket and measurement. - - Specify the time range to monitor; use the same interval that the task is scheduled to run. - - Specify the `TARGET` as `EMAIL`. - - Specify the `_field` as `_message`. + - Set the time range to monitor; use the same interval that the task is scheduled to run. - Set the `_level` to alert on, for example, `crit`, `warn`, `info`, or `ok`. + - Use the `map()` function to evaluate the criteria to send an alert using `http.post()`. + - Specify your email service `url` (endpoint), include applicable request `headers`, and verify your request `data` format follows the format specified for your email service. -5. Use the `map()` function to specify the criteria to send an alert using `http.post()`. +#### Examples -#### Examples - alert email task script +{{< tabs-wrapper >}} +{{% tabs %}} +[SendGrid](#) +[AWS SES](#) +[Mailjet](#) +{{% /tabs %}} -##### SendGrid + +{{% tab-content %}} The example below uses the SendGrid API to send an alert email when more than 3 critical statuses occur within 10 minutes. -``` +```js import "http" +// Import the Secrets package if you store your API key as a secret. +// For detail on how to do this, see Step 4 above. +import "influxdata/influxdb/secrets" + +// Retrieve the secret if applicable. Otherwise, skip this line +// and add the API key as the Bearer token in the Authorization header. +SENDGRID_APIKEY = secrets.get(key: "SENDGRID_APIKEY") + numberOfCrits = from(bucket: "_monitoring") |> range(start: -10m) |> filter(fn: (r) => (r["_measurement"] == "statuses")) - |> filter(fn: (r) => (r["TARGET"] == "EMAIL")) - |> filter(fn: (r) => (r["_field"] == "_message")) |> filter(fn: (r) => (r["_level"] == "crit")) |> count() numberOfCrits |> map(fn: (r) => - (if r._value > 3 then {r with _value: http.post(url: "https://api.sendgrid.com/v3/mail/send", headers: {"Content-Type": "application/json", "Authorization": "Bearer "}, data: bytes(v: "{ - \"personalizations\": [{ - \"to\": [{ - \"email\": \”jane.doe@example.com\" - }], - \"subject\": \”InfluxData critical alert\" + (if r._value > 3 then {r with _value: http.post(url: "https://api.sendgrid.com/v3/mail/send", + headers: {"Content-Type": "application/json", "Authorization": "Bearer ${SENDGRID_APIKEY}", + data: bytes(v: "{ + \"personalizations\": [{ + \"to\": [{ + \"email\": \”jane.doe@example.com\"}], + \"subject\": \”InfluxData critical alert\" }], - \"from\": { - \"email\": \"john.doe@example.com\" - }, + \"from\": {\"email\": \"john.doe@example.com\"}, \"content\": [{ \"type\": \"text/plain\", \"value\": \”Example alert text\" @@ -80,36 +92,43 @@ numberOfCrits }\""))} else {r with _value: 0})) ``` -##### AWS Simple Email Service (SES) +{{% /tab-content %}} + + +{{% tab-content %}} The example below uses the AWS SES API v2 to send an alert email when more than 3 critical statuses occur within 10 minutes. {{% note %}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). We recommend signing your AWS API requests using the [Signature Version 4 signing process](https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html). {{% /note %}} -``` +```js import "http" +// Import the Secrets package if you store your API key as a secret. +// For detail on how to do this, see Step 4 above. +import "influxdata/influxdb/secrets" + +// Retrieve the secret if applicable. Otherwise, skip this line +// and add the API key as the Bearer token in the Authorization header. +SENDGRID_APIKEY = secrets.get(key: "SENDGRID_APIKEY") + numberOfCrits = from(bucket: "_monitoring") |> range(start: -10m) |> filter(fn: (r) => (r["_measurement"] == "statuses")) - |> filter(fn: (r) => (r["TARGET"] == "EMAIL")) - |> filter(fn: (r) => (r["_field"] == "_message")) |> filter(fn: (r) => (r["_level"] == "crit")) |> count() numberOfCrits |> map(fn: (r) => - (if r._value > 3 then {r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", headers: {"Content-Type": "application/json", "Authorization": "AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE,SignedHeaders=Date;x-amz-date,Signature=9d63c3b5b7623d1fa3dc7fd1547313b9546c6d0fbbb6773a420613b7EXAMPLE"}, data: bytes(v: "{ - \"personalizations\": [{ - \"to\": [{ - \"email\": \”jane.doe@example.com\" - }], - \"subject\": \”InfluxData critical alert\" + (if r._value > 3 then {r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", headers: {"Content-Type": "application/json", "Authorization": "AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE,SignedHeaders=Datex-amz-date,Signature=9d63c3b5b7623d1fa3dc7fd1547313b9546c6d0fbbb6773a420613b7EXAMPLE"}, + data: bytes(v: "{ + \"personalizations\": [{ + \"to\": [{ + \"email\": \”jane.doe@example.com\"}], + \"subject\": \”InfluxData critical alert\" }], - \"from\": { - \"email\": \"john.doe@example.com\" - }, + \"from\": {\"email\": \"john.doe@example.com\"}, \"content\": [{ \"type\": \"text/plain\", \"value\": \”Example alert text\" @@ -117,33 +136,88 @@ numberOfCrits }\""))} else {r with _value: 0})) ``` -##### Mailjet +{{% /tab-content %}} -The example below uses the Mailjet Send API to send an alert email when more than 1 critical statuses occurs within 10 minutes. + +{{% tab-content %}} + +The example below uses the Mailjet Send API to send an alert email when more than 3 critical statuses occur within 10 minutes. {{% note %}} To view your Mailjet API credentials, sign in to Mailjet and open the [API Key Management page](https://app.mailjet.com/account/api_keys). {{% /note %}} -```sh +```js import "http" +// Import the Secrets package if you store your API key as a secret. +// For detail on how to do this, see Step 4 above. +import "influxdata/influxdb/secrets" + +// Retrieve the secret if applicable. Otherwise, skip this line +// and add the API key as the Bearer token in the Authorization header. +SENDGRID_APIKEY = secrets.get(key: "SENDGRID_APIKEY") + numberOfCrits = from(bucket: "_monitoring") |> range(start: -10m) |> filter(fn: (r) => (r["_measurement"] == "statuses")) - |> filter(fn: (r) => (r["TARGET"] == "EMAIL")) - |> filter(fn: (r) => (r["_field"] == "_message")) |> filter(fn: (r) => (r["_level"] == "crit")) |> count() numberOfCrits |> map(fn: (r) => - (if r._value > 1 then {r with _value: http.post(url: "https://api.mailjet.com/v3.1/send", headers: {"Content-type": "application/json", Authorization: "Basic : 3 then {r with _value: http.post(url: "https://api.mailjet.com/v3.1/send", headers: {"Content-type": "application/json", Authorization: "Basic :Hello, welcome to Mailjet!
}]}' + \"HTMLPart\": `"

Hello, to review critical alerts, review your Critical Alert Dashboard

}]}' }\""))} else {r with _value: 0})) ``` + +{{% /tab-content %}} + +{{< /tabs-wrapper >}} + +--- + + + + + From 0c03ace7603228a28767e89884f1f22220b64b3d Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 11 Aug 2020 21:11:14 -0700 Subject: [PATCH 07/23] update Mailgun example --- content/v2.0/monitor-alert/send-email.md | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 108c4ac12..66a2a5edf 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -50,6 +50,7 @@ Send an alert email using a third party service, such as SendGrid, AWS Simple Em [SendGrid](#) [AWS SES](#) [Mailjet](#) +[Mailgun](#) {{% /tabs %}} @@ -178,15 +179,11 @@ numberOfCrits {{% /tab-content %}} -{{< /tabs-wrapper >}} - ---- - - +{{% /tab-content %}} +{{< /tabs-wrapper >}} + +--- From 3e529c171e1368b5a13230f6b4c75f2d6463bfe7 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 11 Aug 2020 21:14:55 -0700 Subject: [PATCH 08/23] fix CI build --- content/v2.0/monitor-alert/send-email.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 66a2a5edf..53e819d74 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -206,8 +206,13 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => - (if r._value > 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN/messages&from=YOU@YOUR_DOMAIN_NAME&to=AuthorizedRecipient@example.com&subject=InfluxData%20Critical%20Errors&text=Review%20trecent%20critical%20errors.", headers: {"Content-type": "application/x-www-form-urlencoded", Authorization: "Basic api: 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN/messages", headers: {"Content-type": "application/x-www-form-urlencoded, Authorization: "Basic api:' \ + (if r._value > 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages", headers: {Authorization: "Basic api: Date: Tue, 11 Aug 2020 21:19:45 -0700 Subject: [PATCH 10/23] add tab-content wrapper --- content/v2.0/monitor-alert/send-email.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 6a6c09441..0ee3f2390 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -181,6 +181,9 @@ numberOfCrits + +{{% tab-content %}} + The example below uses the Mailgun API to send an alert email when more than 3 critical statuses occur within 10 minutes. {{% note %}} To view your Mailgun API keys, sign in to Mailjet and open [Account Security - API security](https://app.mailgun.com/app/account/security/api_keys). Mailgun requires that you specify a domain via Mailgun. For domains created in the US region, use `https://api.mailgun.net/v3`. For domains created in the EU region, use `https://api.eu.mailgun.net/v3`. Mailgun currently validates emails for the US region only. If you're using a free version of Mailgun, a domain is created when you set up your account and you can set up a maximum of five authorized recipients. To view your Mailgun domains, sign in to Mailgun and view the [Domains page](https://app.mailgun.com/app/sending/domains). From 3e70a300f0741bf2fe01d3e750d1b793eb7f83d5 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 11 Aug 2020 21:27:03 -0700 Subject: [PATCH 11/23] rmv space --- content/v2.0/monitor-alert/send-email.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 0ee3f2390..b2bebc8c3 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -181,7 +181,6 @@ numberOfCrits - {{% tab-content %}} The example below uses the Mailgun API to send an alert email when more than 3 critical statuses occur within 10 minutes. From 5049bdb0005db18ca7380ae10cdc7d2b15bfd132 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 11 Aug 2020 21:34:24 -0700 Subject: [PATCH 12/23] tighten up spacing --- content/v2.0/monitor-alert/send-email.md | 70 ++++++++++++------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index b2bebc8c3..5c835413e 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -80,17 +80,17 @@ numberOfCrits (if r._value > 3 then {r with _value: http.post(url: "https://api.sendgrid.com/v3/mail/send", headers: {"Content-Type": "application/json", "Authorization": "Bearer ${SENDGRID_APIKEY}", data: bytes(v: "{ - \"personalizations\": [{ - \"to\": [{ - \"email\": \”jane.doe@example.com\"}], - \"subject\": \”InfluxData critical alert\" - }], - \"from\": {\"email\": \"john.doe@example.com\"}, - \"content\": [{ - \"type\": \"text/plain\", - \"value\": \”Example alert text\" - }] - }\""))} else {r with _value: 0})) + \"personalizations\": [{ + \"to\": [{ + \"email\": \”jane.doe@example.com\"}], + \"subject\": \”InfluxData critical alert\" + }], + \"from\": {\"email\": \"john.doe@example.com\"}, + \"content\": [{ + \"type\": \"text/plain\", + \"value\": \”Example alert text\" + }] + }\""))} else {r with _value: 0})) ``` {{% /tab-content %}} @@ -124,17 +124,17 @@ numberOfCrits |> map(fn: (r) => (if r._value > 3 then {r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", headers: {"Content-Type": "application/json", "Authorization": "AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE,SignedHeaders=Datex-amz-date,Signature=9d63c3b5b7623d1fa3dc7fd1547313b9546c6d0fbbb6773a420613b7EXAMPLE"}, data: bytes(v: "{ - \"personalizations\": [{ - \"to\": [{ - \"email\": \”jane.doe@example.com\"}], - \"subject\": \”InfluxData critical alert\" - }], - \"from\": {\"email\": \"john.doe@example.com\"}, - \"content\": [{ - \"type\": \"text/plain\", - \"value\": \”Example alert text\" - }] - }\""))} else {r with _value: 0})) + \"personalizations\": [{ + \"to\": [{ + \"email\": \”jane.doe@example.com\"}], + \"subject\": \”InfluxData critical alert\" + }], + \"from\": {\"email\": \"john.doe@example.com\"}, + \"content\": [{ + \"type\": \"text/plain\", + \"value\": \”Example alert text\" + }] + }\""))} else {r with _value: 0})) ``` {{% /tab-content %}} @@ -167,14 +167,14 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => (if r._value > 3 then {r with _value: http.post(url: "https://api.mailjet.com/v3.1/send", headers: {"Content-type": "application/json", Authorization: "Basic :Hello, to review critical alerts, review your Critical Alert Dashboard}]}' + \"Messages\": [{ + \"From\": {\"Email\": \”jane.doe@example.com\"}, + \"To\": [{\"Email\": \"john.doe@example.com\"]}, + \"Subject\": \”InfluxData critical alert\", + \"TextPart\": \”Example alert text\" + \"HTMLPart\": `"

Hello, to review critical alerts, review your Critical Alert Dashboard

}]}' - }\""))} else {r with _value: 0})) + }\""))} else {r with _value: 0})) ``` {{% /tab-content %}} @@ -209,13 +209,13 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => (if r._value > 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages", headers: {Authorization: "Basic api:' \ + to=YOU@YOUR_DOMAIN_NAME \ + to=bar@example.com \ + subject='Hello' \ + text='Testing some Mailgun awesomeness!’ - }\""))} else {r with _value: 0})) + }\""))} else {r with _value: 0})) ``` {{% /tab-content %}} From c31360cd63d39c33d380f5264dd47f82817207cc Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 11 Aug 2020 21:57:57 -0700 Subject: [PATCH 13/23] update mailgun info --- content/v2.0/monitor-alert/send-email.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 5c835413e..e26a06bd8 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -185,7 +185,8 @@ numberOfCrits The example below uses the Mailgun API to send an alert email when more than 3 critical statuses occur within 10 minutes. -{{% note %}} To view your Mailgun API keys, sign in to Mailjet and open [Account Security - API security](https://app.mailgun.com/app/account/security/api_keys). Mailgun requires that you specify a domain via Mailgun. For domains created in the US region, use `https://api.mailgun.net/v3`. For domains created in the EU region, use `https://api.eu.mailgun.net/v3`. Mailgun currently validates emails for the US region only. If you're using a free version of Mailgun, a domain is created when you set up your account and you can set up a maximum of five authorized recipients. To view your Mailgun domains, sign in to Mailgun and view the [Domains page](https://app.mailgun.com/app/sending/domains). +{{% note %}} To view your Mailgun API keys, sign in to Mailjet and open [Account Security - API security](https://app.mailgun.com/app/account/security/api_keys).
+Mailgun requires that a domain be specified via Mailgun. A domain is automatically created for you when you first set up your account. You must include this domain in your url endpoint (for example, `https://api.mailgun.net/v3/YOUR_DOMAIN` or `https://api.eu.mailgun.net/v3/YOUR_DOMAIN`. If you're using a free version of Mailgun, you can set up a maximum of five authorized recipients (to receive email alerts) for your domain. To view your Mailgun domains, sign in to Mailgun and view the [Domains page](https://app.mailgun.com/app/sending/domains). {{% /note %}} ```js @@ -208,7 +209,7 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => - (if r._value > 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages", headers: {Authorization: "Basic api: 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN/messages", headers: {Authorization: "Basic api: Date: Tue, 11 Aug 2020 22:03:43 -0700 Subject: [PATCH 14/23] edits --- content/v2.0/monitor-alert/send-email.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index e26a06bd8..1bd355c07 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -78,7 +78,7 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => (if r._value > 3 then {r with _value: http.post(url: "https://api.sendgrid.com/v3/mail/send", - headers: {"Content-Type": "application/json", "Authorization": "Bearer ${SENDGRID_APIKEY}", + headers: {"Content-Type": "application/json", "Authorization": "Bearer ${SENDGRID_APIKEY}", data: bytes(v: "{ \"personalizations\": [{ \"to\": [{ @@ -122,7 +122,8 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => - (if r._value > 3 then {r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", headers: {"Content-Type": "application/json", "Authorization": "AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE,SignedHeaders=Datex-amz-date,Signature=9d63c3b5b7623d1fa3dc7fd1547313b9546c6d0fbbb6773a420613b7EXAMPLE"}, + (if r._value > 3 then {r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", + headers: {"Content-Type": "application/json", "Authorization": "AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE,SignedHeaders=Datex-amz-date,Signature=9d63c3b5b7623d1fa3dc7fd1547313b9546c6d0fbbb6773a420613b7EXAMPLE"}, data: bytes(v: "{ \"personalizations\": [{ \"to\": [{ From 1bbbc8384643c65e2b282cc2496907d4ea34b9f4 Mon Sep 17 00:00:00 2001 From: kelseiv <47797004+kelseiv@users.noreply.github.com> Date: Tue, 11 Aug 2020 22:05:35 -0700 Subject: [PATCH 15/23] delete extra space --- content/v2.0/monitor-alert/send-email.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 1bd355c07..a7512f260 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -193,7 +193,6 @@ Mailgun requires that a domain be specified via Mailgun. A domain is automatical ```js import "http" - // Import the Secrets package if you store your API key as a secret. // For detail on how to do this, see Step 4 above. import "influxdata/influxdb/secrets" From a903e96647e9ce27a5549ff92f2c864008655620 Mon Sep 17 00:00:00 2001 From: kelseiv <47797004+kelseiv@users.noreply.github.com> Date: Wed, 12 Aug 2020 08:34:10 -0700 Subject: [PATCH 16/23] remove extra character --- content/v2.0/monitor-alert/send-email.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index a7512f260..eabea2dc2 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -209,7 +209,7 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => - (if r._value > 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN/messages", headers: {Authorization: "Basic api: 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN/messages", headers: {Authorization: "Basic api:your-private-api-key"}, data: bytes(v: "{ from='Excited User ' \ to=YOU@YOUR_DOMAIN_NAME \ to=bar@example.com \ From 445a515003a660b62c8314cce93b153815817fcb Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 12 Aug 2020 09:59:26 -0700 Subject: [PATCH 17/23] edit --- content/v2.0/monitor-alert/send-email.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 1bd355c07..cc1574f80 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -32,13 +32,13 @@ Send an alert email using a third party service, such as SendGrid, AWS Simple Em {{< nav-icon "tasks" >}} 2. Click **{{< icon "plus" >}} Create Task**, and then select **New Task**. -3. In the **Name** field, enter a descriptive name, for example, **Send alert email**, and then schedule how often to run the task, for example, every `10m`. For more detail, such as using cron syntax or including an offset, see [Task configuration options](/v2.0/process-data/task-options/). +3. In the **Name** field, enter a descriptive name, for example, **Send alert email**, and then enter how often to run the task in the **Every** field, for example, `10m`. For more detail, such as using cron syntax or including an offset, see [Task configuration options](/v2.0/process-data/task-options/). 4. In the right panel, enter the following detail in your **task script** (see [examples below](#examples)): - Import the [Flux HTTP package](/v2.0/reference/flux/stdlib/http/). - (Optional) Store your API key as a secret for reuse. First, import the [Flux InfluxDB Secrets package](/v2.0/reference/flux/stdlib/secrets/), and then [add your API key as a secret](/v2.0/security/secrets/manage-secrets/add/). - Specify the `_monitoring` bucket and `statuses` measurement. InfluxDB stores all [check](/v2.0/reference/glossary/#check) output data in this bucket and measurement. - - Set the time range to monitor; use the same interval that the task is scheduled to run. + - Set the time range to monitor; use the same interval that the task is scheduled to run. For example, `range (start: -task.every)`. - Set the `_level` to alert on, for example, `crit`, `warn`, `info`, or `ok`. - Use the `map()` function to evaluate the criteria to send an alert using `http.post()`. - Specify your email service `url` (endpoint), include applicable request `headers`, and verify your request `data` format follows the format specified for your email service. From c50ded371327040544f658de4e68f1e650681e97 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 17 Aug 2020 13:47:54 -0700 Subject: [PATCH 18/23] edits from Scott --- content/v2.0/monitor-alert/send-email.md | 99 +++++++++++++----------- 1 file changed, 53 insertions(+), 46 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 2e4db3b56..8d1be2a70 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -11,18 +11,18 @@ related: - /v2.0/monitor-alert/checks/ --- -Send an alert email using a third party service, such as SendGrid, AWS Simple Email Service (SES), Mailjet, or Mailgun. To send an alert email, complete the following steps: +Send an alert email using a third party service, such as [SendGrid](https://sendgrid.com/), [Amazon Simple Email Service (SES)](https://aws.amazon.com/ses/), [Mailjet](https://www.mailjet.com/), or [Mailgun](https://www.mailgun.com/). To send an alert email, complete the following steps: 1. [Create a check](/v2.0/monitor-alert/checks/create/#create-a-check-in-the-influxdb-ui) to identify the data to monitor and the status to alert on. -2. Set up your preferred email service (sign up, retrieve API key, and send test email): +2. Set up your preferred email service (sign up, retrieve API credentials, and send test email): - **SendGrid**: See [Getting Started With the SendGrid API](https://sendgrid.com/docs/API_Reference/api_getting_started.html) - - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). + - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). Your AWS SES request, including the `url` (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). - **Mailjet**: See [Getting Started](https://dev.mailjet.com/email/guides/getting-started/) - **Mailgun**: See [Mailgun Signup](https://signup.mailgun.com/new/signup) 3. [Create an alert email task](#create-an-alert-email-task) to call your email service and send an alert email. {{% note %}} - In the procedure below, we use the **Task UI** to create a task. Explore other ways to [create a task](/v2.0/process-data/manage-tasks/create-task/). + In the procedure below, we use the **Task** page in the InfluxDB UI (user interface) to create a task. Explore other ways to [create a task](/v2.0/process-data/manage-tasks/create-task/). {{% /note %}} ### Create an alert email task @@ -36,8 +36,8 @@ Send an alert email using a third party service, such as SendGrid, AWS Simple Em 4. In the right panel, enter the following detail in your **task script** (see [examples below](#examples)): - Import the [Flux HTTP package](/v2.0/reference/flux/stdlib/http/). - - (Optional) Store your API key as a secret for reuse. First, import the [Flux InfluxDB Secrets package](/v2.0/reference/flux/stdlib/secrets/), and then [add your API key as a secret](/v2.0/security/secrets/manage-secrets/add/). - - Specify the `_monitoring` bucket and `statuses` measurement. InfluxDB stores all [check](/v2.0/reference/glossary/#check) output data in this bucket and measurement. + - (Optional) Store your API key as a secret for reuse. First, [add your API key as a secret](/v2.0/security/secrets/manage-secrets/add/), and then import the [Flux InfluxDB Secrets package](/v2.0/reference/flux/stdlib/secrets/). + - Query the `statuses` measurement in the `_monitoring` bucket to retrieve all statuses generated by your check. - Set the time range to monitor; use the same interval that the task is scheduled to run. For example, `range (start: -task.every)`. - Set the `_level` to alert on, for example, `crit`, `warn`, `info`, or `ok`. - Use the `map()` function to evaluate the criteria to send an alert using `http.post()`. @@ -56,7 +56,7 @@ Send an alert email using a third party service, such as SendGrid, AWS Simple Em {{% tab-content %}} -The example below uses the SendGrid API to send an alert email when more than 3 critical statuses occur within 10 minutes. +The example below uses the SendGrid API to send an alert email when more than 3 critical statuses occur since the previous task run. ```js import "http" @@ -70,15 +70,15 @@ import "influxdata/influxdb/secrets" SENDGRID_APIKEY = secrets.get(key: "SENDGRID_APIKEY") numberOfCrits = from(bucket: "_monitoring") - |> range(start: -10m) - |> filter(fn: (r) => (r["_measurement"] == "statuses")) - |> filter(fn: (r) => (r["_level"] == "crit")) + |> range(start: -task.every) + |> filter(fn: (r) => r.measurement == "statuses" and r.level == "crit") |> count() numberOfCrits - |> map(fn: (r) => - (if r._value > 3 then {r with _value: http.post(url: "https://api.sendgrid.com/v3/mail/send", - headers: {"Content-Type": "application/json", "Authorization": "Bearer ${SENDGRID_APIKEY}", + |> map(fn: (r) => (if r._value > 3 then { + r with _value: http.post( + url: "https://api.sendgrid.com/v3/mail/send", + headers: {"Content-Type": "application/json", Authorization: "Bearer ${SENDGRID_APIKEY}", data: bytes(v: "{ \"personalizations\": [{ \"to\": [{ @@ -98,32 +98,35 @@ numberOfCrits {{% tab-content %}} -The example below uses the AWS SES API v2 to send an alert email when more than 3 critical statuses occur within 10 minutes. +The example below uses the AWS SES API v2 to send an alert email when more than 3 critical statuses occur since the last task run. -{{% note %}} Your AWS SES request, including the url (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). We recommend signing your AWS API requests using the [Signature Version 4 signing process](https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html). +{{% note %}} +Your AWS SES request, including the `url` (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). We recommend signing your AWS API requests using the [Signature Version 4 signing process](https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html). {{% /note %}} ```js import "http" -// Import the Secrets package if you store your API key as a secret. +// Import the Secrets package if you store your API credentials as secrets. // For detail on how to do this, see Step 4 above. import "influxdata/influxdb/secrets" -// Retrieve the secret if applicable. Otherwise, skip this line +// Retrieve the secrets if applicable. Otherwise, skip this line // and add the API key as the Bearer token in the Authorization header. -SENDGRID_APIKEY = secrets.get(key: "SENDGRID_APIKEY") +AWS_AUTH_ALGORITHM = secrets.get(key: "AWS_AUTH_ALGORITHM") +AWS_CREDENTIAL = secrets.get(key: "AWS_CREDENTIAL") +AWS_SIGNED_HEADERS = secrets.get(key: "AWS_SIGNED_HEADERS") +AWS_CALCULATED_SIGNATURE = secrets.get(key: "AWS_CALCULATED_SIGNATURE") numberOfCrits = from(bucket: "_monitoring") - |> range(start: -10m) - |> filter(fn: (r) => (r["_measurement"] == "statuses")) - |> filter(fn: (r) => (r["_level"] == "crit")) + |> range(start: -task.every) + |> filter(fn: (r) => (r.measurement == "statuses" and r._level == "crit") |> count() numberOfCrits - |> map(fn: (r) => - (if r._value > 3 then {r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", - headers: {"Content-Type": "application/json", "Authorization": "AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE,SignedHeaders=Datex-amz-date,Signature=9d63c3b5b7623d1fa3dc7fd1547313b9546c6d0fbbb6773a420613b7EXAMPLE"}, + |> map(fn: (r) => (if r._value > 3 then { + r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", + headers: {"Content-Type": "application/json", Authorization: "Bearer ${AWS_AUTH_ALGORITHM}${AWS_CREDENTIAL}${AWS_SIGNED_HEADERS}${AWS_CALCULATED_SIGNATURE}"}, data: bytes(v: "{ \"personalizations\": [{ \"to\": [{ @@ -143,31 +146,34 @@ numberOfCrits {{% tab-content %}} -The example below uses the Mailjet Send API to send an alert email when more than 3 critical statuses occur within 10 minutes. +The example below uses the Mailjet Send API to send an alert email when more than 3 critical statuses since the last task run. -{{% note %}} To view your Mailjet API credentials, sign in to Mailjet and open the [API Key Management page](https://app.mailjet.com/account/api_keys). +{{% note %}} +To view your Mailjet API credentials, sign in to Mailjet and open the [API Key Management page](https://app.mailjet.com/account/api_keys). {{% /note %}} ```js import "http" -// Import the Secrets package if you store your API key as a secret. +// Import the Secrets package if you store your API keys as secrets. // For detail on how to do this, see Step 4 above. import "influxdata/influxdb/secrets" -// Retrieve the secret if applicable. Otherwise, skip this line -// and add the API key as the Bearer token in the Authorization header. -SENDGRID_APIKEY = secrets.get(key: "SENDGRID_APIKEY") +// Retrieve the secrets if applicable. Otherwise, skip this line +// and add the API keys as Basic credentials in the Authorization header. +MAILJET_APIKEY = secrets.get(key: "MAILJET_APIKEY") +MAILJET_SECRET_APIKEY = secrets.get(key: "MAILJET_SECRET_APIKEY") numberOfCrits = from(bucket: "_monitoring") - |> range(start: -10m) - |> filter(fn: (r) => (r["_measurement"] == "statuses")) - |> filter(fn: (r) => (r["_level"] == "crit")) + |> range(start: -task.every) + |> filter(fn: (r) => (r.measurement == "statuses" and "r.level" == "crit") |> count() numberOfCrits - |> map(fn: (r) => - (if r._value > 3 then {r with _value: http.post(url: "https://api.mailjet.com/v3.1/send", headers: {"Content-type": "application/json", Authorization: "Basic : map(fn: (r) => (if r._value > 3 then { + r with _value: http.post(url: "https://api.mailjet.com/v3.1/send", + headers: {"Content-type": "application/json", Authorization: "Basic ${MAILJET_APIKEY}:${MAILJET_SECRET_APIKEY}"}, + data: bytes(v: "{ \"Messages\": [{ \"From\": {\"Email\": \”jane.doe@example.com\"}, \"To\": [{\"Email\": \"john.doe@example.com\"]}, @@ -184,10 +190,11 @@ numberOfCrits {{% tab-content %}} -The example below uses the Mailgun API to send an alert email when more than 3 critical statuses occur within 10 minutes. +The example below uses the Mailgun API to send an alert email when more than 3 critical statuses occur since the last task run. -{{% note %}} To view your Mailgun API keys, sign in to Mailjet and open [Account Security - API security](https://app.mailgun.com/app/account/security/api_keys).
-Mailgun requires that a domain be specified via Mailgun. A domain is automatically created for you when you first set up your account. You must include this domain in your url endpoint (for example, `https://api.mailgun.net/v3/YOUR_DOMAIN` or `https://api.eu.mailgun.net/v3/YOUR_DOMAIN`. If you're using a free version of Mailgun, you can set up a maximum of five authorized recipients (to receive email alerts) for your domain. To view your Mailgun domains, sign in to Mailgun and view the [Domains page](https://app.mailgun.com/app/sending/domains). +{{% note %}} +To view your Mailgun API keys, sign in to Mailjet and open [Account Security - API security](https://app.mailgun.com/app/account/security/api_keys).
+Mailgun requires that a domain be specified via Mailgun. A domain is automatically created for you when you first set up your account. You must include this domain in your `url` endpoint (for example, `https://api.mailgun.net/v3/YOUR_DOMAIN` or `https://api.eu.mailgun.net/v3/YOUR_DOMAIN`. If you're using a free version of Mailgun, you can set up a maximum of five authorized recipients (to receive email alerts) for your domain. To view your Mailgun domains, sign in to Mailgun and view the [Domains page](https://app.mailgun.com/app/sending/domains). {{% /note %}} ```js @@ -199,22 +206,22 @@ import "influxdata/influxdb/secrets" // Retrieve the secret if applicable. Otherwise, skip this line // and add the API key as the Bearer token in the Authorization header. -SENDGRID_APIKEY = secrets.get(key: "SENDGRID_APIKEY") +MAILGUN_APIKEY = secrets.get(key: "MAILGUN_APIKEY") numberOfCrits = from(bucket: "_monitoring") - |> range(start: -10m) + |> range(start: -task.every) |> filter(fn: (r) => (r["_measurement"] == "statuses")) |> filter(fn: (r) => (r["_level"] == "crit")) |> count() numberOfCrits |> map(fn: (r) => - (if r._value > 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN/messages", headers: {Authorization: "Basic api:your-private-api-key"}, data: bytes(v: "{ - from='Excited User ' \ - to=YOU@YOUR_DOMAIN_NAME \ - to=bar@example.com \ - subject='Hello' \ - text='Testing some Mailgun awesomeness!’ + (if r._value > 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN/messages", headers: {"Content-type": "application/json", Authorization: "Basic api:${MAILGUN_APIKEY}"}, data: bytes(v: "{ + \"from\": \"Username \", + \"to\"=\"YOU@YOUR_DOMAIN_NAME\", + \"to\"=\"email@example.com\", + \"subject\"=\"Critical InfluxData alert\", + \"text\"=\"You have critical alerts to review\" }\""))} else {r with _value: 0})) ``` From c2921492dbff771e358b391d958ac6e513f7cd2f Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 17 Aug 2020 15:14:27 -0700 Subject: [PATCH 19/23] updates to SES --- content/v2.0/monitor-alert/send-email.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 8d1be2a70..d7f296ee2 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -128,19 +128,23 @@ numberOfCrits r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", headers: {"Content-Type": "application/json", Authorization: "Bearer ${AWS_AUTH_ALGORITHM}${AWS_CREDENTIAL}${AWS_SIGNED_HEADERS}${AWS_CALCULATED_SIGNATURE}"}, data: bytes(v: "{ - \"personalizations\": [{ + \"personalizations\": [ + { \"to\": [{ \"email\": \”jane.doe@example.com\"}], \"subject\": \”InfluxData critical alert\" }], \"from\": {\"email\": \"john.doe@example.com\"}, - \"content\": [{ + \"content\": [ + { \"type\": \"text/plain\", \"value\": \”Example alert text\" }] }\""))} else {r with _value: 0})) ``` +For details on the =request syntax, see [SendEmail API v2 reference](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html). + {{% /tab-content %}} From dab5fa47e15d995470f1647e99366ae1d7009b15 Mon Sep 17 00:00:00 2001 From: kelseiv <47797004+kelseiv@users.noreply.github.com> Date: Mon, 17 Aug 2020 15:16:36 -0700 Subject: [PATCH 20/23] fix format --- content/v2.0/monitor-alert/send-email.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index d7f296ee2..789fa096c 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -128,15 +128,13 @@ numberOfCrits r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", headers: {"Content-Type": "application/json", Authorization: "Bearer ${AWS_AUTH_ALGORITHM}${AWS_CREDENTIAL}${AWS_SIGNED_HEADERS}${AWS_CALCULATED_SIGNATURE}"}, data: bytes(v: "{ - \"personalizations\": [ - { + \"personalizations\": [{ \"to\": [{ \"email\": \”jane.doe@example.com\"}], \"subject\": \”InfluxData critical alert\" }], \"from\": {\"email\": \"john.doe@example.com\"}, - \"content\": [ - { + \"content\": [{ \"type\": \"text/plain\", \"value\": \”Example alert text\" }] From ba87b695c4296dbc3044cbdbb5266ff1b9f3032e Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 18 Aug 2020 17:27:28 -0700 Subject: [PATCH 21/23] edits f Scott --- content/v2.0/monitor-alert/send-email.md | 46 ++++++++++++------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 789fa096c..4f5182ec2 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -17,7 +17,7 @@ Send an alert email using a third party service, such as [SendGrid](https://send 2. Set up your preferred email service (sign up, retrieve API credentials, and send test email): - **SendGrid**: See [Getting Started With the SendGrid API](https://sendgrid.com/docs/API_Reference/api_getting_started.html) - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). Your AWS SES request, including the `url` (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). - - **Mailjet**: See [Getting Started](https://dev.mailjet.com/email/guides/getting-started/) + - **Mailjet**: See [Getting Started with Mailjet](https://dev.mailjet.com/email/guides/getting-started/) - **Mailgun**: See [Mailgun Signup](https://signup.mailgun.com/new/signup) 3. [Create an alert email task](#create-an-alert-email-task) to call your email service and send an alert email. @@ -78,18 +78,18 @@ numberOfCrits |> map(fn: (r) => (if r._value > 3 then { r with _value: http.post( url: "https://api.sendgrid.com/v3/mail/send", - headers: {"Content-Type": "application/json", Authorization: "Bearer ${SENDGRID_APIKEY}", - data: bytes(v: "{ - \"personalizations\": [{ - \"to\": [{ - \"email\": \”jane.doe@example.com\"}], - \"subject\": \”InfluxData critical alert\" + headers: {"Content-Type": "application/json", Authorization: "Bearer ${SENDGRID_APIKEY}", + data: bytes(v: "{ + \"personalizations\": [{ + \"to\": [{ + \"email\": \”jane.doe@example.com\"}], + \"subject\": \”InfluxData critical alert\" }], - \"from\": {\"email\": \"john.doe@example.com\"}, - \"content\": [{ - \"type\": \"text/plain\", - \"value\": \”Example alert text\" - }] + \"from\": {\"email\": \"john.doe@example.com\"}, + \"content\": [{ + \"type\": \"text/plain\", + \"value\": \”Example alert text\" + }] }\""))} else {r with _value: 0})) ``` @@ -125,8 +125,9 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => (if r._value > 3 then { - r with _value: http.post(url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", - headers: {"Content-Type": "application/json", Authorization: "Bearer ${AWS_AUTH_ALGORITHM}${AWS_CREDENTIAL}${AWS_SIGNED_HEADERS}${AWS_CALCULATED_SIGNATURE}"}, + r with _value: http.post( + url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", + headers: {"Content-Type": "application/json", Authorization: "Bearer ${AWS_AUTH_ALGORITHM}${AWS_CREDENTIAL}${AWS_SIGNED_HEADERS}${AWS_CALCULATED_SIGNATURE}"}, data: bytes(v: "{ \"personalizations\": [{ \"to\": [{ @@ -173,16 +174,16 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => (if r._value > 3 then { - r with _value: http.post(url: "https://api.mailjet.com/v3.1/send", - headers: {"Content-type": "application/json", Authorization: "Basic ${MAILJET_APIKEY}:${MAILJET_SECRET_APIKEY}"}, - data: bytes(v: "{ + r with _value: http.post( + url: "https://api.mailjet.com/v3.1/send", + headers: {"Content-type": "application/json", Authorization: "Basic ${MAILJET_APIKEY}:${MAILJET_SECRET_APIKEY}"}, + data: bytes(v: "{ \"Messages\": [{ \"From\": {\"Email\": \”jane.doe@example.com\"}, \"To\": [{\"Email\": \"john.doe@example.com\"]}, \"Subject\": \”InfluxData critical alert\", \"TextPart\": \”Example alert text\" \"HTMLPart\": `"

Hello, to review critical alerts, review your Critical Alert Dashboard

}]}' - }\""))} else {r with _value: 0})) ``` @@ -195,8 +196,7 @@ numberOfCrits The example below uses the Mailgun API to send an alert email when more than 3 critical statuses occur since the last task run. {{% note %}} -To view your Mailgun API keys, sign in to Mailjet and open [Account Security - API security](https://app.mailgun.com/app/account/security/api_keys).
-Mailgun requires that a domain be specified via Mailgun. A domain is automatically created for you when you first set up your account. You must include this domain in your `url` endpoint (for example, `https://api.mailgun.net/v3/YOUR_DOMAIN` or `https://api.eu.mailgun.net/v3/YOUR_DOMAIN`. If you're using a free version of Mailgun, you can set up a maximum of five authorized recipients (to receive email alerts) for your domain. To view your Mailgun domains, sign in to Mailgun and view the [Domains page](https://app.mailgun.com/app/sending/domains). +To view your Mailgun API keys, sign in to Mailjet and open [Account Security - API security](https://app.mailgun.com/app/account/security/api_keys). Mailgun requires that a domain be specified via Mailgun. A domain is automatically created for you when you first set up your account. You must include this domain in your `url` endpoint (for example, `https://api.mailgun.net/v3/YOUR_DOMAIN` or `https://api.eu.mailgun.net/v3/YOUR_DOMAIN`. If you're using a free version of Mailgun, you can set up a maximum of five authorized recipients (to receive email alerts) for your domain. To view your Mailgun domains, sign in to Mailgun and view the [Domains page](https://app.mailgun.com/app/sending/domains). {{% /note %}} ```js @@ -218,13 +218,15 @@ numberOfCrits = from(bucket: "_monitoring") numberOfCrits |> map(fn: (r) => - (if r._value > 1 then {r with _value: http.post(url: "https://api.mailgun.net/v3/YOUR_DOMAIN/messages", headers: {"Content-type": "application/json", Authorization: "Basic api:${MAILGUN_APIKEY}"}, data: bytes(v: "{ + (if r._value > 1 then {r with _value: http.post( + url: "https://api.mailgun.net/v3/YOUR_DOMAIN/messages", + headers: {"Content-type": "application/json", Authorization: "Basic api:${MAILGUN_APIKEY}"}, + data: bytes(v: "{ \"from\": \"Username \", \"to\"=\"YOU@YOUR_DOMAIN_NAME\", \"to\"=\"email@example.com\", \"subject\"=\"Critical InfluxData alert\", \"text\"=\"You have critical alerts to review\" - }\""))} else {r with _value: 0})) ``` From 4e6a1cd438edd6dc8b6bb72d8074bce7469d4bd6 Mon Sep 17 00:00:00 2001 From: kelseiv <47797004+kelseiv@users.noreply.github.com> Date: Tue, 18 Aug 2020 17:35:35 -0700 Subject: [PATCH 22/23] fix typos --- content/v2.0/monitor-alert/send-email.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index 4f5182ec2..b0f9aee99 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -142,14 +142,14 @@ numberOfCrits }\""))} else {r with _value: 0})) ``` -For details on the =request syntax, see [SendEmail API v2 reference](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html). +For details on the request syntax, see [SendEmail API v2 reference](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html). {{% /tab-content %}} {{% tab-content %}} -The example below uses the Mailjet Send API to send an alert email when more than 3 critical statuses since the last task run. +The example below uses the Mailjet Send API to send an alert email when more than 3 critical statuses occur since the last task run. {{% note %}} To view your Mailjet API credentials, sign in to Mailjet and open the [API Key Management page](https://app.mailjet.com/account/api_keys). From ec7521f5083de9bcd38b7e3d75034475f5cb5b24 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 19 Aug 2020 10:29:23 -0700 Subject: [PATCH 23/23] edit f Scot --- content/v2.0/monitor-alert/send-email.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/content/v2.0/monitor-alert/send-email.md b/content/v2.0/monitor-alert/send-email.md index b0f9aee99..ad4ef9a18 100644 --- a/content/v2.0/monitor-alert/send-email.md +++ b/content/v2.0/monitor-alert/send-email.md @@ -78,7 +78,7 @@ numberOfCrits |> map(fn: (r) => (if r._value > 3 then { r with _value: http.post( url: "https://api.sendgrid.com/v3/mail/send", - headers: {"Content-Type": "application/json", Authorization: "Bearer ${SENDGRID_APIKEY}", + headers: {"Content-Type": "application/json", Authorization: "Bearer ${SENDGRID_APIKEY}"}, data: bytes(v: "{ \"personalizations\": [{ \"to\": [{ @@ -233,5 +233,3 @@ numberOfCrits {{% /tab-content %}} {{< /tabs-wrapper >}} - ----