I've been experimenting with Logster and feeding information to
Graphite/Carbon for quick types of graphing data.  I thought I would
share the Parser I built for parsing Courier logs.  It is very simple
in that it merely counts successful and failed logins.  But it is a
good beginning point if there is need for more detailed data
extraction.  You could enhance the existing regex or create another
regex for parsing lines and then use that to create those extra data.

I have labeled it GPLv2, so use it as you will and the license allows.
Feel free to disseminate it to the Logster ML or a Logster wiki (if
one ever does get set up. Logster has so little documentation findable
by Google that it's frustrating.  And you have to include "-lobster"
for every Google query, because Google tries to be a little too
helpful with what it thinks I may have meant. :-/ )

Hopefully someone will find it useful.

...Todd
-- 
The total budget at all receivers for solving senders' problems is $0.
If you want them to accept your mail and manage it the way you want,
send it the way the spec says to. --John Levine
###  Author: Todd Lyons <[email protected]>
###  Copyright: 2014
###  License: GPL v2
###  Based on SampleLogster which is Copyright 2011, Etsy, Inc.

import time
import re

from logster.logster_helper import MetricObject, LogsterParser
from logster.logster_helper import LogsterParsingException

class CourierLogster(LogsterParser):

    def __init__(self, option_string=None):
        self.imap_login = 0
        self.imap_login_failed = 0
        self.pop_login = 0
        self.pop_login_failed = 0

### Aug  6 11:09:59 mail2 imapd: LOGIN FAILED, [email protected], ...
### Aug  6 11:13:40 mail2 pop3d: LOGIN FAILED, [email protected], ...
### Aug  6 11:09:59 mail1 pop3d: LOGIN, [email protected], ...
### Aug  6 11:10:00 mail1 imapd: LOGIN, [email protected], ...
### Aug  7 17:41:04 ivwm54 imapd-webmail: LOGIN, [email protected], ...
### Aug  3 10:10:03 ivwm54 pop3d-webmail: LOGIN, [email protected], ...

        self.reg = re.compile('.* (?P<service>(imapd|pop3d))(-webmail)?: LOGIN(?P<success>,)?(?P<failed> FAILED,)? ')

    def parse_line(self, line):

        try:
            regMatch = self.reg.match(line)

            if regMatch:
                linebits = regMatch.groupdict()
                if (linebits['service'] == 'pop3d'):
                    if (linebits['failed']):
                        self.pop_login_failed += 1
                    if (linebits['success']):
                        self.pop_login += 1
                elif (linebits['service'] == 'imapd'):
                    if (linebits['failed']):
                        self.imap_login_failed += 1
                    if (linebits['success']):
                        self.imap_login += 1

        except Exception, e:
            raise LogsterParsingException, "regmatch or contents failed with %s" % e


    def get_state(self, duration):
        self.duration = duration
        return [
            MetricObject("imap_login", self.imap_login, "IMAP Login Success"),
            MetricObject("imap_login_failed", self.imap_login_failed, "IMAP Login Failure"),
            MetricObject("pop_login", self.pop_login, "POP3 Login Success"),
            MetricObject("pop_login_failed", self.pop_login_failed, "POP3 Login Failure")
        ]
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Courier-imap mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap

Reply via email to