Skip to content

Commit 26a03f2

Browse files
authored
Merge pull request #754 from dmick/wip-checkcerts
checkcerts: fix no reporting on cert error; change From address on emails
2 parents 0614952 + 283b764 commit 26a03f2

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

tools/checkcerts.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def parse_args():
5757
return ap.parse_args()
5858

5959
def sendmail(emailto, subject, body):
60-
FROM = 'gitbuilder@ceph.com'
60+
FROM = 'ceph-infra-admins@redhat.com'
6161
TO = emailto # must be a list
6262
SUBJECT = subject
6363
TEXT = body
@@ -85,25 +85,29 @@ def main():
8585

8686
warned = False
8787
for domain in domains:
88+
errstr = None
89+
certerr = False
8890
warn = datetime.timedelta(days=DAYS_BEFORE_WARN)
8991
try:
9092
with socket.create_connection((domain, 443)) as sock:
9193
with context.wrap_socket(sock, server_hostname=domain) as ssock:
9294
cert = ssock.getpeercert()
9395
except (ssl.CertificateError, ssl.SSLError) as e:
94-
print(f'{domain} cert error: {e}', file=sys.stderr)
95-
continue
96-
expire = datetime.datetime.strptime(cert['notAfter'],
97-
'%b %d %H:%M:%S %Y %Z')
98-
now = datetime.datetime.utcnow()
99-
left = expire - now
100-
101-
leftstr = f'{domain:30s} cert: {str(left).rsplit(".",1)[0]} left until it expires'
96+
certerr = True
97+
errstr = f'{domain} cert error: {e}'
98+
99+
if not certerr:
100+
expire = datetime.datetime.strptime(cert['notAfter'],
101+
'%b %d %H:%M:%S %Y %Z')
102+
now = datetime.datetime.utcnow()
103+
left = expire - now
104+
105+
errstr = f'{domain:30s} cert: {str(left).rsplit(".",1)[0]} left until it expires'
102106
if not args.quiet:
103-
print(leftstr, file=sys.stderr)
104-
if left < warn and args.email:
105-
subject = f'{domain}\'s SSL Cert is expiring soon.'
106-
body = leftstr
107+
print(errstr, file=sys.stderr)
108+
if (certerr or (left < warn)) and args.email:
109+
subject = f'Certificate problem with {domain}'
110+
body = errstr
107111
email = args.email
108112
if email == []:
109113
email = DEFAULT_EMAIL

0 commit comments

Comments
 (0)