v1.5.0: API logging to ShopDB
- Logs events (started, cleaned, ok, failed, error, stopped) to ShopDB API - Tracks installations and stats per hostname in ednc_installations table - Event history stored in ednc_logs table - Added CLAUDE.md with project instructions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,9 +36,13 @@
|
||||
|
||||
.NOTES
|
||||
Author: GE Aerospace - Rutland
|
||||
Version: 1.4.0
|
||||
Version: 1.5.0
|
||||
Date: 2025-12-12
|
||||
|
||||
v1.5.0 - API logging:
|
||||
- Logs events (started, cleaned, ok, failed, error, stopped) to ShopDB API
|
||||
- Tracks installations and stats per hostname
|
||||
|
||||
v1.4.0 - Auto-update:
|
||||
- Checks S:\DT\cameron\eDNC-Fix\version.ini every 5 minutes
|
||||
- Auto-downloads and restarts if newer version found
|
||||
@@ -78,7 +82,7 @@ param(
|
||||
)
|
||||
|
||||
# Script info
|
||||
$ScriptVersion = "1.4.0"
|
||||
$ScriptVersion = "1.5.0"
|
||||
$ScriptName = "eDNC Special Character Fix"
|
||||
|
||||
# Auto-update settings
|
||||
@@ -87,6 +91,10 @@ $LocalPath = "C:\eDNC-Fix"
|
||||
$UpdateCheckInterval = 300 # Check every 5 minutes (in seconds)
|
||||
$script:LastUpdateCheck = [DateTime]::MinValue
|
||||
|
||||
# API logging settings
|
||||
$ApiUrl = "http://geitshopdb/api.asp"
|
||||
$script:Hostname = $env:COMPUTERNAME
|
||||
|
||||
# Header display function
|
||||
function Show-Header {
|
||||
param([int]$Cleaned = 0, [int]$Failed = 0, [string]$Status = "Watching...")
|
||||
@@ -205,6 +213,35 @@ function Invoke-Update {
|
||||
}
|
||||
}
|
||||
|
||||
# API logging function
|
||||
function Send-DNCEvent {
|
||||
param(
|
||||
[string]$EventType,
|
||||
[string]$Filename = "",
|
||||
[int]$BytesRemoved = 0,
|
||||
[string]$Message = ""
|
||||
)
|
||||
|
||||
try {
|
||||
$body = @{
|
||||
action = "logDNCEvent"
|
||||
hostname = $script:Hostname
|
||||
filename = $Filename
|
||||
eventType = $EventType
|
||||
bytesRemoved = $BytesRemoved
|
||||
version = $ScriptVersion
|
||||
message = $Message
|
||||
watchFolder = $WatchFolder
|
||||
fileFilter = $FileFilter
|
||||
}
|
||||
|
||||
$null = Invoke-WebRequest -Uri $ApiUrl -Method POST -Body $body -ContentType "application/x-www-form-urlencoded" -UseBasicParsing -TimeoutSec 5
|
||||
}
|
||||
catch {
|
||||
# Silently fail - don't disrupt file watching for API issues
|
||||
}
|
||||
}
|
||||
|
||||
# Initialize console
|
||||
Clear-Host
|
||||
$script:HeaderHeight = Show-Header -Status "Initializing..."
|
||||
@@ -223,6 +260,9 @@ 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"
|
||||
|
||||
# Statistics
|
||||
$script:FilesProcessed = 0
|
||||
$script:BytesRemoved = 0
|
||||
@@ -267,6 +307,25 @@ $action = {
|
||||
[Console]::SetCursorPosition(0, $savedPos)
|
||||
}
|
||||
|
||||
# Helper to log to API
|
||||
$logToApi = {
|
||||
param($eventType, $file, $bytes, $msg)
|
||||
try {
|
||||
$body = @{
|
||||
action = "logDNCEvent"
|
||||
hostname = $Event.MessageData.Hostname
|
||||
filename = $file
|
||||
eventType = $eventType
|
||||
bytesRemoved = $bytes
|
||||
version = $Event.MessageData.Version
|
||||
message = $msg
|
||||
watchFolder = $Event.MessageData.WatchFolder
|
||||
fileFilter = $Event.MessageData.FileFilter
|
||||
}
|
||||
$null = Invoke-WebRequest -Uri $Event.MessageData.ApiUrl -Method POST -Body $body -ContentType "application/x-www-form-urlencoded" -UseBasicParsing -TimeoutSec 5
|
||||
} catch { }
|
||||
}
|
||||
|
||||
# Debounce check - skip if we processed this file recently
|
||||
$now = Get-Date
|
||||
if ($script:RecentlyProcessed.ContainsKey($path)) {
|
||||
@@ -328,9 +387,11 @@ $action = {
|
||||
$script:BytesRemoved += $removed
|
||||
& $updateStatus "CLEANED: $fileName ($removed bytes)" "Green"
|
||||
& $updateStats
|
||||
& $logToApi "cleaned" $fileName $removed "Removed $removed byte(s)"
|
||||
} else {
|
||||
Write-Host " [OK] No special characters found" -ForegroundColor Gray
|
||||
& $updateStatus "OK: $fileName (no changes)" "Gray"
|
||||
& $logToApi "ok" $fileName 0 "No changes needed"
|
||||
}
|
||||
|
||||
# Mark as recently processed
|
||||
@@ -350,6 +411,7 @@ $action = {
|
||||
$script:FailedFiles++
|
||||
& $updateStatus "FAILED: $fileName" "Red"
|
||||
& $updateStats
|
||||
& $logToApi "failed" $fileName 0 "Could not access file after $maxRetries attempts"
|
||||
}
|
||||
}
|
||||
catch {
|
||||
@@ -357,6 +419,7 @@ $action = {
|
||||
$script:FailedFiles++
|
||||
& $updateStatus "ERROR: $fileName" "Red"
|
||||
& $updateStats
|
||||
& $logToApi "error" $fileName 0 $_.Exception.Message
|
||||
break
|
||||
}
|
||||
finally {
|
||||
@@ -374,6 +437,10 @@ $messageData = @{
|
||||
DebounceSeconds = $script:DebounceSeconds
|
||||
StatusLine = 14 # Line number for status updates
|
||||
FileFilter = $FileFilter
|
||||
ApiUrl = $ApiUrl
|
||||
Hostname = $script:Hostname
|
||||
Version = $ScriptVersion
|
||||
WatchFolder = $WatchFolder
|
||||
}
|
||||
|
||||
# Register event handlers
|
||||
@@ -397,6 +464,9 @@ try {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
# Log shutdown to API
|
||||
Send-DNCEvent -EventType "stopped" -Message "Script stopped. Cleaned: $script:FilesProcessed, Failed: $script:FailedFiles"
|
||||
|
||||
# Cleanup on exit
|
||||
$watcher.EnableRaisingEvents = $false
|
||||
$watcher.Dispose()
|
||||
|
||||
Reference in New Issue
Block a user