Hi all,
looks like Apache has issues when Python does a traceback or Exception, so it is needed to monitor Apache log file for that and send the email out if it happens. Now, the only thing is I have no idea which Application did the exception.
Any ideas? The only reference is the time when it happened (in bold, Exception is string to search for). So it would be useful to send email with "https://...com/app1/" info, because app1 did the exception.
The error log is:
[Mon Mar 07
07:23:38.223811 2022] [wsgi:error] [pid 23440] [remote
49.184.37.2:34634]
Exception: no such column: ......
The access log is:
49.184.37.2 - - [07/Mar/2022:07:23:38 +0100] "POST /09ddd5478b5e8f7f26faaa9f809da79c/api HTTP/1.1" 200 336 "https://...com/app1/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36"
Run monitor.py in the background or cron.
Cheers
cat monitor.py
#!/usr/bin/python
import time
import os
import smtplib
#open the file
filename = '/var/log/apache2/error.log'
file = open(filename,'r')
sender = '.....@
gmail.com'
receivers = '<....@
gmail.com>'
message = """From: From JamPy <....@
gmail.com>
To: To Person <....@
gmail.com>
Subject:Error
"""
while 1:
where = file.tell()
line = file.readline()
if not line:
time.sleep(1)
file.seek(where)
else:
if 'Exception:' in line:
#print line
message = message + line;
try:
smtpObj = smtplib.SMTP('127.0.0.1', 25)
smtpObj.sendmail(sender, receivers, message)
#print ("Successfully sent email");
except SMTPException:
print ("Error: unable to send email");