@@ -49,18 +49,66 @@ function Write-ErrorMsg {
4949 Write-Host " [ERROR] $Message " - ForegroundColor Red
5050}
5151
52+ function Write-ParseableBanner {
53+ $accent = " $ ( [char ]27 ) [38;2;158;158;240m"
54+ $reset = " $ ( [char ]27 ) [0m"
55+ $logo = @ (
56+ ' ____ _ ____ ____ _____ _ ____ _ _____' ,
57+ ' | _ \ / \ | _ \/ ___|| ____| / \ | __ )| | | ____|' ,
58+ ' | |_) / _ \ | |_) \___ \| _| / _ \ | _ \| | | _|' ,
59+ ' | __/ ___ \| _ < ___) | |___ / ___ \| |_) | |___| |___' ,
60+ ' |_| /_/ \_\_| \_\____/|_____/_/ \_\____/|_____|_____|'
61+ )
62+
63+ Write-Host " "
64+ $logo | ForEach-Object { Write-Host " $accent $_ $reset " }
65+ Write-Host " "
66+ Write-Host " Host metrics setup" - ForegroundColor White
67+ Write-Host " Installing and configuring the metrics agent for Parseable..."
68+ Write-Host " "
69+ }
70+
71+ function Write-SetupComplete {
72+ param ([string ]$StreamName )
73+
74+ $accent = " $ ( [char ]27 ) [38;2;158;158;240m"
75+ $ok = " $ ( [char ]27 ) [38;2;52;211;153m"
76+ $reset = " $ ( [char ]27 ) [0m"
77+ Write-Host " "
78+ Write-Host " ${ok} [OK] You're all set!${reset} "
79+ Write-Host " Host metrics are now being sent to Parseable."
80+ Write-Host " Dataset: " - NoNewline
81+ Write-Host " ${accent}${StreamName}${reset} "
82+ Write-Host " Return to Parseable and click Continue to verify your data."
83+ }
84+
5285function Test-FluentBitRunning {
5386 if (Test-Path $PID_FILE ) {
5487 $processId = Get-Content $PID_FILE
88+
5589 try {
56- $process = Get-Process - Id $processId - ErrorAction SilentlyContinue
57- if ($process ) {
58- return $true
59- }
90+ $process = Get-CimInstance - ClassName Win32_Process - Filter " ProcessId = $processId " - ErrorAction Stop
6091 }
6192 catch {
93+ throw " Unable to inspect process $processId ; PID file was preserved. $_ "
94+ }
95+
96+ if ($null -eq $process ) {
97+ Remove-Item $PID_FILE - ErrorAction SilentlyContinue
6298 return $false
6399 }
100+
101+ if ([string ]::IsNullOrWhiteSpace($process.ExecutablePath )) {
102+ throw " Unable to verify process $processId ; PID file was preserved."
103+ }
104+
105+ $actualPath = [System.IO.Path ]::GetFullPath($process.ExecutablePath )
106+ $expectedPath = [System.IO.Path ]::GetFullPath($FLUENT_BIT_EXE )
107+ if ([System.StringComparer ]::OrdinalIgnoreCase.Equals($actualPath , $expectedPath )) {
108+ return $true
109+ }
110+
111+ Remove-Item $PID_FILE - ErrorAction SilentlyContinue
64112 }
65113 return $false
66114}
@@ -211,7 +259,7 @@ function Start-FluentBit {
211259 $processId = Get-Content $PID_FILE
212260 Write-Warning " Fluent Bit is already running (PID: $processId )"
213261 Write-Info " Use '$SCRIPT_CMD stop' to stop it first"
214- return
262+ return $false
215263 }
216264
217265 if (-not (Test-Path $CONFIG_FILE )) {
@@ -260,13 +308,14 @@ function Start-FluentBit {
260308 Write-Info " To check status: $SCRIPT_CMD status"
261309 Write-Info " To see logs: $SCRIPT_CMD logs"
262310 Write-Info " To stop: $SCRIPT_CMD stop"
311+ return $true
263312 }
264313}
265314
266315function Restart-FluentBit {
267316 Stop-FluentBit
268317 Start-Sleep - Seconds 2
269- Start-FluentBit
318+ [ void ]( Start-FluentBit )
270319}
271320
272321function Setup-FluentBit {
@@ -282,6 +331,8 @@ function Setup-FluentBit {
282331 exit 1
283332 }
284333
334+ Write-ParseableBanner
335+
285336 $tlsSetting = " On"
286337 $defaultPort = " 443"
287338 if ($IngestorHost -like " https://*" ) {
@@ -357,9 +408,17 @@ function Setup-FluentBit {
357408 # Use UTF8 without BOM (important for Fluent Bit)
358409 $utf8NoBom = New-Object System.Text.UTF8Encoding $false
359410 [System.IO.File ]::WriteAllText($CONFIG_FILE , $configContent , $utf8NoBom )
411+
412+ if (Test-FluentBitRunning ) {
413+ Write-Info " Restarting Fluent Bit to apply the updated configuration..."
414+ Stop-FluentBit
415+ Start-Sleep - Seconds 2
416+ }
360417
361418 Write-Host " "
362- Start-FluentBit
419+ if (Start-FluentBit ) {
420+ Write-SetupComplete - StreamName $StreamName
421+ }
363422}
364423
365424function Show-Help {
@@ -411,7 +470,7 @@ switch ($Param1.ToLower()) {
411470 Restart-FluentBit
412471 }
413472 " start" {
414- Start-FluentBit
473+ [ void ]( Start-FluentBit )
415474 }
416475 " status" {
417476 Show-Status
0 commit comments