|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + The script validates if the Splunk OpenTelemetry .NET Deployer TA can be |
| 4 | + installed and uninstalled successfully by Splunk. |
| 5 | +
|
| 6 | +.DESCRIPTION |
| 7 | + The script extracts the Splunk OpenTelemetry .NET Deployer TA from a .tgz file |
| 8 | + and installs it. It then validates the installation by checking if the expected |
| 9 | + files and directories are present. The script also uninstalls the Splunk OpenTelemetry |
| 10 | + .NET instrumentation, by changing the local configuration of the Deployer TA |
| 11 | + and validates the uninstallation by once again checking if the instrumentation |
| 12 | + files and folders were removed. |
| 13 | +
|
| 14 | +.PARAMETER tgzFilePath |
| 15 | + Path to the .tgz file containing the Splunk OpenTelemetry .NET Deployer TA. |
| 16 | +
|
| 17 | +.PARAMETER splunkInstallPath |
| 18 | + Path to the Splunk installation directory. |
| 19 | +
|
| 20 | +.PARAMETER splunkAppName |
| 21 | + Actual name on the disk of the folder with the Splunk OpenTelemetry .NET |
| 22 | + Deployer TA app. |
| 23 | +#> |
| 24 | +param ( |
| 25 | + [string]$tgzFilePath, |
| 26 | + [string]$splunkInstallPath, |
| 27 | + [string]$splunkAppName = "splunk_otel_dotnet_deployer" |
| 28 | +) |
| 29 | + |
| 30 | +# Function to extract .tgz file into the given destination path |
| 31 | +function Expand-Tgz { |
| 32 | + param ( |
| 33 | + [string]$tgzFilePath, |
| 34 | + [string]$destinationPath |
| 35 | + ) |
| 36 | + |
| 37 | + Write-Host "Expanding '$tgzFilePath' into '$destinationPath'" |
| 38 | + tar -xzf $tgzFilePath -C $destinationPath |
| 39 | +} |
| 40 | + |
| 41 | +# Validate parameters |
| 42 | +if (-not (Test-Path $tgzFilePath)) { |
| 43 | + Write-Error "The specified .tgz file does not exist: $tgzFilePath" |
| 44 | + exit 1 |
| 45 | +} |
| 46 | +if (-not (Test-Path $splunkInstallPath)) { |
| 47 | + Write-Error "The specified Splunk installation path does not exist: $splunkInstallPath" |
| 48 | + exit 1 |
| 49 | +} |
| 50 | + |
| 51 | +$splunkAppsPath = Join-Path $splunkInstallPath "etc/apps" |
| 52 | +Expand-Tgz -tgzFilePath $tgzFilePath -destinationPath $splunkAppsPath |
| 53 | + |
| 54 | +# Check if the TA is installed |
| 55 | +$taPath = Join-Path $splunkAppsPath $splunkAppName |
| 56 | +if (Test-Path $taPath) { |
| 57 | + Write-Host "Splunk TA $splunkAppName is installed at $taPath" |
| 58 | +} else { |
| 59 | + Write-Error "Splunk TA $splunkAppName is not installed" |
| 60 | + exit 1 |
| 61 | +} |
| 62 | + |
| 63 | +# Restart Splunk |
| 64 | +Write-Host "Restarting Splunk" |
| 65 | +& "$splunkInstallPath/bin/splunk.exe" restart |
| 66 | + |
| 67 | +# Check if the Splunk OpenTelemetry .NET instrumentation is installed - remember |
| 68 | +# that the TA needs some time to complete this operation after the restart |
| 69 | +Start-Sleep -Seconds 30 |
| 70 | +$splunkOtelDotNetPath = Join-Path ${env:ProgramFiles} "Splunk OpenTelemetry .NET" |
| 71 | +if (Test-Path $splunkOtelDotNetPath) { |
| 72 | + Write-Host "Splunk OpenTelemetry .NET instrumentation is installed at $splunkOtelDotNetPath" |
| 73 | +} else { |
| 74 | + Write-Error "Splunk OpenTelemetry .NET instrumentation is not installed" |
| 75 | + exit 1 |
| 76 | +} |
| 77 | + |
| 78 | +# Create a local inputs.conf for the TA and configure it to uninstall the Splunk OpenTelemety .NET instrumentation |
| 79 | +$localInputsConfPath = Join-Path $taPath "local/inputs.conf" |
| 80 | +# Ensure the local directory exists |
| 81 | +$localDir = Join-Path $taPath "local" |
| 82 | +if (-not (Test-Path $localDir)) { |
| 83 | + New-Item -ItemType Directory -Path $localDir | Out-Null |
| 84 | +} |
| 85 | + |
| 86 | +# Copy the default inputs.conf to the local directory |
| 87 | +$defaultInputsConfPath = Join-Path $taPath "default/inputs.conf" |
| 88 | +if (Test-Path $defaultInputsConfPath) { |
| 89 | + Copy-Item -Path $defaultInputsConfPath -Destination $localInputsConfPath |
| 90 | + Write-Host "Copied default inputs.conf to local directory" |
| 91 | +} else { |
| 92 | + Write-Error "Default inputs.conf does not exist at $defaultInputsConfPath" |
| 93 | + exit 1 |
| 94 | +} |
| 95 | + |
| 96 | +# Modify the local inputs.conf to uninstall the Splunk OpenTelemetry .NET instrumentation |
| 97 | +$localInputsConfContent = $(Get-Content $localInputsConfPath).Replace("uninstall = false", "uninstall = true") |
| 98 | +Set-Content -Path $localInputsConfPath -Value $localInputsConfContent |
| 99 | + |
| 100 | +# Restart Splunk |
| 101 | +Write-Host "Restarting Splunk" |
| 102 | +& "$splunkInstallPath/bin/splunk.exe" restart |
| 103 | + |
| 104 | +# Check if the Splunk OpenTelemetry .NET instrumentation is uninstalled - remember |
| 105 | +# that the TA needs some time to complete this operation after the restart |
| 106 | +Start-Sleep -Seconds 30 |
| 107 | +if (-not (Test-Path $splunkOtelDotNetPath)) { |
| 108 | + Write-Host "Splunk OpenTelemetry .NET instrumentation is uninstalled" |
| 109 | +} else { |
| 110 | + Write-Error "Splunk OpenTelemetry .NET instrumentation is not uninstalled" |
| 111 | + exit 1 |
| 112 | +} |
0 commit comments