Skip to content

Commit

Permalink
mirahezerenewssl: improve logging (#3665)
Browse files Browse the repository at this point in the history
  • Loading branch information
paladox authored Jan 19, 2024
1 parent e3c397f commit 216809c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions modules/ssl/files/mirahezerenewssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
from flask import Flask
from flask import request
import logging
import os
import logging.handlers
import subprocess

app = Flask(__name__)

logging.basicConfig(filename='/var/log/ssl/miraheze-renewal.log', format='%(asctime)s - %(message)s', level=logging.INFO, force=True)
formatter = logging.Formatter('%(asctime)s - %(message)s', '%m-%d-%Y %I:%M:%S %p')
handler = logging.handlers.TimedRotatingFileHandler('/var/log/ssl/miraheze-renewal.log', 'midnight', 1)
handler.setFormatter(formatter)
logger = logging.getLogger()
logger.addHandler(handler)
logger.setLevel(logging.INFO)


@app.route('/renew', methods=['POST'])
Expand All @@ -24,8 +30,8 @@ def post():
with lock:
lock.acquire()
try:
logging.info(f'Renewed SSL certificate: {content["SERVICEDESC"]}')
os.system(f'/var/lib/nagios/ssl-acme -s {content["SERVICESTATE"]} -t {content["SERVICESTATETYPE"]} -u {content["SERVICEDESC"]} >> /var/log/ssl/ssl-renew.log 2>&1')
logger.info(f'Renewed SSL certificate: {content["SERVICEDESC"]}')
logger.info(subprocess.run(f'/var/lib/nagios/ssl-acme -s {content["SERVICESTATE"]} -t {content["SERVICESTATETYPE"]} -u {content["SERVICEDESC"]}', stderr=subprocess.STDOUT, shell=True))
lock_acquired = True
finally:
lock.release()
Expand Down

0 comments on commit 216809c

Please sign in to comment.