|
35 | 35 |
|
36 | 36 | # !!! change version upon update !!! |
37 | 37 | global VERSION |
38 | | -VERSION ="1.1.7.2" |
| 38 | +VERSION ="1.1.7.3" |
39 | 39 |
|
40 | 40 | # postfix regexp |
41 | 41 | postf_match = r'([A-Za-z]+[ \t]+[0-9]+[ \t]+[0-9]+\:[0-9]+:[0-9]+).*' |
42 | 42 | """(0) Regex to match the Date/Time at the start of each log line""" |
43 | | -postf_match += r'([A-F0-9]{11})\:[ \t]+?(.*)' |
| 43 | +# postf_match += r'([A-F0-9]{11})\:[ \t]+?(.*)' |
| 44 | +postf_match += r'\:[ \t]([A-F0-9]{1,15})\:[ \t]+?(.*)' |
44 | 45 | """Regex to match the (1) Queue ID and the (2) Log Message""" |
45 | 46 |
|
46 | 47 | # exim regexp (for syslog and separate mainlog) |
@@ -144,40 +145,45 @@ async def import_log(logfile: str) -> Dict[str, PostfixMessage]: |
144 | 145 | # avoid utf-8 codec error |
145 | 146 | with open(logfile, 'rb') as f: |
146 | 147 | while True: |
| 148 | + |
147 | 149 | line = f.readline().decode(errors='replace') |
148 | 150 | if not line: break |
149 | 151 |
|
150 | 152 | m = match.match(line) |
| 153 | + |
151 | 154 | if not m: continue |
152 | 155 |
|
153 | 156 | dtime, qid, msg = m.groups() |
154 | 157 | """Thu Mar 09 2023 14:13:35 GMT+00:00 ---- '%a %b %d %Y %H:%M:%S %Z' """ |
155 | 158 | """Mar 13 10:57:04 |
156 | 159 | dtime = datetime.strptime(dtime, '%b %d %H:%M:%S').replace(year=datetime.today().year).strftime('%d.%m.%Y-%H:%M:%S') |
157 | 160 | print("New time stamp: "+ dtime)""" |
| 161 | + #log.info(m) |
158 | 162 | #print("m.groups[1]: ",m.groups()[1])# - queue_id |
159 | 163 | #print("m.groups[2]: ",m.groups()[2])# - message |
160 | 164 | # merge multiple mail_to strings into one for the one queue_id |
161 | 165 |
|
162 | 166 | #m['mail_to'] += ", "+recipients |
163 | 167 | #print("mail_to: ",m['mail_to']) |
164 | | - |
| 168 | + #print("mail_to: ",m['mail_to']) |
165 | 169 | if qid not in messages: |
166 | 170 | messages[qid] = PostfixMessage(timestamp=dtime, queue_id=qid) |
167 | 171 | messages[qid].merge(await parse_line(msg)) |
168 | | - |
169 | | - cheking_mailto = messages[qid]['mail_to'] |
| 172 | + #print(messages[qid]) |
| 173 | + #print(msg) |
| 174 | + checking_mailto = messages[qid]['mail_to'] |
170 | 175 | if qid not in set(multiple_recipients): |
171 | | - if qid == same_qid or same_qid=='': |
| 176 | + if qid == same_qid or same_qid == '': |
172 | 177 | if messages[qid]['status'].get('code') is not None: |
173 | | - # check if there are already recipients in message |
174 | | - #print("Looking for ",cheking_mailto," in message '",msg, "' related to qid ", qid) |
175 | | - if cheking_mailto in msg: |
176 | | - same_qid = qid |
177 | | - counter += 1 |
| 178 | + # check if there are already recipients in message and there are recipients parsed |
| 179 | + #print("Looking for ",checking_mailto," in message \"",msg, "\" related to qid ", qid) |
| 180 | + if checking_mailto != '': |
| 181 | + if checking_mailto in msg: |
| 182 | + same_qid = qid |
| 183 | + counter += 1 |
178 | 184 | else: |
179 | 185 | #print("New message ID: ", qid) |
180 | | - #print("There are ", counter," recipients in message ",same_qid) |
| 186 | + #print("There are", counter,"recipients in message id",same_qid) |
181 | 187 | if counter > 1: |
182 | 188 | multiple_recipients.append(same_qid) |
183 | 189 | counter = 0 |
@@ -239,6 +245,7 @@ async def main(): |
239 | 245 | r, conn, r_q = await get_rethink() |
240 | 246 | r_q: rethinkdb.query |
241 | 247 | """housekeeping from old logs""" |
| 248 | + |
242 | 249 | housekeeping_days = settings.housekeeping_days |
243 | 250 | if housekeeping_days != '': |
244 | 251 | log.info('Start housekeeping') |
@@ -301,7 +308,7 @@ async def main(): |
301 | 308 | continue |
302 | 309 | # check if there are many recipients |
303 | 310 | if m.get('id') in set(multiple_recipients): |
304 | | - #print("There multiple recipients in ",m.get('id')) |
| 311 | + print("There multiple recipients in ",m.get('id')) |
305 | 312 | m['mail_to'] += " and more (check log lines)" |
306 | 313 | m['status']['code'] = 'multiple' |
307 | 314 | m['status']['message'] = 'multiple, see log lines below' |
|
0 commit comments