4 Commits

Author SHA1 Message Date
kelly fe4886a305 Merge pull request 'implementing better error handling' (#2) from v0.2 into main
Reviewed-on: #2
2026-05-04 21:40:28 -05:00
kelly 32400d8413 implementing better error handling 2026-05-04 16:45:35 -05:00
kelly e56b2027cd updated to have apprise as a notification option 2026-04-29 21:14:40 -05:00
Kelly Thomas Reardon 327cb22bfd Merge pull request #1 from blinkfink182/v0.1
v0.1
2024-09-02 10:22:26 -05:00
2 changed files with 74 additions and 24 deletions
+70 -23
View File
@@ -5,6 +5,58 @@
[string] $qbtUser = $ENV:QBTUSER
[string] $qbtPassword = $ENV:QBTPASSWORD
[string] $notificationWebhookURL = $ENV:NOTIFICATIONWEBHOOKURL
[string] $discordWebhookURL = $ENV:DISCORDWEBHOOKURL
[string] $appriseWebhookURL = $ENV:APPRISEWEBHOOKURL
[string] $appriseWebhookTag = $ENV:APPRISEWEBHOOKTAG
function Send-Notification
{
param(
# Content of the notification
[Parameter(Mandatory=$true)]
[string]
$content
)
if ($notificationWebhookURL -or $discordWebhookURL)
{
if ($discordWebhookURL) { $notificationWebhookURL = $discordWebhookURL }
$headers = @{
"Content-Type"="application/json"
}
$body = @{
content=$content
# content="QBitTorrent Listening Port updated to $gluetunForwardedPort"
}
$json = $body | ConvertTo-Json
try {
Invoke-WebRequest -URI $notificationWebhookURL -Method post -Body $json -Headers $headers
}
catch {
Write-Host "Notification Error Encountered: $($global:Error[0])"
}
}
elseif ($appriseWebhookURL)
{
$headers = @{
"Content-Type"="application/json"
}
$body = @{
title="QBitTorrent Port Manager"
body=$content
# body="QBitTorrent Listening Port updated to $gluetunForwardedPort"
tags="$appriseWebhookTag"
}
$json = $body | ConvertTo-Json
try {
Invoke-WebRequest -URI $appriseWebhookURL -Method post -Body $json -Headers $headers
}
catch {
Write-Host "Notification Error Encountered: $($global:Error[0])"
}
}
}
while ($true)
{
@@ -18,32 +70,27 @@ while ($true)
username = $qbtUser
password = $qbtPassword
}
$qbtSession = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
$qbtResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/auth/login" -WebSession $qbtSession -Method POST -Headers $qbtHeaders -Body $qbtBody
try {
$qbtSession = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
$qbtResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/auth/login" -WebSession $qbtSession -Method POST -Headers $qbtHeaders -Body $qbtBody
$qbtQueryResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/app/preferences" -WebSession $qbtSession -Method GET
$qbtListenPort = (ConvertFrom-Json $qbtQueryResponse.Content).listen_port
Write-Host "Current QBT Listening port: $qbtListenPort"
$qbtQueryResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/app/preferences" -WebSession $qbtSession -Method GET
$qbtListenPort = (ConvertFrom-Json $qbtQueryResponse.Content).listen_port
Write-Host "Current QBT Listening port: $qbtListenPort"
if ($gluetunForwardedPort -eq $qbtListenPort)
{
Write-Host "Ports match!"
}
else
{
$qbtPortChangeBody = 'json={"listen_port":' + $gluetunForwardedPort + '}'
$qbtPortChangeResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/app/setPreferences" -WebSession $qbtSession -Method POST -Headers $qbtHeaders -Body $qbtPortChangeBody
if ($notificationWebhookURL)
if ($gluetunForwardedPort -eq $qbtListenPort)
{
$headers = @{
"Content-Type"="application/json"
}
$body = @{
content="QBitTorrent Listening Port updated to $gluetunForwardedPort"
}
$json = $body | ConvertTo-Json
Invoke-WebRequest -URI $notificationWebhookURL -Method post -Body $json -Headers $headers
Write-Host "Ports match!"
}
else
{
$qbtPortChangeBody = 'json={"listen_port":' + $gluetunForwardedPort + '}'
$qbtPortChangeResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/app/setPreferences" -WebSession $qbtSession -Method POST -Headers $qbtHeaders -Body $qbtPortChangeBody
Send-Notification -content "QBitTorrent Listening Port updated to $gluetunForwardedPort"
}
}
catch {
Write-Host "Error encountered: $($global:Error[0])"
Send-Notification -content "Error encountered: $($global:Error[0])"
}
Write-Host "Sleeping for $schedule minutes..."
Start-Sleep ($schedule * 60)
+4 -1
View File
@@ -10,6 +10,9 @@ services:
- QBTPORT=8787 # qbittorrent port
- QBTUSER=admin # qbittorrent webUI username
- QBTPASSWORD=adminpass # qbittorrent webUI password
- NOTIFICATIONWEBHOOKURL=https://discord.com/api/webhooks/<webhookURL> # discord notification wehook URL
#- NOTIFICATIONWEBHOOKURL=https://discord.com/api/webhooks/<webhookURL> # DEPRECATED discord notification wehook URL
#- DISCORDWEBHOOKURL=https://discord.com/api/webhooks/<webhookURL> # discord notification wehook URL
#- APPRISEWEBHOOKURL=https://apprisehost/notify/config # apprise notification url
#- APPRISEWEBHOOKTAG=all # apprise notification tag
volumes:
- C:/Docker/qbittorrent/gluetun/tmp:/tmp # REQUIRED: Path to where the 'forwarded_port' file from gluetun is stored