From 0c83f7a70b351bb664adcb3a88b45df8e54defc7 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Wed, 13 Mar 2024 17:38:08 +0100 Subject: [PATCH] Adds support for check objects not being added to summary header --- doc/100-General/10-Changelog.md | 1 + lib/icinga/plugin/New-IcingaCheck.psm1 | 29 ++++++++-------- .../plugin/New-IcingaCheckBaseObject.psm1 | 33 ++++++++++++------- lib/icinga/plugin/New-IcingaCheckPackage.psm1 | 2 +- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index b963ba9..f93a7f2 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -28,6 +28,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#690](https://github.com/Icinga/icinga-powershell-framework/pull/690) Adds automatic renewal of the `icingaforwindows.pfx` certificate for the REST-Api daemon in case the certificate is not yet present, valid or changed during the runtime of the daemon while also making the `icingaforwindows.pfx` mandatory for all installations, regardless of JEA being used or not * [#692](https://github.com/Icinga/icinga-powershell-framework/pull/692) Renames `Restart-IcingaWindowsService` to `Restart-IcingaForWindows` and adds alias for backwards compatibility to start unifying the Icinga for Windows cmdlets * [#693](https://github.com/Icinga/icinga-powershell-framework/pull/693) Adds new command `Restart-Icinga` to restart both, the Icinga Agent and Icinga for Windows +* [#694](https://github.com/Icinga/icinga-powershell-framework/pull/694) Adds support for check objects not being added to summary header ## 1.11.2 (tbd) diff --git a/lib/icinga/plugin/New-IcingaCheck.psm1 b/lib/icinga/plugin/New-IcingaCheck.psm1 index e805be3..9a2a475 100644 --- a/lib/icinga/plugin/New-IcingaCheck.psm1 +++ b/lib/icinga/plugin/New-IcingaCheck.psm1 @@ -1,19 +1,20 @@ function New-IcingaCheck() { param( - [string]$Name = '', - $Value = $null, - $BaseValue = $null, - $Unit = '', - $MetricIndex = 'default', - $MetricName = '', - $MetricTemplate = '', - [string]$Minimum = '', - [string]$Maximum = '', - $ObjectExists = -1, - $Translation = $null, - [string]$LabelName = $null, - [switch]$NoPerfData = $FALSE + [string]$Name = '', + $Value = $null, + $BaseValue = $null, + $Unit = '', + $MetricIndex = 'default', + $MetricName = '', + $MetricTemplate = '', + [string]$Minimum = '', + [string]$Maximum = '', + $ObjectExists = -1, + $Translation = $null, + [string]$LabelName = $null, + [switch]$NoPerfData = $FALSE, + [switch]$NoHeaderReport = $FALSE ); $IcingaCheck = New-IcingaCheckBaseObject; @@ -45,6 +46,8 @@ function New-IcingaCheck() $IcingaCheck | Add-Member -MemberType NoteProperty -Name '__ThresholdObject' -Value $null; $IcingaCheck | Add-Member -MemberType NoteProperty -Name '__TimeInterval' -Value $null; + $IcingaCheck.__SetNoHeaderReport($NoHeaderReport); + $IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name 'Compile' -Value { $this.__ValidateThresholdInput(); if ($null -eq $this.__ThresholdObject) { diff --git a/lib/icinga/plugin/New-IcingaCheckBaseObject.psm1 b/lib/icinga/plugin/New-IcingaCheckBaseObject.psm1 index 555a655..ad854a7 100644 --- a/lib/icinga/plugin/New-IcingaCheckBaseObject.psm1 +++ b/lib/icinga/plugin/New-IcingaCheckBaseObject.psm1 @@ -2,17 +2,18 @@ function New-IcingaCheckBaseObject() { $IcingaCheckBaseObject = New-Object -TypeName PSObject; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name 'Name' -Value ''; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name 'Verbose' -Value 0; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__CheckPerfData' -Value @{ }; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__Hidden' -Value $FALSE; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__Parent' -Value $IcingaCheckBaseObject; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__Indention' -Value 0; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__ErrorMessage' -Value ''; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__CheckState' -Value $IcingaEnums.IcingaExitCode.Ok; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__CheckCommand' -Value ''; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__CheckOutput' -Value $null; - $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__ObjectType' -Value 'IcingaCheckBaseObject'; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name 'Name' -Value ''; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name 'Verbose' -Value 0; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__CheckPerfData' -Value @{ }; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__Hidden' -Value $FALSE; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__SkipSummary' -Value $FALSE; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__Parent' -Value $IcingaCheckBaseObject; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__Indention' -Value 0; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__ErrorMessage' -Value ''; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__CheckState' -Value $IcingaEnums.IcingaExitCode.Ok; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__CheckCommand' -Value ''; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__CheckOutput' -Value $null; + $IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__ObjectType' -Value 'IcingaCheckBaseObject'; $IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetCheckCommand' -Value { $CallStack = Get-PSCallStack; @@ -65,6 +66,16 @@ function New-IcingaCheckBaseObject() $this.__Hidden = $Hidden; } + $IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__NoHeaderReport' -Value { + return $this.__SkipSummary; + } + + $IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetNoHeaderReport' -Value { + param ([bool]$SkipSummary); + + $this.__SkipSummary = $SkipSummary; + } + $IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetName' -Value { return $this.Name; } diff --git a/lib/icinga/plugin/New-IcingaCheckPackage.psm1 b/lib/icinga/plugin/New-IcingaCheckPackage.psm1 index f31d483..9e5e8df 100644 --- a/lib/icinga/plugin/New-IcingaCheckPackage.psm1 +++ b/lib/icinga/plugin/New-IcingaCheckPackage.psm1 @@ -179,7 +179,7 @@ function New-IcingaCheckPackage() $check.Compile(); - if ($check.__IsHidden()) { + if ($check.__IsHidden() -Or $check.__NoHeaderReport()) { continue; }