From f716963be8d5c8ad8061361cff57a874389317e9 Mon Sep 17 00:00:00 2001 From: Jonathan Rosenbaum Date: Thu, 18 Jun 2026 02:20:39 -0400 Subject: [PATCH] Catch email lists with 0 subscribers, and send an alert email. --- automation/run-subscription.sh | 84 ++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/automation/run-subscription.sh b/automation/run-subscription.sh index 2af423a..2c3546f 100755 --- a/automation/run-subscription.sh +++ b/automation/run-subscription.sh @@ -42,6 +42,83 @@ error_exit() { exit 1 } +# Send aggregated alert email for zero members or zero success +send_zero_member_alert() { + if [ -z "$EMAIL_TO" ] || [ -z "$SMTP_HOST" ]; then + return + fi + + local subject="LWVWV Subscription Alert: Issues Detected" + local body="WARNING: The LWVWV subscription process encountered issues. + +================================ +SUBSCRIPTION SUMMARY +================================ +Total Lists Processed: ${#LIST_CONFIGS[@]} +Successful: $SUCCESS_COUNT +Failed: ${#FAILED_LISTS[@]} +Lists with 0 Members: ${#ZERO_MEMBER_LISTS[@]} + +================================ +LISTS WITH 0 MEMBERS FOUND +================================" + + if [ ${#ZERO_MEMBER_LISTS[@]} -gt 0 ]; then + for list_info in "${ZERO_MEMBER_LISTS[@]}"; do + body="$body + - $list_info" + done + else + body="$body + (None)" + fi + + if [ ${#FAILED_LISTS[@]} -gt 0 ]; then + body="$body + +================================ +FAILED LISTS +================================" + for list_id in "${FAILED_LISTS[@]}"; do + body="$body + - $list_id" + done + fi + + body="$body + +================================ +TROUBLESHOOTING +================================ +This may indicate: +- CSV format issues (e.g., UTF-8 BOM in column headers) +- Missing data in the portal +- Filter configuration problems +- Connector API issues + +Please check: +1. The roster CSV file format +2. Portal data availability +3. League ID filters in configuration +4. Connector service status + +================================ +Roster File: $ROSTER_FILE +Timestamp: $(date) +================================" + + # Send email using s-nail with SMTP configuration + echo "$body" | s-nail -r "$EMAIL_FROM" \ + -s "$subject" \ + -S smtp="$SMTP_HOST:$SMTP_PORT" \ + -S smtp-use-starttls \ + -S smtp-auth="$SMTP_AUTH" \ + -S smtp-auth-user="$SMTP_USER" \ + -S smtp-auth-password="$SMTP_PASSWORD" \ + -S ssl-verify="${SSL_VERIFY_IGNORE:-ignore}" \ + "$EMAIL_TO" 2>/dev/null || log "Failed to send alert email" +} + # Create work directory mkdir -p "$WORK_DIR" @@ -111,6 +188,7 @@ log "==========================================" # Track success/failure per list SUCCESS_COUNT=0 FAILED_LISTS=() +ZERO_MEMBER_LISTS=() # Track lists that had 0 members found # Helper function to increment counter (avoids set -e issues with arithmetic) increment_count() { @@ -154,6 +232,7 @@ for CONFIG in "${LIST_CONFIGS[@]}"; do if [ "$MEMBER_COUNT" -eq 0 ]; then log "⚠ No members found for League ID $LEAGUE_ID, skipping $LIST_ID" + ZERO_MEMBER_LISTS+=("$LIST_ID (League: $LEAGUE_ID)") rm -f "$FILTERED_CSV" continue fi @@ -189,6 +268,11 @@ if [ -z "$1" ] && [ -f "$ROSTER_FILE" ]; then rm -f "$ROSTER_FILE" fi +# Check if we need to send alert (0 members found for any list, or 0 successful subscriptions) +if [ ${#ZERO_MEMBER_LISTS[@]} -gt 0 ] || [ $SUCCESS_COUNT -eq 0 ]; then + send_zero_member_alert +fi + # If any lists failed, report error if [ ${#FAILED_LISTS[@]} -gt 0 ]; then error_exit "Failed to subscribe to the following list(s): ${FAILED_LISTS[*]}"