This commit is contained in:
2025-08-17 12:40:37 -03:00
parent 7016ced89e
commit 7520d70ce9
2 changed files with 82 additions and 5 deletions

45
haven-notify/README.md Normal file
View File

@@ -0,0 +1,45 @@
# Haven Notify
## Overview
Haven Notify is an internal service designed to send notifications to a specified Discord channel.
It is built in Go and can be deployed as a container or managed service.
## Prerequisites
- Go 1.18 or newer (for local development)
- Docker (for containerized deployment)
- Discord Webhook URL
## API Specification
### Send Notification
- **Endpoint**: `/notify`
- **Method**: `POST`
- **Request Body**:
```json
{
"title": "Notification Title",
"message": "Notification Message"
}
```
## Setup & Usage
### Docker
1. Build the Docker image:
```sh
docker build -t haven-notify .
```
2. Run the container:
```sh
docker run -e WEBHOOK_URL=your_webhook_url haven-notify
```
### Kubernetes
Deployment manifest is available at `deploy/haven-notify.yaml`.
1. Edit the manifest to set your environment variables.
2. Create a generic secret named `WEBHOOK_URL` with `discord-webhook=your_webhook_url`
3. Apply deployment:
```sh
kubectl apply -f deploy/haven-notify.yaml
```

View File

@@ -4,18 +4,41 @@ $7zipPath = "$env:ProgramFiles\7-Zip\7z.exe"
if (!(Test-Path "$env:ProgramFiles\7-Zip\7z.exe")) {
Write-Host "7-Zip is not installed. Please install it to use this script."
exit 1
Send-Notify "❌ 7-Zip is not installed. Backup aborted."
}
$BackupSource = @(
"$env:USERPROFILE\Documents",
"$env:USERPROFILE\Desktop",
"$env:USERPROFILE\Pictures"
"$env:USERPROFILE\Pictures",
"$env:USERPROFILE\.ssh",
"$env:USERPROFILE\.kube"
)
$NASDestination = "\\OMV\Backup\$env:COMPUTERNAME"
$TempDir = "$env:TEMP\BackupTemp"
$Date = Get-Date -Format "yyyy-MM-dd"
$NotifyUrl = "http://notify.haven/notify"
function Send-Notify {
param (
[string]$Message
)
if (-not $NotifyUrl) {
Write-Host "NOTIFY_URL environment variable is not set. Notification not sent."
return
}
$Title = "Backup - $env:COMPUTERNAME"
$Body = @{ title = $Title; message = $Message } | ConvertTo-Json
try {
Invoke-RestMethod -Uri $NotifyUrl -Method Post -ContentType 'application/json' -Body $Body | Out-Null
Write-Host "Notification sent: $Title - $Message"
} catch {
Write-Host "Failed to send notification: $_"
}
}
# Create temp directory
New-Item -ItemType Directory -Path $TempDir -Force
@@ -30,18 +53,26 @@ foreach ($Folder in $BackupSource) {
$ZipFile = "$TempDir\$FolderName-$Date.zip"
Write-Host "Compressing $Folder..."
& "$7zipPath" a -tzip "$ZipFile" "$Folder\*" -mx=9
$compressResult = & "$7zipPath" a -tzip "$ZipFile" "$Folder\*" -mx=9
if ($LASTEXITCODE -ne 0) {
Write-Host "Compression failed for $Folder."
Send-Notify "❌ Compression failed for $Folder."
continue
}
Write-Host "Copying $ZipFile to NAS..."
Copy-Item $ZipFile $NASDestination -Force
Write-Host "Removing $ZipFile..."
Remove-Item $ZipFile
} else {
Write-Host "Source folder not found: $Folder"
Send-Notify "⚠️ Source folder not found: $Folder"
}
}
Write-Host "Removing Files older than 15 days from $NASDestination..."
$OldFiles = Get-ChildItem -Path $NASDestination -File | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-15) }
Write-Host "Removing Files older than 7 days from $NASDestination..."
$OldFiles = Get-ChildItem -Path $NASDestination -File | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) }
foreach ($OldFile in $OldFiles) {
Remove-Item $OldFile.FullName -Force
Write-Host "Removed: $($OldFile.FullName)"
@@ -49,4 +80,5 @@ foreach ($OldFile in $OldFiles) {
# Cleanup
Remove-Item $TempDir -Recurse -Force
Write-Host "Backup completed!"
Write-Host "Backup completed!"
Send-Notify "✅ Backup completed successfully."