Skip to content

Commit 26de34e

Browse files
authored
feat: add Parseable branding to metrics onboarding scripts (#1741)
* feat: add Parseable branding to metrics onboarding scripts * ix: address CodeRabbit review comments * fix: resolved coderabbit comment * fix: resolved coderabbit comment
1 parent c7e9c95 commit 26de34e

2 files changed

Lines changed: 102 additions & 8 deletions

File tree

‎scripts/ingest.ps1‎

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5285
function 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

266315
function Restart-FluentBit {
267316
Stop-FluentBit
268317
Start-Sleep -Seconds 2
269-
Start-FluentBit
318+
[void](Start-FluentBit)
270319
}
271320

272321
function 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

365424
function 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

‎scripts/ingest.sh‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ set -e
1414
RED='\033[0;31m'
1515
GREEN='\033[0;32m'
1616
YELLOW='\033[1;33m'
17+
ACCENT='\033[38;2;158;158;240m'
18+
OK='\033[38;2;52;211;153m'
19+
BOLD='\033[1m'
1720
NC='\033[0m' # No Color
1821

1922
# File locations
@@ -34,6 +37,29 @@ print_warning() {
3437
echo -e "${YELLOW}[WARNING]${NC} $1"
3538
}
3639

40+
print_parseable_banner() {
41+
echo ""
42+
printf '%b%s%b\n' "$ACCENT" ' ____ _ ____ ____ _____ _ ____ _ _____' "$NC"
43+
printf '%b%s%b\n' "$ACCENT" '| _ \ / \ | _ \/ ___|| ____| / \ | __ )| | | ____|' "$NC"
44+
printf '%b%s%b\n' "$ACCENT" '| |_) / _ \ | |_) \___ \| _| / _ \ | _ \| | | _|' "$NC"
45+
printf '%b%s%b\n' "$ACCENT" '| __/ ___ \| _ < ___) | |___ / ___ \| |_) | |___| |___' "$NC"
46+
printf '%b%s%b\n' "$ACCENT" '|_| /_/ \_\_| \_\____/|_____/_/ \_\____/|_____|_____|' "$NC"
47+
echo ""
48+
echo -e "${BOLD}Host metrics setup${NC}"
49+
echo "Installing and configuring the metrics agent for Parseable..."
50+
echo ""
51+
}
52+
53+
print_setup_complete() {
54+
local stream_name="$1"
55+
56+
echo ""
57+
echo -e "${OK}${BOLD}✓ You're all set!${NC}"
58+
echo "Host metrics are now being sent to Parseable."
59+
echo -e "Dataset: ${BOLD}${stream_name}${NC}"
60+
echo "Return to Parseable and click Continue to verify your data."
61+
}
62+
3763
# Function to check if Fluent Bit is running
3864
is_running() {
3965
if [ -f "$PID_FILE" ]; then
@@ -256,6 +282,8 @@ setup_fluent_bit() {
256282
exit 1
257283
fi
258284

285+
print_parseable_banner
286+
259287
if [[ "$INGESTOR_HOST" =~ ^[Hh][Tt][Tt][Pp][Ss]:// ]]; then
260288
INGESTOR_HOST="${INGESTOR_HOST#*://}"
261289
TLS_SETTING="On"
@@ -336,10 +364,17 @@ ${TENANT_HEADER}
336364
EOF
337365
chmod 600 "$CONFIG_FILE"
338366
sed "s/Header X-API-Key.*/Header X-API-Key [REDACTED]/" "$CONFIG_FILE"
367+
368+
if is_running; then
369+
print_info "Restarting Fluent Bit to apply the updated configuration..."
370+
stop_fluent_bit
371+
sleep 2
372+
fi
339373

340374
# Start Fluent Bit
341375
echo ""
342376
start_fluent_bit
377+
print_setup_complete "$STREAM_NAME"
343378
}
344379

345380
# Main script logic

0 commit comments

Comments
 (0)