|
| 1 | +### Grab variables from inputs.conf |
| 2 | +$BTOOL_INPUT = & $SPLUNKHOME\bin\splunk.exe cmd btool inputs list powershell://dsRemove --debug |
| 3 | +$SFRK_APP = ($BTOOL_INPUT -replace [regex]::Escape("$SPLUNKHOME\etc\apps\"),"" -replace "\\(default|local)\\inputs.conf","").Split(" ")[0] |
| 4 | +$CORRECT_DS_LINE = ($BTOOL_INPUT | findstr deploymentServerUri) |
| 5 | +$CORRECT_DS_APP_LINE = ($BTOOL_INPUT | findstr deploymentClientApp) |
| 6 | +$CORRECT_DS = ("$CORRECT_DS_LINE" -replace [regex]::Escape("$SPLUNKHOME\etc\apps\"),"").Split(" ")[3] |
| 7 | +$CORRECT_DS_APP = ("$CORRECT_DS_APP_LINE" -replace [regex]::Escape("$SPLUNKHOME\etc\apps\"),"").Split(" ")[3] |
| 8 | + |
| 9 | +if (!$CORRECT_DS) { |
| 10 | + Write-output "deploymentServerUri not configured in inputs.conf" | timestamp |
| 11 | + exit |
| 12 | +} |
| 13 | + |
| 14 | +if (!$CORRECT_DS_APP) { |
| 15 | + Write-output "deploymentClientApp not configured in inputs.conf" | timestamp |
| 16 | + exit |
| 17 | +} |
| 18 | + |
1 | 19 | ### Configure file paths for the system
|
2 |
| -$LOCAL = {$((Get-ChildItem -Path "$SPLUNKHOME\etc\system\local" -Include deploymentclient.conf -File -Recurse).Count)} |
3 |
| -$DEPLOYED = {$((Get-ChildItem -Path "$SPLUNKHOME\etc\apps" -Include deploymentclient.conf -File -Recurse).Count)} |
| 20 | +$LOCAL = $((Get-ChildItem -Path "$SPLUNKHOME\etc\system\local" -Include deploymentclient.conf -File -Recurse).Count) |
| 21 | +$DEPLOYED = $((Get-ChildItem -Path "$SPLUNKHOME\etc\apps" -Include deploymentclient.conf -File -Recurse).Count) |
| 22 | +$LIST_APPS = $(Get-ChildItem -Path "$SPLUNKHOME\etc\apps" -Include deploymentclient.conf -File -Recurse) |
| 23 | +$BAD_APPS = @(($LIST_APPS -replace "(deafult|local)\\deploymentclient.conf","").where{$_ -notmatch [regex]::Escape("$CORRECT_DS_APP") }) |
4 | 24 | $RESTART_CHECK = "$SPLUNKHOME\etc\restartds.txt"
|
5 | 25 |
|
6 | 26 | ### Filter to attach timestamps where necessary
|
7 |
| -filter timestamp {"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.fff') ${env:COMPUTERNAME}: $_"} |
| 27 | +filter timestamp {"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.fff zzz') ${env:COMPUTERNAME}: $_"} |
| 28 | + |
| 29 | +## Capture the current configuration that Splunk is using from btool |
| 30 | +$BTOOL = & $SPLUNKHOME\bin\splunk.exe cmd btool deploymentclient list --debug | FINDSTR 'targetUri' |
| 31 | +$CURRENT_DS = ($BTOOL -replace [regex]::Escape("$SPLUNKHOME"),"").Split(" ")[3] |
| 32 | +$CURRENT_APP_PATH = "$SPLUNKHOME"+($BTOOL -replace [regex]::Escape("$SPLUNKHOME"),"" -replace "\\(deafult|local)\\deploymentclient.conf","").Split(" ")[0] |
| 33 | +$CURRENT_APP_NAME = ($CURRENT_APP_PATH -replace [regex]::Escape("$SPLUNKHOME\etc\apps\"),"") |
8 | 34 |
|
9 | 35 | ### Check to see if there is a deploymentclient.conf file under $SPLUNKHOME\etc\apps and bail out if there isn't
|
10 | 36 | if ($DEPLOYED -eq "0") {
|
11 |
| - Write-output "No deploymentclient.conf detected in $SPLUNKHOME\etc\apps. Bailing out so the fowarder doesn't get orphaned." | timestamp |
12 |
| -} elseif ($DEPLOYED -gt "1") { |
13 |
| - Write-output "Multiple deploymentclient.conf detected in $SPLUNKHOME\etc\apps. Check all deployed apps to ensure you\'re only using one." | timestamp |
14 |
| -} elseif ($LOCAL -eq "1" -AND $DEPLOYED -eq "1") { |
15 |
| - ### Remove the local "deploymentclient.conf" and flag |
16 |
| - Write-output "Removed deploymentclient.conf from local system." | timestamp |
17 |
| - Remove-Item -Path "$LOCAL" |
18 |
| - Out-File -FilePath "$RESTART_CHECK" |
19 |
| -} else { |
20 |
| - Write-output "No deploymentclient.conf correction necessary." | timestamp |
| 37 | + Write-output "No deploymentclient.conf detected in $SPLUNKHOME\etc\apps. Bailing out so the fowarder doesn't get orphaned." | timestamp |
| 38 | + Write-output "Deploy $CORRECT_APP to this server to correct this issue." | timestamp |
| 39 | +} |
| 40 | +elseif ($DEPLOYED -gt "1") { |
| 41 | + Write-output "Multiple deploymentclient.conf detected in $SPLUNKHOME\etc\apps." | timestamp |
| 42 | + Write-output "Removing bad app(s) to ensure there is no contention with $CORRECT_DS_APP" | timestamp |
| 43 | + foreach ($item in $BAD_APPS) |
| 44 | + { |
| 45 | + Remove-Item -Path "$item" -Force -Recurse -Confirm |
| 46 | + Write-output "Removed app: $item" | timestamp |
| 47 | + } |
| 48 | + Out-File -FilePath "$RESTART_CHECK" |
| 49 | +} |
| 50 | +elseif ($LOCAL -eq "1" -AND $DEPLOYED -eq "1") { |
| 51 | + Write-output "Removed deploymentclient.conf from local system." | timestamp |
| 52 | + Remove-Item -Path "$LOCAL" -Force -Confirm |
| 53 | + Out-File -FilePath "$RESTART_CHECK" |
| 54 | +} |
| 55 | +else { |
| 56 | + Write-output "No deploymentclient.conf correction necessary." | timestamp |
21 | 57 | }
|
0 commit comments