Exemple #1
0
    def process(self):
        """Process the log file.

        We parse it and then generate standard graphics (day, week,
        month).
        """
        for line in self.f.readlines():
            self._parse_line(line)

        G = Grapher()
        for dom, data in self.data.iteritems():
            self._dprint("[rrd] dealing with domain %s" % dom)
            for t in sorted(data.keys()):
                self.update_rrd(dom, t)

            for graph_tpl in MailTraffic().get_graphs():
                G.make_defaults(dom, graph_tpl)
Exemple #2
0
    def process(self):
        """Process the log file.

        We parse it and then generate standard graphics (day, week,
        month).
        """
        for line in self.f.readlines():
            self._parse_line(line)

        G = Grapher()
        for dom, data in self.data.iteritems():
            self._dprint("[rrd] dealing with domain %s" % dom)
            for t in sorted(data.keys()):
                self.update_rrd(dom, t)

            for graph_tpl in MailTraffic().get_graphs():
                G.make_defaults(dom, graph_tpl)
Exemple #3
0
    def process(self):
        id_expr = re.compile("([0-9A-F]+): (.*)")
        prev_se = -1
        prev_mi = -1
        prev_ho = -1
        for line in self.f.readlines():
            m = self.line_expr.match(line)
            if not m:
                continue
            (mo, da, ho, mi, se, host, prog, pid, log) = m.groups()
            se = int(int(se) / rrdstep)  # rrd step is one-minute => se = 0

            if prev_se != se or prev_mi != mi or prev_ho != ho:
                cur_t = str2Time(self.year(mo), mo, da, ho, mi, se)
                cur_t = cur_t - cur_t % rrdstep
                prev_mi = mi
                prev_ho = ho
                prev_se = se
            m = id_expr.match(log)
            if m:
                (line_id, line_log) = m.groups()

                m = re.search("message-id=<([^>]*)>", line_log)
                if m:
                    self.workdict[line_id] = {'from': m.group(1), 'size': 0}
                    continue

                m = re.search("from=<([^>]*)>, size=(\d+)", line_log)
                if m:
                    self.workdict[line_id] = {'from': m.group(1),
                                              'size': string.atoi(m.group(2))}
                    continue

                m = re.search("to=<([^>]*)>.*status=(\S+)", line_log)
                if m:
                    if not line_id in self.workdict:
                        if self.debug:
                            print "Inconsistent mail (%s: %s), skipping" % (line_id, m.group(1))
                        continue
                    if not m.group(2) in variables:
                        if self.debug:
                            print "Unsupported status %s, skipping" % m.group(2)
                        continue

                    addrfrom = re.match("([^@]+)@(.+)", self.workdict[line_id]['from'])
                    if addrfrom is not None and addrfrom.group(2) in self.domains:
                        self.inc_counter(addrfrom.group(2), cur_t, 'sent')
                        self.inc_counter(addrfrom.group(2), cur_t, 'size_sent',
                                         self.workdict[line_id]['size'])
                    addrto = re.match("([^@]+)@(.+)", m.group(1))
                    domname = addrto.group(2) if addrto is not None else None
                    if m.group(2) == "sent":
                        self.inc_counter(addrto.group(2), cur_t, 'recv')
                        self.inc_counter(addrto.group(2), cur_t, 'size_recv',
                                         self.workdict[line_id]['size'])
                    else:
                        self.inc_counter(domname, cur_t, m.group(2))
                    continue

                if self.debug:
                    print "Unknown line format: %s" % line_log
            else:
                m = re.match("NOQUEUE: reject: .*from=<(.*)> to=<([^>]*)>", log)
                if m:
                    addrto = re.match("([^@]+)@(.+)", m.group(2))
                    if addrto and addrto.group(2) in self.domains:
                        self.inc_counter(addrto.group(2), cur_t, 'reject')
                    continue
                if self.debug:
                    print "Unknown line format: %s" % log

        # Sort everything by time
        G = Grapher()
        for dom, data in self.data.iteritems():
            if self.debug:
                print "[rrd] dealing with domain %s" % dom
            for t in sorted(data.keys()):
                self.update_rrd(dom, t)

            for graph_tpl in MailTraffic().get_graphs():
                G.make_defaults(dom, graph_tpl)
Exemple #4
0
    def process(self):
        id_expr = re.compile("([0-9A-F]+): (.*)")
        prev_se = -1
        prev_mi = -1
        prev_ho = -1
        for line in self.f.readlines():
            m = self.line_expr.match(line)
            if not m:
                continue
            (mo, da, ho, mi, se, host, prog, pid, log) = m.groups()
            se = int(int(se) / rrdstep)  # rrd step is one-minute => se = 0

            if prev_se != se or prev_mi != mi or prev_ho != ho:
                cur_t = str2Time(self.year(mo), mo, da, ho, mi, se)
                cur_t = cur_t - cur_t % rrdstep
                prev_mi = mi
                prev_ho = ho
                prev_se = se
            m = id_expr.match(log)
            if m:
                (line_id, line_log) = m.groups()

                m = re.search("message-id=<([^>]*)>", line_log)
                if m:
                    self.workdict[line_id] = {"from": m.group(1), "size": 0}
                    continue

                m = re.search("from=<([^>]*)>, size=(\d+)", line_log)
                if m:
                    self.workdict[line_id] = {"from": m.group(1), "size": string.atoi(m.group(2))}
                    continue

                m = re.search("to=<([^>]*)>.*status=(\S+)", line_log)
                if m:
                    if not line_id in self.workdict:
                        if self.debug:
                            print "Inconsistent mail (%s: %s), skipping" % (line_id, m.group(1))
                        continue
                    if not m.group(2) in variables:
                        if self.debug:
                            print "Unsupported status %s, skipping" % m.group(2)
                        continue

                    addrfrom = re.match("([^@]+)@(.+)", self.workdict[line_id]["from"])
                    if addrfrom is not None and addrfrom.group(2) in self.domains:
                        self.inc_counter(addrfrom.group(2), cur_t, "sent")
                        self.inc_counter(addrfrom.group(2), cur_t, "size_sent", self.workdict[line_id]["size"])
                    addrto = re.match("([^@]+)@(.+)", m.group(1))
                    domname = addrto.group(2) if addrto is not None else None
                    if m.group(2) == "sent":
                        self.inc_counter(addrto.group(2), cur_t, "recv")
                        self.inc_counter(addrto.group(2), cur_t, "size_recv", self.workdict[line_id]["size"])
                    else:
                        self.inc_counter(domname, cur_t, m.group(2))
                    continue

                if self.debug:
                    print "Unknown line format: %s" % line_log
            else:
                m = re.match("NOQUEUE: reject: .*from=<(.*)> to=<([^>]*)>", log)
                if m:
                    addrto = re.match("([^@]+)@(.+)", m.group(2))
                    if addrto and addrto.group(2) in self.domains:
                        self.inc_counter(addrto.group(2), cur_t, "reject")
                    continue
                if self.debug:
                    print "Unknown line format: %s" % log

        # Sort everything by time
        G = Grapher()
        for dom, data in self.data.iteritems():
            if self.debug:
                print "[rrd] dealing with domain %s" % dom
            for t in sorted(data.keys()):
                self.update_rrd(dom, t)

            for graph_tpl in MailTraffic().get_graphs():
                G.make_defaults(dom, graph_tpl)