Files
ncore-hnr/README.md
Zsolt Alföldi 89835b237c Add retry mechanism and failure notifications for nCore/qBittorrent setup
- Implemented a retry mechanism for external calls, allowing up to 3 attempts before failing.
- Enhanced error handling to send failure notifications when setup steps fail, including detailed error messages.
- Updated RunSummary model to include status, error step, and error message fields for better tracking of run outcomes.
- Modified database schema to store failure metadata for runs.
- Updated README.md to reflect changes in error handling and notification behavior.
2026-05-07 12:03:00 +02:00

3.5 KiB

ncore-hnr

Go app for checking nCore hit'n'run-risk torrents, force-starting matching qBittorrent torrents, and tracking state in SQLite.

Configuration

Put local config in .env:

NCORE_USERNAME='your-ncore-username'
NCORE_PASSWORD='your-ncore-password'

QBITTORRENT_URL='http://localhost:8080'
QBITTORRENT_USERNAME='admin'
QBITTORRENT_PASSWORD='your-qbit-password'

APP_DB_PATH='data/ncore-hnr.sqlite'
DRY_RUN='false'
ALERT_AFTER='48h'

# Optional notifications: set NOTIFICATION_TYPE to 'ntfy' or 'smtp'.
NOTIFICATION_DRY_RUN='false'
NOTIFICATION_TYPE=''

NOTIFICATION_NTFY_URL=''

NOTIFICATION_SMTP_HOST=''
NOTIFICATION_SMTP_PORT='587'
NOTIFICATION_SMTP_USERNAME=''
NOTIFICATION_SMTP_PASSWORD=''
NOTIFICATION_SMTP_FROM=''
NOTIFICATION_SMTP_TO=''

DRY_RUN=false is the default and will call qBittorrent setForceStart and reannounce. Use --dry-run=true when you only want to preview matches.

Use --notification-dry-run=true to print the manual-needed notification subject/body without sending it.

Set NOTIFICATION_TYPE=ntfy and NOTIFICATION_NTFY_URL='https://ntfy.sh/your-secret-topic' to send manual-needed alerts through ntfy. For compatibility, old NOTIFY_URL values still work as the ntfy URL.

Set NOTIFICATION_TYPE=smtp to send manual-needed alerts by email. For Gmail, use:

NOTIFICATION_SMTP_HOST='smtp.gmail.com'
NOTIFICATION_SMTP_PORT='587'
NOTIFICATION_SMTP_USERNAME='youraddress@gmail.com'
NOTIFICATION_SMTP_PASSWORD='your-gmail-app-password'
NOTIFICATION_SMTP_FROM='ncore <youraddress@gmail.com>'
NOTIFICATION_SMTP_TO='target@example.com'

External calls are retried 3 times before the run fails. Failed nCore/qBittorrent setup steps send a failure notification and record a failed run, but they do not mark missing torrents as resolved because the current HnR state is unknown.

Run

go run ./cmd/ncore-hnr

Preview without qBittorrent actions:

go run ./cmd/ncore-hnr --dry-run=true

Preview the notification body without sending it:

go run ./cmd/ncore-hnr --dry-run=true --alert-after=0s --notification-dry-run=true

JSON output:

go run ./cmd/ncore-hnr --json

SQLite Views

Show aggregate statistics and the latest run:

go run ./cmd/ncore-hnr stats

Show tracked torrent status rows:

go run ./cmd/ncore-hnr status

Both read-only commands support JSON and a custom DB path:

go run ./cmd/ncore-hnr status --json
go run ./cmd/ncore-hnr stats --db data/ncore-hnr.sqlite

Docker

docker build -t ncore-hnr:local .
docker run --rm --env-file .env -v "$PWD/data:/data" ncore-hnr:local

Build and push to Docker Hub with a tag in the form shortgitsha-epoch:

make docker-publish

Build and push the shell-capable debug image:

make docker-debug-publish

Kubernetes

The k8s/ folder contains a CronJob, PVC, and example Secret. Store real secrets out of git.

For the Flux deployment, create or update the Kubernetes Secret from your local .env without committing the secret values:

kubectl -n media-server create secret generic ncore-hnr-secrets \
  --from-env-file=.env \
  --dry-run=client -o yaml | kubectl apply -f -

Create a temporary debug pod manually:

kubectl apply -f k8s/debug-pod.yaml
kubectl -n media-server exec -it ncore-hnr-debug -- sh

Inside the pod:

ncore-hnr --dry-run=true --notification-dry-run=true --alert-after=0s

Remove the debug pod when finished:

kubectl -n media-server delete pod ncore-hnr-debug