DMARC-Reports erstellen 1


Nach dem DMARC-Records anhand des DMARC-Check unter Debian Wheezy überprüft werden, spricht nichts dagegen, auch selbst daraus Reports zu erstellen und zu verschicken.

Als erstes brauchen wir eine mysql-Datenbank und einen User, um die DMARC-Checks zu speichern. Mysql aufrufen und dann:

CREATE DATABASE opendmarc;
CREATE USER 'opendmarc'@'127.0.0.1' IDENTFIED BY 'top_secret';
GRANT ALL PRIVILEGES ON opendmarc.* TO 'opendmarc'@'127.0.0.1' IDENTIFIED BY 'top_secret';
FLUSH PRIVILEGES;
quit;

Danach wird die Struktur für die Tabelle erzeugt:

mysql opendmarc -u opendmarc_user -ptop_secret < /usr/share/doc/opendmarc/mkdb.mysql

Ich habe ein einfaches Script, dass über Cronjobs die Daten in die Datenbank import, daraus einmal am Tag die Reports erstellt und Einträge löscht, die älter als 90 Tage sind.
Die Variablen müssen nur gesetz werden, wenn sie von den Defaultwerten abweichen (bspw. anderer SQL-User oder ein remote-Server).

#!/bin/bash
# Script to create DMARC reports
#
# Created: 12/03/2014
# Version: 1.0
# Author: Florian Schaal (info@schaal-24.de)
#
# Copyright (c) 2014 Florian Schaal (info@schaal-24.de.)
# All rights reserved.
#
# This script is free software
# you can redistribute it and/or modify it under
# the terms of the GNU General Public License.
# See http://www.fsf.org/licensing/licenses/gpl.html
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY;
# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

DAT_FILE=/var/run/opendmarc/opendmarc.dat

REPORT_EMAIL=dmarc-report@schaal-24.de
REPORT_DIR=/root/dmarc-reports

export OPENDMARC_DBHOST=db.local # default localhost
export OPENDMARC_DB=opendmarc # default opendmarc
export OPENDMARC_PASSWORD=secret # default opendmarc
export OPENDMARC_USER=opendmarc # default opendmarc

case $1 in
import)
if [ -e $DAT_FILE ]; then
/usr/sbin/opendmarc-import < $DAT_FILE &> /dev/null
fi
;;
report)
if [ ! -d "$REPORT_DIR" ]; then mkdir -p $REPORT_DIR; fi
cd $REPORT_DIR
/usr/sbin/opendmarc-reports --day --keepfiles --verbose --report-email $REPORT_EMAIL
;;
expire)
/usr/sbin/opendmarc-expire --expire=90
;;
*)
echo use "import", "report" or "expire"
;;
esac

Und im Crontab sieht das so aus:

# dmarc
0 */2 * * * /root/scripts/dmarc.sh import
15 0 * * * /root/scripts/dmarc.sh report
0 1 * * * /root/scripts/dmarc.sh expire


Hinterlasse einen Kommentar zu PChott Antworten abbrechen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Ein Gedanke zu “DMARC-Reports erstellen

  • PChott

    Great script. Thank you.

    I only have little problem, that in reports in “org_name” is addint “.net”. Any idea with which variable can I set that?