send_report() {
local args=( "$@" )
- local address
# Add the email sender
if [ -n "${CONFIG[EMAIL_SENDER]}" ]; then
return 2
fi
- local IFS=','
-
- # Append the email recipients
- for address in ${CONFIG[EMAIL_RECIPIENTS]}; do
- args+=( "--email-recipient=${address}" )
- done
-
# Generate the report
if ! suricata-report-generator "${args[@]}"; then
return 1
local m="$(date --date="last month" +"%m")"
# Send the report
- send_report --year="${y}" --month="${m}"
+ send_report --year="${y}" --month="${m}" $(fetch_recipients monthly)
}
send_weekly_report() {
local w="$(date --date="last week" +"%V")"
# Send the report
- send_report --year="${y}" --week="${w}"
+ send_report --year="${y}" --week="${w}" $(fetch_recipients weekly)
}
# Sends a daily report for "yesterday"
local d="$(date --date="yesterday" +"%d")"
# Send the report
- send_report --year="${y}" --month="${m}" --day="${d}"
+ send_report --year="${y}" --month="${m}" --day="${d}" $(fetch_recipients daily)
+}
+
+fetch_recipients() {
+ local interval="${1}"
+
+ local recipients="${CONFIG[EMAIL_RECIPIENTS_REPORT_${interval^^}]:-${CONFIG[EMAIL_RECIPIENTS]}}"
+
+ # Parse this as an array
+ read -ra recipients <<< "${recipients//,/ }"
+
+ # Return all recipients
+ local recipient
+ for recipient in ${recipients[@]}; do
+ echo "--email-recipient=${recipient}"
+ done
+
+ return 0
}
main() {