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

@@ -130,6 +130,7 @@ The script uses exponential backoff (500ms → 1s → 2s → 4s → up to 16s) f
| Version | Date | Changes | | Version | Date | Changes |
|---------|------|---------| |---------|------|---------|
| 1.5.1 | 2025-12-12 | Startup warning if PC not registered in ShopDB |
| 1.5.0 | 2025-12-12 | API logging to ShopDB (started, cleaned, failed, stopped events) | | 1.5.0 | 2025-12-12 | API logging to ShopDB (started, cleaned, failed, stopped events) |
| 1.4.0 | 2025-12-12 | Auto-update from S:\DT\cameron\eDNC-Fix\version.ini every 5 min | | 1.4.0 | 2025-12-12 | Auto-update from S:\DT\cameron\eDNC-Fix\version.ini every 5 min |
| 1.3.1 | 2025-12-12 | Added Install-ScheduledTask.ps1 for running as SYSTEM service | | 1.3.1 | 2025-12-12 | Added Install-ScheduledTask.ps1 for running as SYSTEM service |

View File

@@ -36,9 +36,10 @@
.NOTES .NOTES
Author: GE Aerospace - Rutland Author: GE Aerospace - Rutland
Version: 1.5.0 Version: 1.5.1
Date: 2025-12-12 Date: 2025-12-12
v1.5.1 - Startup warning if PC not registered in ShopDB
v1.5.0 - API logging: v1.5.0 - API logging:
- Logs events (started, cleaned, ok, failed, error, stopped) to ShopDB API - Logs events (started, cleaned, ok, failed, error, stopped) to ShopDB API
- Tracks installations and stats per hostname - Tracks installations and stats per hostname
@@ -82,7 +83,7 @@ param(
) )
# Script info # Script info
$ScriptVersion = "1.5.0" $ScriptVersion = "1.5.1"
$ScriptName = "eDNC Special Character Fix" $ScriptName = "eDNC Special Character Fix"
# Auto-update settings # Auto-update settings
@@ -222,6 +223,9 @@ function Send-DNCEvent {
[string]$Message = "" [string]$Message = ""
) )
# Skip if API is disabled (PC not registered or API unreachable)
if (-not $script:ApiEnabled) { return }
try { try {
$body = @{ $body = @{
action = "logDNCEvent" 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 "Removing bytes: $($CharactersToRemove -join ', ') (0x$($CharactersToRemove | ForEach-Object { '{0:X2}' -f $_ } | Join-String -Separator ', 0x'))" -ForegroundColor DarkGray
Write-Host "" Write-Host ""
# Log startup to API # Log startup to API and check if PC is registered
Send-DNCEvent -EventType "started" -Message "Script started" $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 # Statistics
$script:FilesProcessed = 0 $script:FilesProcessed = 0

View File

@@ -1,2 +1,2 @@
[eDNC-Fix] [eDNC-Fix]
Version=1.5.0 Version=1.5.1