Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 67 additions & 8 deletions scripts/ingest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,66 @@ function Write-ErrorMsg {
Write-Host "[ERROR] $Message" -ForegroundColor Red
}

function Write-ParseableBanner {
$accent = "$([char]27)[38;2;158;158;240m"
$reset = "$([char]27)[0m"
$logo = @(
' ____ _ ____ ____ _____ _ ____ _ _____',
'| _ \ / \ | _ \/ ___|| ____| / \ | __ )| | | ____|',
'| |_) / _ \ | |_) \___ \| _| / _ \ | _ \| | | _|',
'| __/ ___ \| _ < ___) | |___ / ___ \| |_) | |___| |___',
'|_| /_/ \_\_| \_\____/|_____/_/ \_\____/|_____|_____|'
)

Write-Host ""
$logo | ForEach-Object { Write-Host "$accent$_$reset" }
Write-Host ""
Write-Host "Host metrics setup" -ForegroundColor White
Write-Host "Installing and configuring the metrics agent for Parseable..."
Write-Host ""
}

function Write-SetupComplete {
param([string]$StreamName)

$accent = "$([char]27)[38;2;158;158;240m"
$ok = "$([char]27)[38;2;52;211;153m"
$reset = "$([char]27)[0m"
Write-Host ""
Write-Host "${ok}[OK] You're all set!${reset}"
Write-Host "Host metrics are now being sent to Parseable."
Write-Host "Dataset: " -NoNewline
Write-Host "${accent}${StreamName}${reset}"
Write-Host "Return to Parseable and click Continue to verify your data."
}

function Test-FluentBitRunning {
if (Test-Path $PID_FILE) {
$processId = Get-Content $PID_FILE

try {
$process = Get-Process -Id $processId -ErrorAction SilentlyContinue
if ($process) {
return $true
}
$process = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $processId" -ErrorAction Stop
}
catch {
throw "Unable to inspect process $processId; PID file was preserved. $_"
}

if ($null -eq $process) {
Remove-Item $PID_FILE -ErrorAction SilentlyContinue
return $false
}

if ([string]::IsNullOrWhiteSpace($process.ExecutablePath)) {
throw "Unable to verify process $processId; PID file was preserved."
}

$actualPath = [System.IO.Path]::GetFullPath($process.ExecutablePath)
$expectedPath = [System.IO.Path]::GetFullPath($FLUENT_BIT_EXE)
if ([System.StringComparer]::OrdinalIgnoreCase.Equals($actualPath, $expectedPath)) {
return $true
}

Remove-Item $PID_FILE -ErrorAction SilentlyContinue
}
return $false
}
Expand Down Expand Up @@ -211,7 +259,7 @@ function Start-FluentBit {
$processId = Get-Content $PID_FILE
Write-Warning "Fluent Bit is already running (PID: $processId)"
Write-Info "Use '$SCRIPT_CMD stop' to stop it first"
return
return $false
}

if (-not (Test-Path $CONFIG_FILE)) {
Expand Down Expand Up @@ -260,13 +308,14 @@ function Start-FluentBit {
Write-Info "To check status: $SCRIPT_CMD status"
Write-Info "To see logs: $SCRIPT_CMD logs"
Write-Info "To stop: $SCRIPT_CMD stop"
return $true
}
}

function Restart-FluentBit {
Stop-FluentBit
Start-Sleep -Seconds 2
Start-FluentBit
[void](Start-FluentBit)
}

function Setup-FluentBit {
Expand All @@ -282,6 +331,8 @@ function Setup-FluentBit {
exit 1
}

Write-ParseableBanner

$tlsSetting = "On"
$defaultPort = "443"
if ($IngestorHost -like "https://*") {
Expand Down Expand Up @@ -357,9 +408,17 @@ function Setup-FluentBit {
# Use UTF8 without BOM (important for Fluent Bit)
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllText($CONFIG_FILE, $configContent, $utf8NoBom)

if (Test-FluentBitRunning) {
Write-Info "Restarting Fluent Bit to apply the updated configuration..."
Stop-FluentBit
Start-Sleep -Seconds 2
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

Write-Host ""
Start-FluentBit
if (Start-FluentBit) {
Write-SetupComplete -StreamName $StreamName
}
}

function Show-Help {
Expand Down Expand Up @@ -411,7 +470,7 @@ switch ($Param1.ToLower()) {
Restart-FluentBit
}
"start" {
Start-FluentBit
[void](Start-FluentBit)
}
"status" {
Show-Status
Expand Down
35 changes: 35 additions & 0 deletions scripts/ingest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
ACCENT='\033[38;2;158;158;240m'
OK='\033[38;2;52;211;153m'
BOLD='\033[1m'
NC='\033[0m' # No Color

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

print_parseable_banner() {
echo ""
printf '%b%s%b\n' "$ACCENT" ' ____ _ ____ ____ _____ _ ____ _ _____' "$NC"
printf '%b%s%b\n' "$ACCENT" '| _ \ / \ | _ \/ ___|| ____| / \ | __ )| | | ____|' "$NC"
printf '%b%s%b\n' "$ACCENT" '| |_) / _ \ | |_) \___ \| _| / _ \ | _ \| | | _|' "$NC"
printf '%b%s%b\n' "$ACCENT" '| __/ ___ \| _ < ___) | |___ / ___ \| |_) | |___| |___' "$NC"
printf '%b%s%b\n' "$ACCENT" '|_| /_/ \_\_| \_\____/|_____/_/ \_\____/|_____|_____|' "$NC"
echo ""
echo -e "${BOLD}Host metrics setup${NC}"
echo "Installing and configuring the metrics agent for Parseable..."
echo ""
}

print_setup_complete() {
local stream_name="$1"

echo ""
echo -e "${OK}${BOLD}✓ You're all set!${NC}"
echo "Host metrics are now being sent to Parseable."
echo -e "Dataset: ${BOLD}${stream_name}${NC}"
echo "Return to Parseable and click Continue to verify your data."
}

# Function to check if Fluent Bit is running
is_running() {
if [ -f "$PID_FILE" ]; then
Expand Down Expand Up @@ -256,6 +282,8 @@ setup_fluent_bit() {
exit 1
fi

print_parseable_banner

if [[ "$INGESTOR_HOST" =~ ^[Hh][Tt][Tt][Pp][Ss]:// ]]; then
INGESTOR_HOST="${INGESTOR_HOST#*://}"
TLS_SETTING="On"
Expand Down Expand Up @@ -336,10 +364,17 @@ ${TENANT_HEADER}
EOF
chmod 600 "$CONFIG_FILE"
sed "s/Header X-API-Key.*/Header X-API-Key [REDACTED]/" "$CONFIG_FILE"

if is_running; then
print_info "Restarting Fluent Bit to apply the updated configuration..."
stop_fluent_bit
sleep 2
fi

# Start Fluent Bit
echo ""
start_fluent_bit
print_setup_complete "$STREAM_NAME"
}

# Main script logic
Expand Down
Loading