initial commit

This commit is contained in:
BeauTroll
2025-12-16 04:41:26 +01:00
commit 2b048a09e1
16 changed files with 1719 additions and 0 deletions

110
scripts/test-notifications.sh Executable file
View File

@@ -0,0 +1,110 @@
#!/bin/bash
#
# Script de test des notifications ntfy
# Usage: ./test-notifications.sh
#
# Couleurs
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Charger les variables d'environnement
if [ -f /etc/borgmatic/.env ]; then
source /etc/borgmatic/.env
elif [ -f .env ]; then
source .env
else
echo -e "${RED}❌ Fichier .env non trouvé${NC}"
echo "Créez un fichier .env avec NTFY_URL et NTFY_USER"
exit 1
fi
if [ -z "$NTFY_URL" ]; then
echo -e "${RED}❌ NTFY_URL non défini dans .env${NC}"
exit 1
fi
echo -e "${BLUE}==================================================${NC}"
echo -e "${BLUE}Test des notifications ntfy${NC}"
echo -e "${BLUE}==================================================${NC}"
echo ""
echo -e "${YELLOW}Configuration:${NC}"
echo " URL: $NTFY_URL"
echo " Auth: $([ -n "$NTFY_USER" ] && echo "✅ Configurée" || echo "❌ Non configurée")"
echo ""
# Test 1: Notification simple
echo -e "${YELLOW}📤 Test 1: Notification simple...${NC}"
RESPONSE=$(curl -s -w "\n%{http_code}" -u "$NTFY_USER" \
-H "Title: Test Borgmatic" \
-H "Priority: default" \
-H "Tags: test" \
-d "Ceci est un test de notification depuis le script de configuration Borgmatic" \
"$NTFY_URL")
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
if [ "$HTTP_CODE" -eq 200 ]; then
echo -e "${GREEN}✅ Notification simple envoyée avec succès${NC}"
else
echo -e "${RED}❌ Échec (HTTP $HTTP_CODE)${NC}"
echo "$RESPONSE"
exit 1
fi
sleep 2
# Test 2: Notification de succès (simule un backup réussi)
echo -e "${YELLOW}📤 Test 2: Notification de succès de backup...${NC}"
RESPONSE=$(curl -s -w "\n%{http_code}" -u "$NTFY_USER" \
-H "Title: ✅ Backup réussi" \
-H "Priority: default" \
-H "Tags: white_check_mark,backup" \
-d "Test de notification de succès
Archive: test-backup-$(date +%Y%m%d-%H%M)
Date: $(date '+%Y-%m-%d %H:%M:%S')
Taille: 15.2 GB" \
"$NTFY_URL")
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
if [ "$HTTP_CODE" -eq 200 ]; then
echo -e "${GREEN}✅ Notification de succès envoyée avec succès${NC}"
else
echo -e "${RED}❌ Échec (HTTP $HTTP_CODE)${NC}"
exit 1
fi
sleep 2
# Test 3: Notification d'erreur (simule un backup échoué)
echo -e "${YELLOW}📤 Test 3: Notification d'erreur de backup...${NC}"
RESPONSE=$(curl -s -w "\n%{http_code}" -u "$NTFY_USER" \
-H "Title: ❌ Backup échoué" \
-H "Priority: high" \
-H "Tags: x,backup,alert" \
-d "Test de notification d'erreur
Erreur: Ceci est un test - pas de vraie erreur !
Date: $(date '+%Y-%m-%d %H:%M:%S')
Vérifiez les logs: journalctl -u borgmatic.service -n 50" \
"$NTFY_URL")
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
if [ "$HTTP_CODE" -eq 200 ]; then
echo -e "${GREEN}✅ Notification d'erreur envoyée avec succès${NC}"
else
echo -e "${RED}❌ Échec (HTTP $HTTP_CODE)${NC}"
exit 1
fi
echo ""
echo -e "${GREEN}==================================================${NC}"
echo -e "${GREEN}✅ Tous les tests de notification ont réussi !${NC}"
echo -e "${GREEN}==================================================${NC}"
echo ""
echo "Vérifiez que vous avez reçu 3 notifications sur votre appareil:"
echo " 1. Notification de test simple"
echo " 2. Notification de succès de backup"
echo " 3. Notification d'erreur de backup"
echo ""