9

I have schedule a HTTP call type job using Google Cloud Scheduler. How do I send out email alert if the job failed?

I have read the Cloud Scheduler documentation, and google around but the answer is not obvious. I had also attempted the stackdriver alert policy but can't find the corresponding metrics for the failed log entry.

I expect an email notification can be configured to send out if the scheduled job failed.

Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
Chee Kin Chan
  • 119
  • 1
  • 5

4 Answers4

8

One way to handle this is to create a new Log-Based Metric with this filter:

resource.type="cloud_scheduler_job" severity != INFO.

Then you can create an alert based on this new metric.

RayB
  • 2,096
  • 3
  • 24
  • 42
  • It looks like this has changed, any chance @RayB that you know how to do this in Metrics Explorer now? – marbletravis Feb 23 '22 at 20:35
  • More info, I have tried, it looks like its now under log_metrics, but when I do severity != INFO I get nothing, when I know I have had failed jobs recently – marbletravis Feb 23 '22 at 21:48
3

I use a workaround to solve my own problem.

Since my Cloud Scheduler is calling a HTTP call to my Cloud Function.

I use stack driver to create an alert to monitor my function execution with status code != ok. Any time the function execute with failure, an email alert will be send to my inbox.

This for the time being solve my problem.

Nevertheless, perhaps Cloud Scheduler can provide such enhancement to send alert as part of the configuration.

thank you.

Chee Kin Chan
  • 119
  • 1
  • 5
1

You can use log-based metrics in Stackdriver along with email notifications to get email notifications when your job fails.

Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
1

October 2022: You no longer need to create a metric for this, you can skip that step and create an alert directly from Logs Explorer after entering the query already described: resource.type="cloud_scheduler_job" severity != INFO

jazzdup
  • 89
  • 3