Parsear logs de Qmail

Hace un par de semanas un compañero mio tuvo que analizar los logs del servidor de correo Qmail, para saber si ciertos correos concretos se habian enviado satisfactoriamente o no.
Al poco rato lo escuche quejarse de lo jodido que era mirar los logs del qmail, y que Postfix le daba mil vueltas ( para gustos colores =) ).

Al cabo de unas horas, se me ocurrió hacer una aplicación que parseara los logs del servidor y los formateara para mostarlos de una manera comprensible y amigable.

Así, de unos logs tipo:

Sep 26 07:01:59 localhost qmail: 1317013319.002026 info msg 498832: bytes 183926 from qp 30726 uid 0
Sep 26 07:01:59 localhost qmail: 1317013319.010598 starting delivery 3405: msg 498832 to remote xxxx@xxxxx
Sep 26 07:01:59 localhost qmail: 1317013319.010664 status: local 0/10 remote 1/20
Sep 26 07:02:01 localhost qmail: 1317013321.324740 starting delivery 3406: msg 498832 to remote xxxxx@xxxx
Sep 26 07:02:01 localhost qmail: 1317013321.324801 status: local 0/10 remote 2/20
Sep 26 07:02:06 localhost qmail: 1317013326.945589 delivery 3405: success: xxx.xxx.xx.xxx_accepted_message./Remote_host_said:_250_ok_dirdel/
Sep 26 07:02:06 localhost qmail: 1317013326.945678 status: local 0/10 remote 1/20
Sep 26 07:02:06 localhost qmail: 1317013326.945751 starting delivery 3407: msg 498832 to remote xxxxx@xxxx
Sep 26 07:02:06 localhost qmail: 1317013326.945822 status: local 0/10 remote 2/20
Sep 26 07:02:13 localhost qmail: 1317013333.920704 delivery 3406: success: xx.xx.xxx.xx_accepted_message./Remote_host_said:_250_ok_dirdel/
Sep 26 07:02:13 localhost qmail: 1317013333.920745 status: local 0/10 remote 1/20
Sep 26 07:02:13 localhost qmail: 1317013333.920770 new msg 498911
Sep 26 07:02:13 localhost qmail: 1317013333.920798 info msg 498911: bytes 11669 from qp 30812 uid 0
Sep 26 07:02:13 localhost qmail: 1317013333.930092 starting delivery 3408: msg 498911 to xxxxx@xxxxx
Sep 26 07:02:13 localhost qmail: 1317013333.930164 status: local 1/10 remote 1/20
Sep 26 07:02:30 localhost qmail: 1317013350.855134 status: local 0/10 remote 1/20
Sep 26 07:02:30 localhost qmail: 1317013350.855163 delivery 3407: success: xxx.xx.xxx.xx_accepted_message./Remote_host_said:_250_2.0.0_OK_1317013337_gb5si16548563wbb.23/
Sep 26 07:02:30 localhost qmail: 1317013350.855190 status: local 0/10 remote 0/20
Sep 26 07:02:42 localhost qmail: 1317013362.306631 new msg 498943
Sep 26 07:02:42 localhost qmail: 1317013362.306664 info msg 498943: bytes 11860 from qp 30822 uid 64020
Sep 26 07:02:42 localhost qmail: 1317013362.314473 starting delivery 3409: msg 498943 to local xxxxx-xxxx@xxxxx
Sep 26 07:02:42 localhost qmail: 1317013362.314537 status: local 1/10 remote 0/20
Sep 26 07:02:44 localhost qmail: 1317013364.497246 end msg 498911

Podemos pasarlo a:

[+] Msgid: 498832
[+] Hour: 07:01:59
[+] From: xxxxx@xx.xxxx.xxx
    [+] Delivery id: 3405
    [+] To: xxxx@xxxx.xxx
    [+] Delivery id: 3406
    [+] To: xxxxxx@xxxx.xxx
    [+] Delivery id: 3407
    [+] To: xxxxx@xxxx.xxx

Aquí podeis encontrar el codigo: http://paste.ideaslabs.com/show/gLYkHGrC5R

Quede claro que esto no pretende ser la panacea, y que lo he hecho solo por curiosidad y ganas.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">