Stackdriver HTTPS uptime check, with certificate verification

Stackdriver offers Uptime Checks for HTTPS. Sadly these checks don’t verify the certificate, so you won’t get an alert if a certificate expires.

A simple solution is to add a Google Cloud Function in between Stackdriver and your site. This allows the usual Stackdriver monitoring and alerting, plus a check in Google Cloud Function that the certificate is correct.

  1. Create a new HTTP  triggered Google Cloud Function with the following code:
const https = require('https');
 * Checks for correct upstream HTTPS response.
 * @param {!Object} req Cloud Function request context.
 * @param {!Object} res Cloud Function response context.
exports.checkHTTPS = function checkHTTPS(req, res) {
  upstream_req = https.get("https://YOUR_SITE/", (upstream_res) => {
Creating the new Cloud Function
  1. Create an Uptime check in Stackdriver, using the Cloud Function trigger URL instead of the target site.
Creating a Stackdriver Uptime Check

That’s it! You now have a Uptime Check that will alert if there is a failure of the certificate to validate, as well as any other issues.






Leave a Reply

Your email address will not be published. Required fields are marked *