Skip to content

Instantly share code, notes, and snippets.

@gleicon
Created January 23, 2016 01:18
Show Gist options
  • Save gleicon/c9d00718c82dc5aa55fd to your computer and use it in GitHub Desktop.
Save gleicon/c9d00718c82dc5aa55fd to your computer and use it in GitHub Desktop.
import requests
import smtplib
user = "yourusername"
password = "yourpass"
fromaddr = "user@gmail.com"
toaddr = "sysadmin@gmail.com"
smtpserver = "smtp.server"
port = 587
hosts = [ "https://host1/", "https://host2", "https://host3", "https://www.google.com"]
def check_ssl(url):
try:
req = requests.get(url, verify=True)
except requests.exceptions.SSLError:
sendmail(url)
def sendmail(host):
msg = "\r\n".join([
"From: " + fromaddr,
"To: " + toaddr,
"Subject: SSL Error at " + host,
"",
"check ssl certificate at "+ host
])
server = smtplib.SMTP(smtpserver, port)
server.ehlo()
server.starttls()
server.ehlo()
server.login(user,password)
server.sendmail(fromaddr, toaddr, msg)
server.quit()
if __name__ == "__main__":
for a in hosts:
check_ssl(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment