monitoring Jam App Apache error logs (or any log for error)

49 views
Skip to first unread message

Drazen D. Babic

unread,
Mar 7, 2022, 1:46:08 AM3/7/22
to Jam.py Users Mailing List
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");
Message has been deleted

Danijel Kaurin

unread,
Nov 16, 2022, 2:46:16 AM11/16/22
to Drazen D. Babic, Jam.py Users Mailing List
Hi Dražen.

This is usefull tool for error reporting. I was just looking for something similar these days, thank you 😊

Regards

On Mon, 14 Nov 2022 at 13:13, Drazen D. Babic <bab...@gmail.com> wrote:
Hi all,

I've found the solution! 
Because there are more and more users on the site, I want to get the Email when Exception happens! 
When it does happen, this is normally 500 error, and the server has issues. 

Configured "Traceback" to test with first, since I know how to simulate the traceback. 

So now I got the email with:
Content match Service error.log

        Date:        Mon, 14 Nov 2022 13:06:19
        Action:      alert
        Host:        xxxxxx
        Description: content match:
[Mon Nov 14 13:04:44.969778 2022] [wsgi:error] [pid 134794] [remote xxxxxx:23584] Traceback (most recent call last):
.
.
So now I can configure the same for Exception! Nice!

--
You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jam-py/65b324e5-640a-45d1-a47b-b1a033673e6fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages