Checks the certificate on every domain in your sheet each morning and emails the ones running out of time to renew.
Uses
Gmail
Google Sheets
Warn before SSL certificates expire
Every morning at 08:00, the domains listed in your spreadsheet are read, the certificate on each one is looked up through a certificate-checking service you point it at, and the days left before it expires are worked out. Anything inside your warning window is collected into a single email, so a renewal is booked while there is still time rather than after the site has gone down.
You get one email listing each domain that is expiring soon with its expiry date and the days remaining, and any certificate already expired is called out as such. A domain that cannot be reached, or whose answer carries no expiry date, is listed separately in the same email and never stops the rest being checked. A row with no domain is skipped. When every certificate is comfortably valid, nothing is sent.
Before the first run you need a spreadsheet tab listing your domains under a column headed 'Domain', a certificate-checking service that answers for one domain at a time, and an inbox for the warnings.
domainSheetUrl to blank.Set domainSheetUrl to blank.domainSheetTab to blank.Set domainSheetTab to blank.certificateApiUrl to blank.Set certificateApiUrl to blank.alertEmail to blank.Set alertEmail to blank.warnWithinDays to 30.Set warnWithinDays to 30.domainSheetUrl. Save it as domainSheet.Read the rows of domainSheetUrl. Save it as domainSheet.sites to domainSheet.rows.Set sites to domainSheet.rows.expiringSoon to an empty list.Set expiringSoon to an empty list.couldNotCheck to an empty list.Set couldNotCheck to an empty list.site in sites:For each site in sites:domain to blank.Set domain to blank.missingDomainIf a step below fails, save the error as missingDomainsite.Domain and save it as domain.Trim site.Domain and save it as domain.domain to blank.Change domain to blank.domain is emptyIf domain is emptydaysLeft to 0.Set daysLeft to 0.expiresOn to blank.Set expiresOn to blank.wasChecked to false.Set wasChecked to false.checkFailedIf a step below fails, save the error as checkFailedcertificateApiUrl plus domain and save it as certificate.Fetch certificateApiUrl plus domain and save it as certificate.certificate.body.result.valid_till and save it as expiryDate.Trim certificate.body.result.valid_till and save it as expiryDate.expiryDate and save it as daysLeft.Count the days from today's date to expiryDate and save it as daysLeft.expiresOn to expiryDate.Change expiresOn to expiryDate.wasChecked to true.Change wasChecked to true.domain - checkFailed.message with certificateApiUrl replaced by the endpoint address to the end of couldNotCheck and save it as couldNotCheck.Add domain - checkFailed.message with certificateApiUrl replaced by the endpoint address to the end of couldNotCheck and save it as couldNotCheck.wasChecked is yes and daysLeft is less than or equal to warnWithinDaysIf wasChecked is yes and daysLeft is less than or equal to warnWithinDaysdaysLeft is less than 0If daysLeft is less than 0domain - EXPIRED on expiresOn to the end of expiringSoon and save it as expiringSoon.Add domain - EXPIRED on expiresOn to the end of expiringSoon and save it as expiringSoon.domain - expires on expiresOn (daysLeft days left) to the end of expiringSoon and save it as expiringSoon.Add domain - expires on expiresOn (daysLeft days left) to the end of expiringSoon and save it as expiringSoon.report to blank.Set report to blank.expiringSoon isn't emptyIf expiringSoon isn't emptyreport to Certificates expiring within warnWithinDays days:Change report to Certificates expiring within warnWithinDays days:
expiringSoon joined by a new line
.couldNotCheck isn't emptyIf couldNotCheck isn't emptyreport to reportChange report to report
These sites could not be checked:
couldNotCheck joined by a new line
.report is emptyIf report is emptywarnWithinDays more days.Finish the run: Every certificate checked is valid for more than warnWithinDays more days.alertEmail.Send an email to alertEmail.
Subject: SSL certificate check: the length of expiringSoon expiring within warnWithinDays daysreport