Script to customize Let's Encrypt mails
This commit is contained in:
parent
cb21ff0932
commit
b49d7d4617
2 changed files with 417 additions and 0 deletions
59
sysadmin/letsencrypt_mail.py
Normal file
59
sysadmin/letsencrypt_mail.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# SPDX-FileCopyrightText: 2021 Luca Beltrame <lbeltrame@kde.org>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
from enum import Enum
|
||||
import fileinput
|
||||
|
||||
import drymail # Vendored
|
||||
|
||||
|
||||
SUBJECT = "Certbot status: {0}"
|
||||
HEADER = {"X-Notification-Type": "letsencrypt"}
|
||||
|
||||
|
||||
class State(Enum):
|
||||
|
||||
renewed = 1
|
||||
no_action = 2
|
||||
error = 3
|
||||
unknown = 4
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}'
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
state = State.unknown
|
||||
text = list()
|
||||
|
||||
for line in fileinput.input():
|
||||
line = line.strip()
|
||||
text.append(line)
|
||||
|
||||
if "all renewals succeeded" in line:
|
||||
state = State.renewed
|
||||
elif "not due for renewal" in line:
|
||||
state = State.no_action
|
||||
|
||||
text = "\n".join(text)
|
||||
subject = SUBJECT.format(str(state))
|
||||
message = drymail.Message(
|
||||
sender=("Certbot renewal bot", "notify@dennogumi.org"),
|
||||
receivers=["root"],
|
||||
subject=subject,
|
||||
headers=HEADER,
|
||||
text=text
|
||||
)
|
||||
|
||||
client = drymail.SMTPMailer(
|
||||
host='localhost')
|
||||
|
||||
client.send(message)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue