Log Analysis¶
Guide to analyzing Mailborder logs for troubleshooting and monitoring.
Log Locations¶
Main logs:
/var/log/mailborder/mailborder.log # General system log
/var/log/mailborder/auth.log # Authentication events
/var/log/mailborder/spam.log # Spam detection
/var/log/mailborder/virus.log # Virus scanning
/var/log/mailborder/policy.log # Policy enforcement
/var/log/mailborder/geoip.log # GeoIP filtering
/var/log/mail.log # Postfix SMTP log
Service logs:
/var/log/mailborder/mb-rpcd.log
/var/log/mailborder/mb-filter.log
/var/log/mailborder/mb-milter.log
/var/log/mailborder/mb-scribe.log
Common Log Searches¶
Find Errors¶
# All errors today
sudo grep ERROR /var/log/mailborder/*.log
# Specific service errors
sudo grep ERROR /var/log/mailborder/mb-filter.log | tail -n 20
# Critical errors only
sudo grep CRITICAL /var/log/mailborder/mailborder.log
Track Email¶
By message ID:
sudo grep "<message-id@sender.com>" /var/log/mail.log
sudo grep "<message-id@sender.com>" /var/log/mailborder/mb-filter.log
By sender:
By recipient:
Authentication Events¶
Failed logins:
Successful logins:
Account lockouts:
By IP address:
Spam Detection¶
High spam scores:
Rejected as spam:
False positives (released from quarantine):
Virus Detection¶
All virus detections:
By virus name:
Recent detections:
Log Analysis Tools¶
Using journalctl¶
View service logs:
sudo journalctl -u mb-rpcd
sudo journalctl -u mb-filter -n 100
sudo journalctl -u mb-filter -f # Follow
Time-based:
# Last hour
sudo journalctl -u mb-filter --since "1 hour ago"
# Today
sudo journalctl -u mb-rpcd --since today
# Specific date
sudo journalctl -u mb-filter --since "2025-01-13 00:00" --until "2025-01-13 23:59"
Priority filtering:
# Errors only
sudo journalctl -u mb-rpcd -p err
# Warnings and above
sudo journalctl -u mb-filter -p warning
Using grep¶
Count occurrences:
Most common errors:
sudo grep ERROR /var/log/mailborder/mailborder.log | \
cut -d':' -f4- | sort | uniq -c | sort -rn | head -n 10
Error frequency by hour:
sudo grep ERROR /var/log/mailborder/mailborder.log | \
awk '{print $1, $2}' | cut -d':' -f1 | uniq -c
Using awk¶
Extract specific fields:
# Spam scores
sudo awk '/spam score/ {print $NF}' /var/log/mailborder/spam.log | \
sort -n | tail -n 20
Calculate averages:
# Average spam score
sudo awk '/spam score/ {sum+=$NF; count++} END {print sum/count}' \
/var/log/mailborder/spam.log
Processing times:
# Average processing time
sudo awk '/Processing Time/ {sum+=$NF; count++} END {print sum/count "ms"}' \
/var/log/mailborder/mb-filter.log
Monitoring Patterns¶
Email Volume Trends¶
Emails per hour:
Spam ratio:
TOTAL=$(sudo grep "Verdict:" /var/log/mailborder/mb-filter.log | wc -l)
SPAM=$(sudo grep "Verdict: QUARANTINE\|Verdict: REJECT" /var/log/mailborder/mb-filter.log | wc -l)
echo "Spam rate: $(echo "scale=2; $SPAM/$TOTAL*100" | bc)%"
Performance Monitoring¶
Slow requests:
sudo grep "Processing Time" /var/log/mailborder/mb-filter.log | \
awk '$NF > 1000 {print}' | tail -n 20
# Shows requests > 1 second
Queue depth over time:
Security Monitoring¶
Brute force attempts:
sudo grep "Failed login" /var/log/mailborder/auth.log | \
awk '{print $(NF-2)}' | sort | uniq -c | sort -rn | head -n 10
# Shows IPs with most failed attempts
Blocked IPs:
Automated Log Analysis¶
Create Analysis Script¶
#!/bin/bash
# /usr/local/bin/analyze-logs.sh
echo "=== Mailborder Log Analysis ==="
echo "Date: $(date)"
echo
echo "Errors (last hour):"
sudo journalctl --since "1 hour ago" | grep -c ERROR
echo
echo "Email processed (last hour):"
sudo grep "Verdict:" /var/log/mailborder/mb-filter.log | \
grep "$(date +%Y-%m-%d) $(date +%H):" | wc -l
echo
echo "Spam caught (last hour):"
sudo grep "Verdict: QUARANTINE\|Verdict: REJECT" /var/log/mailborder/mb-filter.log | \
grep "$(date +%Y-%m-%d) $(date +%H):" | wc -l
echo
echo "Failed logins (last hour):"
sudo grep "Failed login" /var/log/mailborder/auth.log | \
grep "$(date +%Y-%m-%d) $(date +%H):" | wc -l
Schedule:
Log Aggregation¶
Using logwatch:
Custom Logwatch configuration:
Log Rotation¶
Check rotation config:
Example configuration:
/var/log/mailborder/*.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
create 0640 mailborder mailborder
sharedscripts
postrotate
systemctl reload mb-rpcd >/dev/null 2>&1 || true
endscript
}
Manual rotation:
Exporting Logs¶
For Support¶
Create support bundle:
sudo tar czf /tmp/mailborder-logs-$(date +%Y%m%d).tar.gz \
/var/log/mailborder/*.log \
/var/log/mail.log \
/var/log/syslog
Sanitize if needed:
# Remove sensitive email addresses
sed 's/[a-zA-Z0-9._%+-]\+@[a-zA-Z0-9.-]\+\.[a-zA-Z]\{2,\}/redacted@example.com/g' \
input.log > sanitized.log
For Analysis Tools¶
Export to CSV:
# Spam scores
sudo awk '/spam score/ {print $1, $2, $NF}' /var/log/mailborder/spam.log | \
sed 's/ /,/g' > spam-scores.csv
Export to JSON:
# Recent errors
sudo grep ERROR /var/log/mailborder/mailborder.log | \
tail -n 100 | jq -R 'split(" ") | {date: .[0], time: .[1], level: .[2], message: .[3:] | join(" ")}' | \
jq -s '.' > errors.json