From 7431c656d3ad4ee1a8a00e71db8d2ec7084ecb8a Mon Sep 17 00:00:00 2001 From: OfficeCom Codex Date: Sat, 25 Jul 2026 21:17:59 +0200 Subject: [PATCH] Use documented NinjaOne custom field commands --- installer/runtime-run-ocsentinel-monitor.ps1 | 49 ++++++++++++-------- release/stable/version.json | 8 ++-- scripts/run-ocsentinel-monitor.ps1 | 49 ++++++++++++-------- src/OCSentinelCli/OCSentinelCli.csproj | 8 ++-- 4 files changed, 68 insertions(+), 46 deletions(-) diff --git a/installer/runtime-run-ocsentinel-monitor.ps1 b/installer/runtime-run-ocsentinel-monitor.ps1 index 1db46ad..760add7 100644 --- a/installer/runtime-run-ocsentinel-monitor.ps1 +++ b/installer/runtime-run-ocsentinel-monitor.ps1 @@ -46,8 +46,13 @@ function Initialize-NinjaFieldWriter { return } + if (Get-Command -Name "Set-NinjaProperty" -ErrorAction SilentlyContinue) { + $script:NinjaFieldBackend = "powershell-modern" + return + } + if (Get-Command -Name "Ninja-Property-Set" -ErrorAction SilentlyContinue) { - $script:NinjaFieldBackend = "powershell" + $script:NinjaFieldBackend = "powershell-legacy" return } @@ -64,14 +69,20 @@ function Set-NinjaCustomFieldValue { [Parameter(Mandatory)] [string]$Name, [AllowEmptyString()] - [string]$Value + [object]$Value, + [Parameter(Mandatory)] + [string]$Type ) Initialize-NinjaFieldWriter switch ($script:NinjaFieldBackend) { - "powershell" { - Ninja-Property-Set $Name $Value | Out-Null + "powershell-modern" { + Set-NinjaProperty -Name $Name -Value $Value -Type $Type -Force | Out-Null + return $true + } + "powershell-legacy" { + Ninja-Property-Set -Name $Name -Value $Value | Out-Null return $true } "cli" { @@ -112,28 +123,28 @@ function Publish-NinjaCustomFields { } } - $fieldValues = [ordered]@{ - "ocsentinelstatus" = [string]$Report.AlertState - "ocsentinelreason" = $Reason - "ocsentinelbasestatus" = [string]$Report.BaseAlertState - "ocsentinelevents" = [string]([int]$Report.TotalEvents) - "ocsentineluniqueips" = [string]([int]$Report.UniqueIpCount) - "ocsentinelcvecritical" = [string]([int]$Report.VulnerabilityCorrelation.CriticalCount) - "ocsentinelcvetotal" = [string]([int]$Report.VulnerabilityCorrelation.TotalCount) - "ocsentinelmode" = $Mode - "ocsentineltriggered" = $Triggered.ToString().ToLowerInvariant() - "ocsentinellastscanutc" = $generatedAtUtc - } + $fieldValues = @( + [pscustomobject]@{ Name = "ocsentinelstatus"; Type = "Text"; Value = [string]$Report.AlertState } + [pscustomobject]@{ Name = "ocsentinelreason"; Type = "Text"; Value = $Reason } + [pscustomobject]@{ Name = "ocsentinelbasestatus"; Type = "Text"; Value = [string]$Report.BaseAlertState } + [pscustomobject]@{ Name = "ocsentinelevents"; Type = "Integer"; Value = [int]$Report.TotalEvents } + [pscustomobject]@{ Name = "ocsentineluniqueips"; Type = "Integer"; Value = [int]$Report.UniqueIpCount } + [pscustomobject]@{ Name = "ocsentinelcvecritical"; Type = "Integer"; Value = [int]$Report.VulnerabilityCorrelation.CriticalCount } + [pscustomobject]@{ Name = "ocsentinelcvetotal"; Type = "Integer"; Value = [int]$Report.VulnerabilityCorrelation.TotalCount } + [pscustomobject]@{ Name = "ocsentinelmode"; Type = "Text"; Value = $Mode } + [pscustomobject]@{ Name = "ocsentineltriggered"; Type = "Checkbox"; Value = $Triggered } + [pscustomobject]@{ Name = "ocsentinellastscanutc"; Type = "DateTime"; Value = $generatedAtUtc } + ) $updated = 0 - foreach ($entry in $fieldValues.GetEnumerator()) { + foreach ($entry in $fieldValues) { try { - if (Set-NinjaCustomFieldValue -Name $entry.Key -Value $entry.Value) { + if (Set-NinjaCustomFieldValue -Name $entry.Name -Value $entry.Value -Type $entry.Type) { $updated++ } } catch { - Write-Warning "Failed to set Ninja custom field '$($entry.Key)': $($_.Exception.Message)" + Write-Warning "Failed to set Ninja custom field '$($entry.Name)': $($_.Exception.Message)" } } diff --git a/release/stable/version.json b/release/stable/version.json index b3554d2..2acb3d8 100644 --- a/release/stable/version.json +++ b/release/stable/version.json @@ -1,8 +1,8 @@ { "channel": "stable", - "version": "1.2.10", - "publishedAtUtc": "2026-07-25T19:14:36.9210206Z", - "artifactUrl": "https://gitea.officecom.cloud/officecom/oc-sentinel/releases/download/v1.2.10/OCSentinelClient-win-x64.zip", - "sha256": "4de7abf96ff9ed47da02ac7f586cc39102fa508372825c2f7bf5e1df2b0f6c80", + "version": "1.2.11", + "publishedAtUtc": "2026-07-25T19:17:43.7567344Z", + "artifactUrl": "https://gitea.officecom.cloud/officecom/oc-sentinel/releases/download/v1.2.11/OCSentinelClient-win-x64.zip", + "sha256": "4a5415ce281f444a987a3fd72980c159afaa37787bbaa396f42d2c496736e5e1", "minUpdaterVersion": "1.0.0" } diff --git a/scripts/run-ocsentinel-monitor.ps1 b/scripts/run-ocsentinel-monitor.ps1 index 738cf81..d1b447e 100644 --- a/scripts/run-ocsentinel-monitor.ps1 +++ b/scripts/run-ocsentinel-monitor.ps1 @@ -46,8 +46,13 @@ function Initialize-NinjaFieldWriter { return } + if (Get-Command -Name "Set-NinjaProperty" -ErrorAction SilentlyContinue) { + $script:NinjaFieldBackend = "powershell-modern" + return + } + if (Get-Command -Name "Ninja-Property-Set" -ErrorAction SilentlyContinue) { - $script:NinjaFieldBackend = "powershell" + $script:NinjaFieldBackend = "powershell-legacy" return } @@ -64,14 +69,20 @@ function Set-NinjaCustomFieldValue { [Parameter(Mandatory)] [string]$Name, [AllowEmptyString()] - [string]$Value + [object]$Value, + [Parameter(Mandatory)] + [string]$Type ) Initialize-NinjaFieldWriter switch ($script:NinjaFieldBackend) { - "powershell" { - Ninja-Property-Set $Name $Value | Out-Null + "powershell-modern" { + Set-NinjaProperty -Name $Name -Value $Value -Type $Type -Force | Out-Null + return $true + } + "powershell-legacy" { + Ninja-Property-Set -Name $Name -Value $Value | Out-Null return $true } "cli" { @@ -112,28 +123,28 @@ function Publish-NinjaCustomFields { } } - $fieldValues = [ordered]@{ - "ocsentinelstatus" = [string]$Report.AlertState - "ocsentinelreason" = $Reason - "ocsentinelbasestatus" = [string]$Report.BaseAlertState - "ocsentinelevents" = [string]([int]$Report.TotalEvents) - "ocsentineluniqueips" = [string]([int]$Report.UniqueIpCount) - "ocsentinelcvecritical" = [string]([int]$Report.VulnerabilityCorrelation.CriticalCount) - "ocsentinelcvetotal" = [string]([int]$Report.VulnerabilityCorrelation.TotalCount) - "ocsentinelmode" = $Mode - "ocsentineltriggered" = $Triggered.ToString().ToLowerInvariant() - "ocsentinellastscanutc" = $generatedAtUtc - } + $fieldValues = @( + [pscustomobject]@{ Name = "ocsentinelstatus"; Type = "Text"; Value = [string]$Report.AlertState } + [pscustomobject]@{ Name = "ocsentinelreason"; Type = "Text"; Value = $Reason } + [pscustomobject]@{ Name = "ocsentinelbasestatus"; Type = "Text"; Value = [string]$Report.BaseAlertState } + [pscustomobject]@{ Name = "ocsentinelevents"; Type = "Integer"; Value = [int]$Report.TotalEvents } + [pscustomobject]@{ Name = "ocsentineluniqueips"; Type = "Integer"; Value = [int]$Report.UniqueIpCount } + [pscustomobject]@{ Name = "ocsentinelcvecritical"; Type = "Integer"; Value = [int]$Report.VulnerabilityCorrelation.CriticalCount } + [pscustomobject]@{ Name = "ocsentinelcvetotal"; Type = "Integer"; Value = [int]$Report.VulnerabilityCorrelation.TotalCount } + [pscustomobject]@{ Name = "ocsentinelmode"; Type = "Text"; Value = $Mode } + [pscustomobject]@{ Name = "ocsentineltriggered"; Type = "Checkbox"; Value = $Triggered } + [pscustomobject]@{ Name = "ocsentinellastscanutc"; Type = "DateTime"; Value = $generatedAtUtc } + ) $updated = 0 - foreach ($entry in $fieldValues.GetEnumerator()) { + foreach ($entry in $fieldValues) { try { - if (Set-NinjaCustomFieldValue -Name $entry.Key -Value $entry.Value) { + if (Set-NinjaCustomFieldValue -Name $entry.Name -Value $entry.Value -Type $entry.Type) { $updated++ } } catch { - Write-Warning "Failed to set Ninja custom field '$($entry.Key)': $($_.Exception.Message)" + Write-Warning "Failed to set Ninja custom field '$($entry.Name)': $($_.Exception.Message)" } } diff --git a/src/OCSentinelCli/OCSentinelCli.csproj b/src/OCSentinelCli/OCSentinelCli.csproj index 9c8a07b..0668ab5 100644 --- a/src/OCSentinelCli/OCSentinelCli.csproj +++ b/src/OCSentinelCli/OCSentinelCli.csproj @@ -9,10 +9,10 @@ OCSentinelCli OfficeCom Sentinel OfficeCom - 1.2.10 - 1.2.10.0 - 1.2.10.0 - 1.2.10 + 1.2.11 + 1.2.11.0 + 1.2.11.0 + 1.2.11