v1.5.1: Startup warning if PC not registered in ShopDB

- Check API response on startup for "Unknown hostname" error
- Display warning if PC not in ShopDB machines table
- Skip API calls if PC not registered (avoid repeated failures)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2025-12-12 09:45:42 -05:00
parent 134670a026
commit 28641c47c5
3 changed files with 33 additions and 5 deletions

View File

@@ -36,9 +36,10 @@
.NOTES
Author: GE Aerospace - Rutland
Version: 1.5.0
Version: 1.5.1
Date: 2025-12-12
v1.5.1 - Startup warning if PC not registered in ShopDB
v1.5.0 - API logging:
- Logs events (started, cleaned, ok, failed, error, stopped) to ShopDB API
- Tracks installations and stats per hostname
@@ -82,7 +83,7 @@ param(
)
# Script info
$ScriptVersion = "1.5.0"
$ScriptVersion = "1.5.1"
$ScriptName = "eDNC Special Character Fix"
# Auto-update settings
@@ -222,6 +223,9 @@ function Send-DNCEvent {
[string]$Message = ""
)
# Skip if API is disabled (PC not registered or API unreachable)
if (-not $script:ApiEnabled) { return }
try {
$body = @{
action = "logDNCEvent"
@@ -260,8 +264,31 @@ Show-Header -Status "Watching for files... (Ctrl+C to stop)" | Out-Null
Write-Host "Removing bytes: $($CharactersToRemove -join ', ') (0x$($CharactersToRemove | ForEach-Object { '{0:X2}' -f $_ } | Join-String -Separator ', 0x'))" -ForegroundColor DarkGray
Write-Host ""
# Log startup to API
Send-DNCEvent -EventType "started" -Message "Script started"
# Log startup to API and check if PC is registered
$script:ApiEnabled = $true
try {
$body = @{
action = "logDNCEvent"
hostname = $script:Hostname
eventType = "started"
version = $ScriptVersion
message = "Script started"
}
$response = Invoke-WebRequest -Uri $ApiUrl -Method POST -Body $body -ContentType "application/x-www-form-urlencoded" -UseBasicParsing -TimeoutSec 5
$json = $response.Content | ConvertFrom-Json
if ($json.success -eq $false -and $json.error -match "Unknown hostname") {
$script:ApiEnabled = $false
Write-Host "WARNING: This PC ($($script:Hostname)) is not registered in ShopDB." -ForegroundColor Yellow
Write-Host " Activity will NOT be logged. Add this PC to ShopDB to enable logging." -ForegroundColor Yellow
Write-Host ""
}
}
catch {
# API unreachable - continue without logging
$script:ApiEnabled = $false
Write-Host "WARNING: Cannot reach ShopDB API. Activity will NOT be logged." -ForegroundColor Yellow
Write-Host ""
}
# Statistics
$script:FilesProcessed = 0