Use documented NinjaOne custom field commands
Some checks failed
OfficeCom Sentinel Client / validate-client (push) Successful in 23s
OfficeCom Sentinel Client / build-client-windows (push) Failing after 18s

This commit is contained in:
OfficeCom Codex
2026-07-25 21:17:59 +02:00
parent 49b0e3025d
commit 7431c656d3
4 changed files with 68 additions and 46 deletions

View File

@@ -46,8 +46,13 @@ function Initialize-NinjaFieldWriter {
return return
} }
if (Get-Command -Name "Set-NinjaProperty" -ErrorAction SilentlyContinue) {
$script:NinjaFieldBackend = "powershell-modern"
return
}
if (Get-Command -Name "Ninja-Property-Set" -ErrorAction SilentlyContinue) { if (Get-Command -Name "Ninja-Property-Set" -ErrorAction SilentlyContinue) {
$script:NinjaFieldBackend = "powershell" $script:NinjaFieldBackend = "powershell-legacy"
return return
} }
@@ -64,14 +69,20 @@ function Set-NinjaCustomFieldValue {
[Parameter(Mandatory)] [Parameter(Mandatory)]
[string]$Name, [string]$Name,
[AllowEmptyString()] [AllowEmptyString()]
[string]$Value [object]$Value,
[Parameter(Mandatory)]
[string]$Type
) )
Initialize-NinjaFieldWriter Initialize-NinjaFieldWriter
switch ($script:NinjaFieldBackend) { switch ($script:NinjaFieldBackend) {
"powershell" { "powershell-modern" {
Ninja-Property-Set $Name $Value | Out-Null 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 return $true
} }
"cli" { "cli" {
@@ -112,28 +123,28 @@ function Publish-NinjaCustomFields {
} }
} }
$fieldValues = [ordered]@{ $fieldValues = @(
"ocsentinelstatus" = [string]$Report.AlertState [pscustomobject]@{ Name = "ocsentinelstatus"; Type = "Text"; Value = [string]$Report.AlertState }
"ocsentinelreason" = $Reason [pscustomobject]@{ Name = "ocsentinelreason"; Type = "Text"; Value = $Reason }
"ocsentinelbasestatus" = [string]$Report.BaseAlertState [pscustomobject]@{ Name = "ocsentinelbasestatus"; Type = "Text"; Value = [string]$Report.BaseAlertState }
"ocsentinelevents" = [string]([int]$Report.TotalEvents) [pscustomobject]@{ Name = "ocsentinelevents"; Type = "Integer"; Value = [int]$Report.TotalEvents }
"ocsentineluniqueips" = [string]([int]$Report.UniqueIpCount) [pscustomobject]@{ Name = "ocsentineluniqueips"; Type = "Integer"; Value = [int]$Report.UniqueIpCount }
"ocsentinelcvecritical" = [string]([int]$Report.VulnerabilityCorrelation.CriticalCount) [pscustomobject]@{ Name = "ocsentinelcvecritical"; Type = "Integer"; Value = [int]$Report.VulnerabilityCorrelation.CriticalCount }
"ocsentinelcvetotal" = [string]([int]$Report.VulnerabilityCorrelation.TotalCount) [pscustomobject]@{ Name = "ocsentinelcvetotal"; Type = "Integer"; Value = [int]$Report.VulnerabilityCorrelation.TotalCount }
"ocsentinelmode" = $Mode [pscustomobject]@{ Name = "ocsentinelmode"; Type = "Text"; Value = $Mode }
"ocsentineltriggered" = $Triggered.ToString().ToLowerInvariant() [pscustomobject]@{ Name = "ocsentineltriggered"; Type = "Checkbox"; Value = $Triggered }
"ocsentinellastscanutc" = $generatedAtUtc [pscustomobject]@{ Name = "ocsentinellastscanutc"; Type = "DateTime"; Value = $generatedAtUtc }
} )
$updated = 0 $updated = 0
foreach ($entry in $fieldValues.GetEnumerator()) { foreach ($entry in $fieldValues) {
try { try {
if (Set-NinjaCustomFieldValue -Name $entry.Key -Value $entry.Value) { if (Set-NinjaCustomFieldValue -Name $entry.Name -Value $entry.Value -Type $entry.Type) {
$updated++ $updated++
} }
} }
catch { 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)"
} }
} }

View File

@@ -1,8 +1,8 @@
{ {
"channel": "stable", "channel": "stable",
"version": "1.2.10", "version": "1.2.11",
"publishedAtUtc": "2026-07-25T19:14:36.9210206Z", "publishedAtUtc": "2026-07-25T19:17:43.7567344Z",
"artifactUrl": "https://gitea.officecom.cloud/officecom/oc-sentinel/releases/download/v1.2.10/OCSentinelClient-win-x64.zip", "artifactUrl": "https://gitea.officecom.cloud/officecom/oc-sentinel/releases/download/v1.2.11/OCSentinelClient-win-x64.zip",
"sha256": "4de7abf96ff9ed47da02ac7f586cc39102fa508372825c2f7bf5e1df2b0f6c80", "sha256": "4a5415ce281f444a987a3fd72980c159afaa37787bbaa396f42d2c496736e5e1",
"minUpdaterVersion": "1.0.0" "minUpdaterVersion": "1.0.0"
} }

View File

@@ -46,8 +46,13 @@ function Initialize-NinjaFieldWriter {
return return
} }
if (Get-Command -Name "Set-NinjaProperty" -ErrorAction SilentlyContinue) {
$script:NinjaFieldBackend = "powershell-modern"
return
}
if (Get-Command -Name "Ninja-Property-Set" -ErrorAction SilentlyContinue) { if (Get-Command -Name "Ninja-Property-Set" -ErrorAction SilentlyContinue) {
$script:NinjaFieldBackend = "powershell" $script:NinjaFieldBackend = "powershell-legacy"
return return
} }
@@ -64,14 +69,20 @@ function Set-NinjaCustomFieldValue {
[Parameter(Mandatory)] [Parameter(Mandatory)]
[string]$Name, [string]$Name,
[AllowEmptyString()] [AllowEmptyString()]
[string]$Value [object]$Value,
[Parameter(Mandatory)]
[string]$Type
) )
Initialize-NinjaFieldWriter Initialize-NinjaFieldWriter
switch ($script:NinjaFieldBackend) { switch ($script:NinjaFieldBackend) {
"powershell" { "powershell-modern" {
Ninja-Property-Set $Name $Value | Out-Null 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 return $true
} }
"cli" { "cli" {
@@ -112,28 +123,28 @@ function Publish-NinjaCustomFields {
} }
} }
$fieldValues = [ordered]@{ $fieldValues = @(
"ocsentinelstatus" = [string]$Report.AlertState [pscustomobject]@{ Name = "ocsentinelstatus"; Type = "Text"; Value = [string]$Report.AlertState }
"ocsentinelreason" = $Reason [pscustomobject]@{ Name = "ocsentinelreason"; Type = "Text"; Value = $Reason }
"ocsentinelbasestatus" = [string]$Report.BaseAlertState [pscustomobject]@{ Name = "ocsentinelbasestatus"; Type = "Text"; Value = [string]$Report.BaseAlertState }
"ocsentinelevents" = [string]([int]$Report.TotalEvents) [pscustomobject]@{ Name = "ocsentinelevents"; Type = "Integer"; Value = [int]$Report.TotalEvents }
"ocsentineluniqueips" = [string]([int]$Report.UniqueIpCount) [pscustomobject]@{ Name = "ocsentineluniqueips"; Type = "Integer"; Value = [int]$Report.UniqueIpCount }
"ocsentinelcvecritical" = [string]([int]$Report.VulnerabilityCorrelation.CriticalCount) [pscustomobject]@{ Name = "ocsentinelcvecritical"; Type = "Integer"; Value = [int]$Report.VulnerabilityCorrelation.CriticalCount }
"ocsentinelcvetotal" = [string]([int]$Report.VulnerabilityCorrelation.TotalCount) [pscustomobject]@{ Name = "ocsentinelcvetotal"; Type = "Integer"; Value = [int]$Report.VulnerabilityCorrelation.TotalCount }
"ocsentinelmode" = $Mode [pscustomobject]@{ Name = "ocsentinelmode"; Type = "Text"; Value = $Mode }
"ocsentineltriggered" = $Triggered.ToString().ToLowerInvariant() [pscustomobject]@{ Name = "ocsentineltriggered"; Type = "Checkbox"; Value = $Triggered }
"ocsentinellastscanutc" = $generatedAtUtc [pscustomobject]@{ Name = "ocsentinellastscanutc"; Type = "DateTime"; Value = $generatedAtUtc }
} )
$updated = 0 $updated = 0
foreach ($entry in $fieldValues.GetEnumerator()) { foreach ($entry in $fieldValues) {
try { try {
if (Set-NinjaCustomFieldValue -Name $entry.Key -Value $entry.Value) { if (Set-NinjaCustomFieldValue -Name $entry.Name -Value $entry.Value -Type $entry.Type) {
$updated++ $updated++
} }
} }
catch { 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)"
} }
} }

View File

@@ -9,10 +9,10 @@
<RootNamespace>OCSentinelCli</RootNamespace> <RootNamespace>OCSentinelCli</RootNamespace>
<Product>OfficeCom Sentinel</Product> <Product>OfficeCom Sentinel</Product>
<Company>OfficeCom</Company> <Company>OfficeCom</Company>
<Version>1.2.10</Version> <Version>1.2.11</Version>
<AssemblyVersion>1.2.10.0</AssemblyVersion> <AssemblyVersion>1.2.11.0</AssemblyVersion>
<FileVersion>1.2.10.0</FileVersion> <FileVersion>1.2.11.0</FileVersion>
<InformationalVersion>1.2.10</InformationalVersion> <InformationalVersion>1.2.11</InformationalVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>