Fail context migration when upload is unavailable
This commit is contained in:
@@ -130,9 +130,10 @@ The script has no script variables and does the following safely:
|
|||||||
2. stores the current NinjaOne organization, location, node, and machine values;
|
2. stores the current NinjaOne organization, location, node, and machine values;
|
||||||
3. starts one signed status scan and upload using that stored context.
|
3. starts one signed status scan and upload using that stored context.
|
||||||
|
|
||||||
Expected output includes `OCSENTINEL_NINJA_CONTEXT=updated`. Do not run this
|
Expected output includes `OCSENTINEL_NINJA_CONTEXT=updated`; this is emitted
|
||||||
script from an interactive PowerShell session, because NinjaOne does not expose
|
only after the immediate upload succeeds. Do not run this script from an
|
||||||
the required environment values there.
|
interactive PowerShell session, because NinjaOne does not expose the required
|
||||||
|
environment values there.
|
||||||
|
|
||||||
## Secret Bootstrap
|
## Secret Bootstrap
|
||||||
|
|
||||||
|
|||||||
@@ -88,20 +88,23 @@ if ($missing.Count -gt 0) {
|
|||||||
$clientConfig | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $clientConfigPath -Encoding UTF8
|
$clientConfig | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $clientConfigPath -Encoding UTF8
|
||||||
Write-Host "OCSentinel NinjaOne context captured: $captured of $($mappings.Count) values."
|
Write-Host "OCSentinel NinjaOne context captured: $captured of $($mappings.Count) values."
|
||||||
|
|
||||||
if ((Test-Path -LiteralPath $secretPath) -and -not [string]::IsNullOrWhiteSpace([string]$clientConfig.n8nWebhookUrl)) {
|
if ([string]::IsNullOrWhiteSpace([string]$clientConfig.n8nWebhookUrl)) {
|
||||||
Write-Host "Running an immediate status scan and upload with the refreshed NinjaOne context."
|
throw "NinjaOne context was stored, but this client has no configured n8n webhook URL. Run the OCSentinel installation/configuration automation with its WebhookUrl variable first."
|
||||||
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $monitorPath `
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path -LiteralPath $secretPath)) {
|
||||||
|
throw "NinjaOne context was stored, but the protected upload secret is missing. Run the OCSentinel installation/configuration automation with its SecretValue variable first."
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Running an immediate status scan and upload with the refreshed NinjaOne context."
|
||||||
|
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $monitorPath `
|
||||||
-Mode status `
|
-Mode status `
|
||||||
-ClientConfigPath $clientConfigPath `
|
-ClientConfigPath $clientConfigPath `
|
||||||
-SecretPath $secretPath `
|
-SecretPath $secretPath `
|
||||||
-UploadMode required `
|
-UploadMode required `
|
||||||
-SuppressTriggerExit
|
-SuppressTriggerExit
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
throw "OCSentinel context refresh scan exited with code $LASTEXITCODE"
|
throw "OCSentinel context refresh scan exited with code $LASTEXITCODE"
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Warning "Context was stored, but the upload configuration or protected secret is missing. The next configured scan will use the stored context."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "OCSENTINEL_NINJA_CONTEXT=updated"
|
Write-Host "OCSENTINEL_NINJA_CONTEXT=updated"
|
||||||
|
|||||||
Reference in New Issue
Block a user