Merge pull request #136 from Icinga/feature/add_support_to_ignore_empty_checkpackages

Feature: Adds support to ignore empty check packages
This commit is contained in:
Lord Hepipud 2020-10-15 15:20:42 +02:00 committed by GitHub
commit 8fe4ea984d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 39 deletions

View file

@ -11,6 +11,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/10?closed=1)
### Enhancements
* [#136](https://github.com/Icinga/icinga-powershell-framework/pull/136) Adds support to ignore empty check packages and return `Ok` instead of `Unknown` if `-IgnoreEmptyPackage` is set on `New-IcingaCheckPackage`
### Bugfixes
* [#127](https://github.com/Icinga/icinga-powershell-framework/issues/127) Fixes wrong error message on failed MSSQL connection due to database not reachable by using `-IntegratedSecurity`

View file

@ -10,7 +10,6 @@ The `IcingaCheckPackage` is the first step to take to write more advanced checks
It will be used like in this example:
```powershell
$IcingaPackage = New-IcingaCheckPackage -Name 'My Package' -OperatorAnd;
```
@ -27,9 +26,9 @@ $IcingaPackage = New-IcingaCheckPackage -Name 'My Package' -OperatorAnd;
| OperatorMax | Int | | Maximum of `n` added checks/packages requires to return Ok for this package to be Ok |
| Checks | Array | | Array of checks to be added to the check package |
| Verbose | int | | Defines the level of output detail from 0 lowest to 3 highest detail |
| IgnoreEmptyPackage | Switch | | By default a check package will return `Unknown` in case no checks are assigned. Setting this argument will ignore this and return `Ok` instead
| Hidden | Switch | | If set, the check package doesn't generate output |
### Examples
#### Example 1
@ -47,4 +46,3 @@ $IcingaPackage = New-IcingaCheckPackage -Name 'My Package' -OperatorAnd;
$IcingaPackage.AddCheck($IcingaCheck1);
$IcingaPackage.AddCheck($IcingaCheck2);
```

View file

@ -12,6 +12,7 @@ function New-IcingaCheckPackage()
[int]$OperatorMax = -1,
[array]$Checks = @(),
[int]$Verbose = 0,
[switch]$IgnoreEmptyPackage = $FALSE,
[switch]$Hidden = $FALSE
);
@ -20,6 +21,7 @@ function New-IcingaCheckPackage()
$Check | Add-Member -MemberType NoteProperty -Name 'exitcode' -Value -1;
$Check | Add-Member -MemberType NoteProperty -Name 'verbose' -Value $Verbose;
$Check | Add-Member -MemberType NoteProperty -Name 'hidden' -Value $Hidden;
$Check | Add-Member -MemberType NoteProperty -Name 'ignoreemptypackage' -Value $IgnoreEmptyPackage;
$Check | Add-Member -MemberType NoteProperty -Name 'checks' -Value $Checks;
$Check | Add-Member -MemberType NoteProperty -Name 'opand' -Value $OperatorAnd;
$Check | Add-Member -MemberType NoteProperty -Name 'opor' -Value $OperatorOr;
@ -153,9 +155,13 @@ function New-IcingaCheckPackage()
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok;
}
}
} else {
if ($this.ignoreemptypackage) {
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok;
} else {
$this.exitcode = $IcingaEnums.IcingaExitCode.Unknown;
}
}
if ([int]$this.exitcode -eq -1) {
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok;