techsneeze / dmarcts-report-parser

A Perl based tool to parse DMARC reports from an IMAP mailbox or from the filesystem, and insert the information into a database. ( Formerly known as imap-dmarcts )
http://www.techsneeze.com/how-parse-dmarc-reports-imap/
GNU General Public License v3.0
224 stars 65 forks source link

Cannot connect to database #56

Closed benscha closed 6 years ago

benscha commented 6 years ago

Hi techsneeze

i have some issues with the script. my DB is working and i can connect with my credentials.

mysql -h localhost -u dmarc -p dmarc

if i run the script like this

./dmarcts-report-parser.pl -x /tmp/dmarc/emailsrvr.com\!domain.com\!1531094400\!1531180800\!5074c731-3737-4597-8977-5af1717fb902.xml

i receive the following error:

DBI connect('database=dmarc;host=localhost','dmarc',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at ./dmarcts-report-parser.pl line 220.

this is the content of my dmarcts-report-parser.conf


################################################################################
### configuration ##############################################################
################################################################################

# If IMAP access is not used, config options starting with $imap do not need to
# be set and are ignored.

$debug = 1;
$delete_reports = 0;

$dbname = 'dmarc';
$dbuser = 'dmarc';
$dbpass = 'my_pass';
$dbhost = 'localhost'; # Set the hostname if we can't connect to the local socket.

$imapserver       = 'mail.example.com:143';
$imapuser         = 'dmarcreports';
$imappass         = 'xxx';
$imapssl          = '0';        # If set to 1, remember to change server port to 993 and disable imaptls.
$imaptls          = '1';        # Enabled as the default and best-practice.
$tlsverify        = '1';        # Enable verify server cert as the default and best-practice.
$imapignoreerror  = 0;          # set it to 1 if you see an "ERROR: message_string() 
                                # expected 119613 bytes but received 81873 you may 
                                # need the IgnoreSizeErrors option" because of malfunction
                                # imap server as MS Exchange 2007, ...
$imapreadfolder   = 'Inbox';

# If $imapmovefolder is set, processed IMAP messages will be moved (overruled by
# the --delete option!)
$imapmovefolder = 'Inbox.processed';

# maximum size of XML files to store in database, long files can cause transaction aborts
$maxsize_xml = 50000;
# store XML as base64 encopded gzip in database (save space, harder usable)
$compress_xml = 0;

# if there was an error during file processing (message does not contain XML or ZIP parts, 
# or a database error) the parser reports an error and does not delete the file, even if 
# delete_reports is set (or --delete is given). Deletion can be enforced by delete_failed, 
# however not for database errors.
$delete_failed = 0;

do you have any hints for me, where the misconfig could be?

thx

lwt-pressy commented 6 years ago

$dbhost = 'localhost'; # Set the hostname if we can't connect to the local socket.

if you use 'localhost' the perl units will connect through the local socket ('/var/run/mysqld/mysqld.sock' in your case). the mysql will always connect through port. So check the socket is it present and are the file rights correct.

benscha commented 6 years ago

thx for this SUPERFAST Solution! that fix did it!

lwt-pressy commented 6 years ago

@techsneeze or @benscha - can you close this?