Adds new [INFO] state for Icinga check and checkpage objects

This commit is contained in:
Lord Hepipud 2025-12-15 13:59:36 +01:00
parent ad59bb9a3a
commit 97f2cb8c11
4 changed files with 99 additions and 24 deletions

View file

@ -19,8 +19,9 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Enhancements
* [#838](https://github.com/Icinga/icinga-powershell-framework/pull/838) Enhances Icinga for Windows to never load and user PowerShell profiles
* [#11](https://github.com/Icinga/icinga-powershell-framework/pull/11) Adds feature to update the cache for performance counter instances to keep track of system changes
* [#838](https://github.com/Icinga/icinga-powershell-framework/pull/838) Enhances Icinga for Windows to never load and user PowerShell profiles
* [#841](https://github.com/Icinga/icinga-powershell-framework/pull/841) Adds new [INFO] state for notice and un-checked monitoring objects
## 1.13.4 (tbd)

View file

@ -112,7 +112,7 @@ function New-IcingaCheck()
# Override shared function
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__SetCheckOutput' -Value {
param ($PluginOutput);
param ($PluginOutput, $CheckOverride);
if ($this.__InLockState()) {
return;
@ -140,9 +140,25 @@ function New-IcingaCheck()
$AddColon = $FALSE;
}
[string]$PluginStatusString = $IcingaEnums.IcingaExitCodeText[$this.__CheckState];
# If our thresholds are empty, we handle this as notice object
if (-not $CheckOverride -And ([string]::IsNullOrEmpty($this.__WarningValue.Threshold.Raw) -and [string]::IsNullOrEmpty($this.__CriticalValue.Threshold.Raw))) {
# If our call sets CheckOverride, it means we could have used something like SetWarning() before
# By doing so, we actively interact with the object and therefore we should not handle it as notice object
$this.__HandleAsNoticeObject = $TRUE;
}
# Set this object to [INFO] state in case it is a notice or no thresholds are defined
# This will ensure we tell the use which check is using active checks
if ($this.__IsNoticeObject -or $this.__HandleAsNoticeObject) {
$PluginStatusString = '[INFO]';
$this.__HandleAsNoticeObject = $TRUE;
}
$this.__CheckOutput = [string]::Format(
'{0} {1}{2} {3}{4}',
$IcingaEnums.IcingaExitCodeText[$this.__CheckState],
$PluginStatusString,
$this.Name,
(&{ if ($AddColon) { return ':'; } else { return ''; } }),
$PluginThresholds,
@ -296,7 +312,7 @@ function New-IcingaCheck()
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__ValidateObject' -Value {
if ($null -eq $this.ObjectExists) {
$this.SetUnknown() | Out-Null;
$this.__SetCheckOutput('The object does not exist');
$this.__SetCheckOutput('The object does not exist', $TRUE);
$this.__LockState();
}
}
@ -317,7 +333,8 @@ function New-IcingaCheck()
'Usage of invalid plugin unit "{0}". Allowed units are: {1}',
$this.Unit,
(($IcingaEnums.IcingaMeasurementUnits.Keys | Sort-Object name) -Join ', ')
)
),
$TRUE
);
$this.__LockState();
@ -395,8 +412,12 @@ function New-IcingaCheck()
param ([string]$Message, [bool]$Lock);
if ($this.__InLockState() -eq $FALSE) {
# If we update the state of an object to anything, we actively tell the system
# that this is no longer a notice object
$this.__HandleAsNoticeObject = $FALSE;
$this.__CheckState = $IcingaEnums.IcingaExitCode.Ok;
$this.__SetCheckOutput($Message);
$this.__SetCheckOutput($Message, $TRUE);
}
if ($Lock) {
@ -410,8 +431,11 @@ function New-IcingaCheck()
param ([string]$Message, [bool]$Lock);
if ($this.__InLockState() -eq $FALSE) {
# If we update the state of an object to anything, we actively tell the system
# that this is no longer a notice object
$this.__HandleAsNoticeObject = $FALSE;
$this.__CheckState = $IcingaEnums.IcingaExitCode.Warning;
$this.__SetCheckOutput($Message);
$this.__SetCheckOutput($Message, $TRUE);
}
if ($Lock) {
@ -425,7 +449,25 @@ function New-IcingaCheck()
param ([string]$Message, [bool]$Lock);
if ($this.__InLockState() -eq $FALSE) {
# If we update the state of an object to anything, we actively tell the system
# that this is no longer a notice object
$this.__HandleAsNoticeObject = $FALSE;
$this.__CheckState = $IcingaEnums.IcingaExitCode.Critical;
$this.__SetCheckOutput($Message, $TRUE);
}
if ($Lock) {
$this.__LockState();
}
return $this;
}
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'SetNotice' -Value {
param ([string]$Message, [bool]$Lock);
if ($this.__InLockState() -eq $FALSE) {
$this.__IsNoticeObject = $TRUE;
$this.__SetCheckOutput($Message);
}
@ -440,8 +482,11 @@ function New-IcingaCheck()
param ([string]$Message, [bool]$Lock);
if ($this.__InLockState() -eq $FALSE) {
# If we update the state of an object to anything, we actively tell the system
# that this is no longer a notice object
$this.__HandleAsNoticeObject = $FALSE;
$this.__CheckState = $IcingaEnums.IcingaExitCode.Unknown;
$this.__SetCheckOutput($Message);
$this.__SetCheckOutput($Message, $TRUE);
}
if ($Lock) {
@ -457,7 +502,7 @@ function New-IcingaCheck()
if ($ThresholdObject.HasError) {
$this.SetUnknown() | Out-Null;
$this.__ThresholdObject = $ThresholdObject;
$this.__SetCheckOutput($this.__ThresholdObject.Message);
$this.__SetCheckOutput($this.__ThresholdObject.Message, $TRUE);
$this.__LockState();
return;
}

View file

@ -2,17 +2,19 @@ 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 '__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 NoteProperty -Name 'Name' -Value '';
$IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name 'Verbose' -Value 0;
$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 '__IsNoticeObject' -Value $FALSE;
$IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__HandleAsNoticeObject' -Value $FALSE;
$IcingaCheckBaseObject | Add-Member -MemberType NoteProperty -Name '__ObjectType' -Value 'IcingaCheckBaseObject';
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetCheckCommand' -Value {
$CallStack = Get-PSCallStack;
@ -103,7 +105,7 @@ function New-IcingaCheckBaseObject()
}
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Force -Name '__SetCheckOutput' -Value {
param ($PluginOutput);
param ($PluginOutput, $CheckOverride);
}
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetCheckOutput' -Value {

View file

@ -9,9 +9,11 @@ function New-IcingaCheckPackage()
[int]$OperatorMax = -1,
[array]$Checks = @(),
[int]$Verbose = 0,
[int]$OverrideExitCode = -1,
[switch]$IgnoreEmptyPackage = $FALSE,
[switch]$Hidden = $FALSE,
[switch]$AddSummaryHeader = $FALSE
[switch]$AddSummaryHeader = $FALSE,
[switch]$IsNoticePackage = $FALSE
);
$IcingaCheckPackage = New-IcingaCheckBaseObject;
@ -28,6 +30,11 @@ function New-IcingaCheckPackage()
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name 'OperatorMax' -Value $OperatorMax;
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name 'IgnoreEmptyPackage' -Value $IgnoreEmptyPackage;
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name 'AddSummaryHeader' -Value $AddSummaryHeader;
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name 'OverrideExitCode' -Value $OverrideExitCode;
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name 'IsNoticePackage' -Value $IsNoticePackage;
# Each check package should have at least one element which provides active checks information,
# otherwise we should display the package as INFO package
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name '__hasActiveChecks' -Value $FALSE;
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name '__Checks' -Value @();
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name '__OkChecks' -Value @();
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name '__WarningChecks' -Value @();
@ -93,7 +100,7 @@ function New-IcingaCheckPackage()
# Override shared function
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Force -Name '__SetCheckOutput' -Value {
param ($PluginOutput);
param ($PluginOutput, $CheckOverride);
$UnknownChecks = '';
$CriticalChecks = '';
@ -140,9 +147,18 @@ function New-IcingaCheckPackage()
$HasContent = $TRUE;
}
[string]$PluginStatusString = $IcingaEnums.IcingaExitCodeText[$this.__GetCheckState()];
# Set this object to [INFO] state in case it is a notice package or no active checks are found
# This will ensure we tell the use which check is using active checks
if ($this.IsNoticePackage -or $this.__hasActiveChecks -eq $FALSE) {
$PluginStatusString = '[INFO]';
$this.__HandleAsNoticeObject = $TRUE;
}
$this.__CheckOutput = [string]::Format(
'{0} {1}{2}{3}{4}{5}{6}{7}{8}',
$IcingaEnums.IcingaExitCodeText[$this.__GetCheckState()],
$PluginStatusString,
$this.Name,
(&{ if ($HasContent) { return ':'; } else { return ''; } }),
$CheckSummary.ToString(),
@ -179,6 +195,13 @@ function New-IcingaCheckPackage()
$check.Compile();
# If we find at least one check which is not a notice object, we can consider
# this package as active checks package
if ($check.__HandleAsNoticeObject -eq $FALSE) {
$this.__hasActiveChecks = $TRUE;
$this.__HandleAsNoticeObject = $FALSE;
}
if ($check.__IsHidden() -Or $check.__NoHeaderReport()) {
continue;
}
@ -317,6 +340,10 @@ function New-IcingaCheckPackage()
return '';
}
if ($this.IsNoticePackage) {
return '';
}
if ($this.OperatorAnd) {
return ' (All must be [OK])';
}