mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Re-Write execution of checks
This commit is contained in:
parent
b782d44242
commit
a9126ce402
20 changed files with 1904 additions and 1305 deletions
|
|
@ -24,11 +24,12 @@ For performance metrics you can provide a `Unit` to ensure your graphing is disp
|
||||||
|
|
||||||
| Argument | Input | Mandatory | Description |
|
| Argument | Input | Mandatory | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| Name | String | * | The unique name of each check within a plugin. Will be display in the check output. |
|
| Name | String | * | The unique name of each check within a plugin. Will be display in the check output. |
|
||||||
| Value | Object | * | The value all comparison is done with. In general this should be a `Numeric` or `String` value |
|
| Value | Object | * | The value all comparison is done with. In general this should be a `Numeric` or `String` value |
|
||||||
| Unit | Units | | Specify the unit for a value to display graph properly |
|
| Unit | Units | | Specify the unit for a value to display graph properly |
|
||||||
| Minimum | String | | The minimum value which is displayed on your graphs |
|
| Minimum | String | | The minimum value which is displayed on your graphs |
|
||||||
| Maximum | String | | The maximum value which is displayed on your graphs |
|
| Maximum | String | | The maximum value which is displayed on your graphs |
|
||||||
|
| BaseValue | Object | | Sets a base value for the check which allows to use dynamic `%` usage on thresholds. The base value will calculate the `%` value from the current value, allowing generic `%` monitoring |
|
||||||
| ObjectExists | Bool | | If you are using values coming from objects, like Services, you can use this argument to determin if the object itself exist or not. In case it doesn't, you will receive a proper output on the check result |
|
| ObjectExists | Bool | | If you are using values coming from objects, like Services, you can use this argument to determin if the object itself exist or not. In case it doesn't, you will receive a proper output on the check result |
|
||||||
| Translation | Hashtable | | In case you want to map values to certain descriptions, you can place a hashtable at this argument which will then map the value to the description on the check result. For example this would apply to service running states |
|
| Translation | Hashtable | | In case you want to map values to certain descriptions, you can place a hashtable at this argument which will then map the value to the description on the check result. For example this would apply to service running states |
|
||||||
| LabelName | String | | Allows to override the default label name generated based on the `-Name` argument to a custom name. Please ensure to remove any special characters manually, as the name set here is the exact name for the label |
|
| LabelName | String | | Allows to override the default label name generated based on the `-Name` argument to a custom name. Please ensure to remove any special characters manually, as the name set here is the exact name for the label |
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ $IcingaPackage = New-IcingaCheckPackage -Name 'My Package' -OperatorAnd;
|
||||||
| Checks | Array | | Array of checks to be added to the check package |
|
| 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 |
|
| 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
|
| 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
|
||||||
|
| AddSummaryHeader | Switch | | Adds a summary on how many checks are Unknown, Critical, Warning and Ok on the output of the package
|
||||||
| Hidden | Switch | | If set, the check package doesn't generate output |
|
| Hidden | Switch | | If set, the check package doesn't generate output |
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@ function Convert-Bytes()
|
||||||
[string]$Unit
|
[string]$Unit
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# Ensure we always use proper formatting of values
|
||||||
|
$Value = $Value.Replace(',', '.');
|
||||||
|
|
||||||
If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)") -eq $FALSE) {
|
If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)") -eq $FALSE) {
|
||||||
$Value = [string]::Format('{0}B', $Value);
|
$Value = [string]::Format('{0}B', $Value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
lib/core/tools/Convert-IcingaCheckArgumentToPSObject.psm1
Normal file
24
lib/core/tools/Convert-IcingaCheckArgumentToPSObject.psm1
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
function Convert-IcingaCheckArgumentToPSObject()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
$Parameter = $null
|
||||||
|
);
|
||||||
|
|
||||||
|
$ParamValue = New-Object -TypeName PSObject;
|
||||||
|
|
||||||
|
if ($null -eq $parameter) {
|
||||||
|
return $ParamValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ParamValue | Add-Member -MemberType NoteProperty -Name 'type' -Value (New-Object -TypeName PSObject);
|
||||||
|
$ParamValue | Add-Member -MemberType NoteProperty -Name 'Description' -Value (New-Object -TypeName PSObject);
|
||||||
|
$ParamValue | Add-Member -MemberType NoteProperty -Name 'Attributes' -Value (New-Object -TypeName PSObject);
|
||||||
|
$ParamValue | Add-Member -MemberType NoteProperty -Name 'position' -Value $Parameter.position;
|
||||||
|
$ParamValue | Add-Member -MemberType NoteProperty -Name 'Name' -Value $Parameter.name;
|
||||||
|
$ParamValue | Add-Member -MemberType NoteProperty -Name 'required' -Value $Parameter.required;
|
||||||
|
$ParamValue.type | Add-Member -MemberType NoteProperty -Name 'name' -Value $Parameter.type.name;
|
||||||
|
$ParamValue.Description | Add-Member -MemberType NoteProperty -Name 'Text' -Value $Parameter.Description.Text;
|
||||||
|
$ParamValue.Attributes | Add-Member -MemberType NoteProperty -Name 'ValidValues' -Value $null;
|
||||||
|
|
||||||
|
return $ParamValue;
|
||||||
|
}
|
||||||
38
lib/core/tools/Convert-IcingaPluginValueToString.psm1
Normal file
38
lib/core/tools/Convert-IcingaPluginValueToString.psm1
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
function Convert-IcingaPluginValueToString()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
$Value,
|
||||||
|
[string]$Unit = '',
|
||||||
|
[string]$OriginalUnit = ''
|
||||||
|
);
|
||||||
|
|
||||||
|
$AdjustedValue = $Value;
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($OriginalUnit)) {
|
||||||
|
$OriginalUnit = $Unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$AdjustedValue = ([math]::Round([decimal]$Value, 6))
|
||||||
|
} catch {
|
||||||
|
$AdjustedValue = $Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($Unit -eq '%' -Or [string]::IsNullOrEmpty($Unit)) {
|
||||||
|
return ([string]::Format('{0}{1}', $AdjustedValue, $Unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($OriginalUnit) {
|
||||||
|
{ ($_ -eq "B") -or ($_ -eq "KiB") -or ($_ -eq "MiB") -or ($_ -eq "GiB") -or ($_ -eq "TiB") -or ($_ -eq "PiB") -or ($_ -eq "EiB") -or ($_ -eq "ZiB") -or ($_ -eq "YiB") } {
|
||||||
|
return (ConvertTo-BytesNextUnit -Value $Value -Unit $Unit -Units @('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'));
|
||||||
|
};
|
||||||
|
{ ($_ -eq "KB") -or ($_ -eq "MB") -or ($_ -eq "GB") -or ($_ -eq "TB") -or ($_ -eq "PB") -or ($_ -eq "EB") -or ($_ -eq "ZB") -or ($_ -eq "YB") } {
|
||||||
|
return (ConvertTo-BytesNextUnit -Value $Value -Unit $Unit -Units @('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'));
|
||||||
|
};
|
||||||
|
's' {
|
||||||
|
return (ConvertFrom-TimeSpan -Seconds $AdjustedValue)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return ([string]::Format('{0}{1}', $AdjustedValue, $Unit));
|
||||||
|
}
|
||||||
14
lib/core/tools/ConvertFrom-Percent.psm1
Normal file
14
lib/core/tools/ConvertFrom-Percent.psm1
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
function ConvertFrom-Percent()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
$Value = $null,
|
||||||
|
$Percent = $null,
|
||||||
|
[int]$Digits = 0
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($null -eq $Value -Or $null -eq $Percent) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ([math]::Round(($Value / 100 * $Percent), $Digits));
|
||||||
|
}
|
||||||
|
|
@ -2,17 +2,52 @@ Import-IcingaLib core\tools;
|
||||||
|
|
||||||
function ConvertFrom-TimeSpan()
|
function ConvertFrom-TimeSpan()
|
||||||
{
|
{
|
||||||
param(
|
param (
|
||||||
$Seconds
|
$Seconds = 0
|
||||||
);
|
);
|
||||||
|
|
||||||
$TimeSpan = [TimeSpan]::FromSeconds($Seconds);
|
$TimeSpan = [TimeSpan]::FromSeconds($Seconds);
|
||||||
|
|
||||||
return [string]::Format(
|
if ($TimeSpan.TotalDays -ge 1.0) {
|
||||||
'{0}d {1}h {2}m {3}s',
|
return (
|
||||||
$TimeSpan.Days,
|
[string]::Format(
|
||||||
$TimeSpan.Hours,
|
'{0}d',
|
||||||
$TimeSpan.Minutes,
|
$TimeSpan.TotalDays
|
||||||
$TimeSpan.Seconds
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
if ($TimeSpan.TotalHours -ge 1.0) {
|
||||||
|
return (
|
||||||
|
[string]::Format(
|
||||||
|
'{0}h',
|
||||||
|
$TimeSpan.TotalHours
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($TimeSpan.TotalMinutes -ge 1.0) {
|
||||||
|
return (
|
||||||
|
[string]::Format(
|
||||||
|
'{0}m',
|
||||||
|
$TimeSpan.TotalMinutes
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($TimeSpan.TotalSeconds -ge 1.0) {
|
||||||
|
return (
|
||||||
|
[string]::Format(
|
||||||
|
'{0}s',
|
||||||
|
$TimeSpan.TotalSeconds
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($TimeSpan.TotalMilliseconds -gt 0) {
|
||||||
|
return (
|
||||||
|
[string]::Format(
|
||||||
|
'{0}ms',
|
||||||
|
$TimeSpan.TotalMilliseconds
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ([string]::Format('{0}s', $Seconds));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
30
lib/core/tools/ConvertTo-BytesNextUnit.psm1
Normal file
30
lib/core/tools/ConvertTo-BytesNextUnit.psm1
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
function ConvertTo-BytesNextUnit()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$Value = $null,
|
||||||
|
[string]$Unit = $null,
|
||||||
|
[array]$Units = @('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB')
|
||||||
|
);
|
||||||
|
|
||||||
|
[string]$UnitValue = [string]::Format('{0}{1}', $Value, $Unit);
|
||||||
|
|
||||||
|
while ($TRUE) {
|
||||||
|
$Unit = Get-IcingaNextUnitIteration -Unit $Unit -Units $Units;
|
||||||
|
[decimal]$NewValue = (Convert-Bytes -Value $UnitValue -Unit $Unit).Value;
|
||||||
|
if ($NewValue -ge 1.0) {
|
||||||
|
if ($Unit -eq $RetUnit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$RetValue = [math]::Round([decimal]$NewValue, 2);
|
||||||
|
$RetUnit = $Unit;
|
||||||
|
} else {
|
||||||
|
if ([string]::IsNullOrEmpty($RetUnit)) {
|
||||||
|
$RetValue = $Value;
|
||||||
|
$RetUnit = 'B';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ([string]::Format('{0}{1}', $RetValue, $RetUnit));
|
||||||
|
}
|
||||||
|
|
@ -77,24 +77,28 @@ function Get-IcingaCheckCommandConfig()
|
||||||
[switch]$IcingaConfig
|
[switch]$IcingaConfig
|
||||||
);
|
);
|
||||||
|
|
||||||
|
[array]$BlacklistedArguments = @(
|
||||||
|
'ThresholdInterval'
|
||||||
|
);
|
||||||
|
|
||||||
# Check whether all Checks will be exported or just the ones specified
|
# Check whether all Checks will be exported or just the ones specified
|
||||||
if ([string]::IsNullOrEmpty($CheckName) -eq $true) {
|
if ([string]::IsNullOrEmpty($CheckName) -eq $true) {
|
||||||
$CheckName = (Get-Command Invoke-IcingaCheck*).Name
|
$CheckName = (Get-Command Invoke-IcingaCheck*).Name
|
||||||
}
|
}
|
||||||
|
|
||||||
[int]$FieldID = 2; # Starts at '2', because '0' and '1' are reserved for 'Verbose' and 'NoPerfData'
|
[int]$FieldID = 2; # Starts at '2', because '0' and '1' are reserved for 'Verbose' and 'NoPerfData'
|
||||||
[hashtable]$Basket = @{};
|
[hashtable]$Basket = @{ };
|
||||||
|
|
||||||
# Define basic hashtable structure by adding fields: "Datafield", "DataList", "Command"
|
# Define basic hashtable structure by adding fields: "Datafield", "DataList", "Command"
|
||||||
$Basket.Add('Datafield', @{});
|
$Basket.Add('Datafield', @{ });
|
||||||
$Basket.Add('DataList', @{});
|
$Basket.Add('DataList', @{ });
|
||||||
$Basket.Add('Command', @{});
|
$Basket.Add('Command', @{ });
|
||||||
|
|
||||||
# At first generate a base Check-Command we can use as import source for all other commands
|
# At first generate a base Check-Command we can use as import source for all other commands
|
||||||
$Basket.Command.Add(
|
$Basket.Command.Add(
|
||||||
'PowerShell Base',
|
'PowerShell Base',
|
||||||
@{
|
@{
|
||||||
'arguments' = @{};
|
'arguments' = @{ };
|
||||||
'command' = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe';
|
'command' = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe';
|
||||||
'disabled' = $FALSE;
|
'disabled' = $FALSE;
|
||||||
'fields' = @();
|
'fields' = @();
|
||||||
|
|
@ -104,26 +108,55 @@ function Get-IcingaCheckCommandConfig()
|
||||||
'object_name' = 'PowerShell Base';
|
'object_name' = 'PowerShell Base';
|
||||||
'object_type' = 'object';
|
'object_type' = 'object';
|
||||||
'timeout' = '180';
|
'timeout' = '180';
|
||||||
'vars' = @{};
|
'vars' = @{ };
|
||||||
'zone' = $NULL;
|
'zone' = $NULL;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$ThresholdIntervalArg = New-Object -TypeName PSObject;
|
||||||
|
$ThresholdIntervalArg | Add-Member -MemberType NoteProperty -Name 'type' -Value (New-Object -TypeName PSObject);
|
||||||
|
$ThresholdIntervalArg | Add-Member -MemberType NoteProperty -Name 'Description' -Value (New-Object -TypeName PSObject);
|
||||||
|
$ThresholdIntervalArg | Add-Member -MemberType NoteProperty -Name 'position' -Value 99;
|
||||||
|
$ThresholdIntervalArg | Add-Member -MemberType NoteProperty -Name 'Name' -Value 'ThresholdInterval';
|
||||||
|
$ThresholdIntervalArg | Add-Member -MemberType NoteProperty -Name 'required' -Value $FALSE;
|
||||||
|
$ThresholdIntervalArg.type | Add-Member -MemberType NoteProperty -Name 'name' -Value 'String';
|
||||||
|
$ThresholdIntervalArg.Description | Add-Member -MemberType NoteProperty -Name 'Text' -Value 'Change the value your defined threshold checks against from the current value to a collected time threshold of the Icinga for Windows daemon, as described here: https://icinga.com/docs/icinga-for-windows/latest/doc/service/10-Register-Service-Checks/ An example for this argument would be 1m or 15m which will use the average of 1m or 15m for monitoring.';
|
||||||
|
|
||||||
# Loop through ${CheckName}, to get information on every command specified/all commands.
|
# Loop through ${CheckName}, to get information on every command specified/all commands.
|
||||||
foreach ($check in $CheckName) {
|
foreach ($check in $CheckName) {
|
||||||
|
|
||||||
# Get necessary syntax-information and more through cmdlet "Get-Help"
|
# Get necessary syntax-information and more through cmdlet "Get-Help"
|
||||||
$Data = (Get-Help $check);
|
$Data = (Get-Help $check);
|
||||||
$ParameterList = (Get-Command -Name $check).Parameters;
|
$ParameterList = (Get-Command -Name $check).Parameters;
|
||||||
|
$CheckParamList = @( $ThresholdIntervalArg );
|
||||||
$PluginNameSpace = $Data.Name.Replace('Invoke-', '');
|
$PluginNameSpace = $Data.Name.Replace('Invoke-', '');
|
||||||
|
|
||||||
|
foreach ($entry in $Data.parameters.parameter) {
|
||||||
|
foreach ($BlackListArg in $BlacklistedArguments) {
|
||||||
|
if ($BlackListArg.ToLower() -eq $entry.Name.ToLower()) {
|
||||||
|
Write-IcingaConsoleError -Message 'The argument "{0}" for check command "{1}" is not allowed, as this is reserved as Framework constant argument and can not be used.' -Objects $BlackListArg, $check;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$CheckParamList += (Convert-IcingaCheckArgumentToPSObject -Parameter $entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($arg in $ParameterList.Keys) {
|
||||||
|
foreach ($entry in $CheckParamList) {
|
||||||
|
if ($entry.Name -eq $arg) {
|
||||||
|
$entry.Attributes.ValidValues = $ParameterList[$arg].Attributes.ValidValues;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Add command Structure
|
# Add command Structure
|
||||||
$Basket.Command.Add(
|
$Basket.Command.Add(
|
||||||
$Data.Name, @{
|
$Data.Name, @{
|
||||||
'arguments' = @{
|
'arguments' = @{
|
||||||
# Set the Command handling for every check command
|
# Set the Command handling for every check command
|
||||||
'-C' = @{
|
'-C' = @{
|
||||||
'value' = [string]::Format('try {{ Use-Icinga -Minimal; }} catch {{ Write-Output {1}The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details{1}; exit 3; }}; Exit-IcingaExecutePlugin -Command {1}{0}{1} ', $Data.Name, "'");
|
'value' = [string]::Format('try {{ Use-Icinga -Minimal; }} catch {{ Write-Output {1}The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details{1}; Write-Output "Error: $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable "icinga-powershell-*" )`r`nModule-Path:`r`n$$($$Env:PSModulePath)"; exit 3; }}; Exit-IcingaExecutePlugin -Command {1}{0}{1} ', $Data.Name, "'");
|
||||||
'order' = '0';
|
'order' = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +169,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
);
|
);
|
||||||
|
|
||||||
# Loop through parameters of a given command
|
# Loop through parameters of a given command
|
||||||
foreach ($parameter in $Data.parameters.parameter) {
|
foreach ($parameter in $CheckParamList) {
|
||||||
|
|
||||||
$IsDataList = $FALSE;
|
$IsDataList = $FALSE;
|
||||||
|
|
||||||
|
|
@ -243,9 +276,9 @@ function Get-IcingaCheckCommandConfig()
|
||||||
|
|
||||||
$DataListName = [string]::Format('{0} {1}', $PluginNameSpace, $parameter.Name);
|
$DataListName = [string]::Format('{0} {1}', $PluginNameSpace, $parameter.Name);
|
||||||
|
|
||||||
if ($null -ne $ParameterList[$parameter.Name].Attributes.ValidValues) {
|
if ($null -ne $parameter.Attributes.ValidValues) {
|
||||||
$IcingaDataType = 'Datalist';
|
$IcingaDataType = 'Datalist';
|
||||||
Add-PowerShellDataList -Name $DataListName -Basket $Basket -Arguments $ParameterList[$parameter.Name].Attributes.ValidValues;
|
Add-PowerShellDataList -Name $DataListName -Basket $Basket -Arguments $parameter.Attributes.ValidValues;
|
||||||
$IsDataList = $TRUE;
|
$IsDataList = $TRUE;
|
||||||
} elseif ($parameter.type.name -eq 'SwitchParameter') {
|
} elseif ($parameter.type.name -eq 'SwitchParameter') {
|
||||||
$IcingaDataType = 'Boolean';
|
$IcingaDataType = 'Boolean';
|
||||||
|
|
@ -315,8 +348,13 @@ function Get-IcingaCheckCommandConfig()
|
||||||
|
|
||||||
$Data = (Get-Help $check)
|
$Data = (Get-Help $check)
|
||||||
$PluginNameSpace = $Data.Name.Replace('Invoke-', '');
|
$PluginNameSpace = $Data.Name.Replace('Invoke-', '');
|
||||||
|
$CheckParamList = @( $ThresholdIntervalArg );
|
||||||
|
|
||||||
foreach ($parameter in $Data.parameters.parameter) {
|
foreach ($entry in $Data.parameters.parameter) {
|
||||||
|
$CheckParamList += (Convert-IcingaCheckArgumentToPSObject -Parameter $entry);;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($parameter in $CheckParamList) {
|
||||||
$IcingaCustomVariable = [string]::Format('{0}_{1}_{2}', $PluginNameSpace, (Get-Culture).TextInfo.ToTitleCase($parameter.type.name), $parameter.Name);
|
$IcingaCustomVariable = [string]::Format('{0}_{1}_{2}', $PluginNameSpace, (Get-Culture).TextInfo.ToTitleCase($parameter.type.name), $parameter.Name);
|
||||||
|
|
||||||
# Todo: Should we improve this? Actually the handling would be identical, we just need to assign
|
# Todo: Should we improve this? Actually the handling would be identical, we just need to assign
|
||||||
|
|
|
||||||
20
lib/core/tools/Get-IcingaNextUnitIteration.psm1
Normal file
20
lib/core/tools/Get-IcingaNextUnitIteration.psm1
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
function Get-IcingaNextUnitIteration()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$Unit = '',
|
||||||
|
[array]$Units = @()
|
||||||
|
);
|
||||||
|
|
||||||
|
[bool]$Found = $FALSE;
|
||||||
|
|
||||||
|
foreach ($entry in $Units) {
|
||||||
|
if ($Found) {
|
||||||
|
return $entry;
|
||||||
|
}
|
||||||
|
if ($entry -eq $Unit) {
|
||||||
|
$Found = $TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
@ -10,8 +10,9 @@ function Get-IcingaHelpThresholds()
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($Value) -eq $FALSE) {
|
if ([string]::IsNullOrEmpty($Value) -eq $FALSE) {
|
||||||
$ExampleCheck = New-IcingaCheck -Name 'Example' -Value $Value;
|
$ExampleCheck = New-IcingaCheck -Name 'Example' -Value $Value;
|
||||||
$ExampleCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical).Compile($TRUE) | Out-Null;
|
$ExampleCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||||
return;
|
|
||||||
|
return (New-IcingaCheckResult -Check $ExampleCheck -Compile);
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-IcingaConsolePlain
|
Write-IcingaConsolePlain
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
[hashtable]$Configuration = @{
|
[hashtable]$Configuration = @{
|
||||||
PluginArgumentConflict = 'Your plugin argument configuration is causing a conflict. Mostly this error is caused by missmatching configurations by enabling multiple switch arguments which are resulting in a conflicting configuration for the plugin.';
|
PluginArgumentConflict = 'Your plugin argument configuration is causing a conflict. Mostly this error is caused by missmatching configurations by enabling multiple switch arguments which are resulting in a conflicting configuration for the plugin.';
|
||||||
PluginArgumentMissing = 'Your plugin argument configuration is missing mandatory arguments. This is error is caused when mandatory or required arguments are missing from a plugin call and the operation is unable to process without them.';
|
PluginArgumentMissing = 'Your plugin argument configuration is missing mandatory arguments. This error is caused when mandatory or required arguments are missing from a plugin call and the operation is unable to process without them.';
|
||||||
PluginNotInstalled = 'The plugin assigned to this service check seems not to be installed on this machine. Please review your service check configuration for spelling errors and check if the plugin is installed and executable on this machine by PowerShell.';
|
PluginNotInstalled = 'The plugin assigned to this service check seems not to be installed on this machine. Please review your service check configuration for spelling errors and check if the plugin is installed and executable on this machine by PowerShell.';
|
||||||
PluginNotAssigned = 'Your check for this service could not be processed because it seems like no valid Cmdlet was assigned to the check command. Please review your check command to ensure that a valid Cmdlet is assigned and executed by a PowerShell call.';
|
PluginNotAssigned = 'Your check for this service could not be processed because it seems like no valid Cmdlet was assigned to the check command. Please review your check command to ensure that a valid Cmdlet is assigned and executed by a PowerShell call.';
|
||||||
EventLogNotInstalled = 'Your Icinga PowerShell Framework has been executed by an unprivileged user before it was properly installed. The Windows EventLog application could not be registered because the current user has insufficient permissions. Please log into the machine and run "Use-Icinga" once from an administrative shell to complete the setup process. Once done this error should vanish.';
|
EventLogNotInstalled = 'Your Icinga PowerShell Framework has been executed by an unprivileged user before it was properly installed. The Windows EventLog application could not be registered because the current user has insufficient permissions. Please log into the machine and run "Use-Icinga" once from an administrative shell to complete the setup process. Once done this error should vanish.';
|
||||||
|
|
|
||||||
421
lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1
Normal file
421
lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1
Normal file
|
|
@ -0,0 +1,421 @@
|
||||||
|
function Compare-IcingaPluginThresholds()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$Threshold = $null,
|
||||||
|
$InputValue = $null,
|
||||||
|
$BaseValue = $null,
|
||||||
|
[switch]$Matches = $FALSE,
|
||||||
|
[switch]$NotMatches = $FALSE,
|
||||||
|
[string]$Unit = '',
|
||||||
|
$ThresholdCache = $null,
|
||||||
|
[string]$CheckName = '',
|
||||||
|
[hashtable]$Translation = @{ },
|
||||||
|
$Minium = $null,
|
||||||
|
$Maximum = $null,
|
||||||
|
[switch]$IsBetween = $FALSE,
|
||||||
|
[switch]$IsLowerEqual = $FALSE,
|
||||||
|
[switch]$IsGreaterEqual = $FALSE,
|
||||||
|
[string]$TimeInterval = $null
|
||||||
|
);
|
||||||
|
|
||||||
|
$IcingaThresholds = New-Object -TypeName PSObject;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Value' -Value $InputValue;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'BaseValue' -Value $BaseValue;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'RawValue' -Value $InputValue;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Unit' -Value $Unit;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'OriginalUnit' -Value $Unit;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'PerfUnit' -Value $Unit;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'IcingaThreshold' -Value $Threshold;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'RawThreshold' -Value $Threshold;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'CompareValue' -Value $null;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'MinRangeValue' -Value $null;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'MaxRangeValue' -Value $null;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'PercentValue' -Value '';
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'TimeSpan' -Value '';
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'InRange' -Value $TRUE;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Message' -Value '';
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Range' -Value '';
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'FullMessage' -Value (
|
||||||
|
[string]::Format('{0}', (ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $Unit -Value $InputValue)))
|
||||||
|
);
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'HeaderValue' -Value $IcingaThresholds.FullMessage;
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'ErrorMessage' -Value '';
|
||||||
|
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'HasError' -Value $FALSE;
|
||||||
|
|
||||||
|
# In case we are using % values, we should set the BaseValue always to 100
|
||||||
|
if ($Unit -eq '%' -And $null -eq $BaseValue) {
|
||||||
|
$BaseValue = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($TimeInterval) -eq $FALSE -And $null -ne $ThresholdCache) {
|
||||||
|
$TimeSeconds = ConvertTo-Seconds $TimeInterval;
|
||||||
|
$MinuteInterval = ([TimeSpan]::FromSeconds($TimeSeconds)).Minutes;
|
||||||
|
$CheckPerfDataLabel = [string]::Format('{0}_{1}', (Format-IcingaPerfDataLabel $CheckName), $MinuteInterval);
|
||||||
|
|
||||||
|
if ($null -ne $ThresholdCache.$CheckPerfDataLabel) {
|
||||||
|
$InputValue = $ThresholdCache.$CheckPerfDataLabel;
|
||||||
|
$InputValue = [math]::round([decimal]$InputValue, 6);
|
||||||
|
$IcingaThresholds.TimeSpan = $MinuteInterval;
|
||||||
|
} else {
|
||||||
|
$IcingaThresholds.HasError = $TRUE;
|
||||||
|
$IcingaThresholds.ErrorMessage = [string]::Format(
|
||||||
|
'The provided time interval "{0}" which translates to "{1}m" in your "-ThresholdInterval" argument does not exist',
|
||||||
|
$TimeInterval,
|
||||||
|
$MinuteInterval
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} <#else {
|
||||||
|
# The symbol splitting our threshold from the time index value
|
||||||
|
# Examples:
|
||||||
|
# @20:40#15m
|
||||||
|
# ~:40#15m
|
||||||
|
# 40#15m
|
||||||
|
$TimeIndexSeparator = '#';
|
||||||
|
|
||||||
|
# In case we found a ~ not starting at the beginning, we should load the
|
||||||
|
# time index values created by our background daemon
|
||||||
|
# Allows us to specify something like "40:50#15"
|
||||||
|
if ($Threshold.Contains($TimeIndexSeparator) -And $null -ne $ThresholdCache) {
|
||||||
|
[int]$LastIndex = $Threshold.LastIndexOf($TimeIndexSeparator);
|
||||||
|
if ($LastIndex -ne 0) {
|
||||||
|
$TmpValue = $Threshold;
|
||||||
|
$Threshold = $TmpValue.Substring(0, $LastIndex);
|
||||||
|
$TimeIndex = $TmpValue.Substring($LastIndex + 1, $TmpValue.Length - $LastIndex - 1);
|
||||||
|
$TimeSeconds = ConvertTo-Seconds $TimeIndex;
|
||||||
|
$MinuteInterval = ([TimeSpan]::FromSeconds($TimeSeconds)).Minutes;
|
||||||
|
|
||||||
|
$CheckPerfDataLabel = [string]::Format('{0}_{1}', (Format-IcingaPerfDataLabel $CheckName), $MinuteInterval);
|
||||||
|
|
||||||
|
if ($null -ne $ThresholdCache.$CheckPerfDataLabel) {
|
||||||
|
$InputValue = $ThresholdCache.$CheckPerfDataLabel;
|
||||||
|
$InputValue = [math]::round([decimal]$InputValue, 6);
|
||||||
|
$IcingaThresholds.TimeSpan = $MinuteInterval;
|
||||||
|
} else {
|
||||||
|
$IcingaThresholds.HasError = $TRUE;
|
||||||
|
$IcingaThresholds.ErrorMessage = [string]::Format(
|
||||||
|
'The provided time interval "{0}{1}" which translates to "{2}m" in your "-ThresholdInterval" argument does not exist',
|
||||||
|
$TimeIndexSeparator,
|
||||||
|
$TimeIndex,
|
||||||
|
$MinuteInterval
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}#>
|
||||||
|
|
||||||
|
[bool]$UseDynamicPercentage = $FALSE;
|
||||||
|
[hashtable]$ConvertedThreshold = Convert-IcingaPluginThresholds -Threshold $Threshold;
|
||||||
|
$Minimum = (Convert-IcingaPluginThresholds -Threshold $Minimum).Value;
|
||||||
|
$Maximum = (Convert-IcingaPluginThresholds -Threshold $Maximum).Value;
|
||||||
|
[string]$ThresholdValue = $ConvertedThreshold.Value;
|
||||||
|
$IcingaThresholds.Unit = $ConvertedThreshold.Unit;
|
||||||
|
$IcingaThresholds.IcingaThreshold = $ThresholdValue;
|
||||||
|
$TempValue = (Convert-IcingaPluginThresholds -Threshold ([string]::Format('{0}{1}', $InputValue, $Unit)));
|
||||||
|
$InputValue = $TempValue.Value;
|
||||||
|
$TmpUnit = $TempValue.Unit;
|
||||||
|
$IcingaThresholds.RawValue = $InputValue;
|
||||||
|
$TempValue = (Convert-IcingaPluginThresholds -Threshold ([string]::Format('{0}{1}', $BaseValue, $Unit)));
|
||||||
|
$BaseValue = $TempValue.Value;
|
||||||
|
$Unit = $TmpUnit;
|
||||||
|
$IcingaThresholds.PerfUnit = $Unit;
|
||||||
|
$IcingaThresholds.BaseValue = $BaseValue;
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($IcingaThresholds.Unit)) {
|
||||||
|
$IcingaThresholds.Unit = $Unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Calculate % value from base value of set
|
||||||
|
if ($null -ne $BaseValue -And $IcingaThresholds.Unit -eq '%') {
|
||||||
|
$InputValue = $InputValue / $BaseValue * 100;
|
||||||
|
$UseDynamicPercentage = $TRUE;
|
||||||
|
} elseif ($null -eq $BaseValue -And $IcingaThresholds.Unit -eq '%') {
|
||||||
|
$IcingaThresholds.HasError = $TRUE;
|
||||||
|
$IcingaThresholds.ErrorMessage = 'This argument does not support the % unit';
|
||||||
|
}
|
||||||
|
|
||||||
|
# Always override our InputValue, case we might have change it
|
||||||
|
$IcingaThresholds.Value = $InputValue;
|
||||||
|
|
||||||
|
# If we simply provide a numeric number, we always check Value > Threshold or Value < 0
|
||||||
|
if ($Matches) {
|
||||||
|
# Checks if the InputValue Matches the Threshold
|
||||||
|
if ($InputValue -Like $ThresholdValue) {
|
||||||
|
$IcingaThresholds.InRange = $FALSE;
|
||||||
|
$IcingaThresholds.Message = 'is matching threshold';
|
||||||
|
$IcingaThresholds.Range = [string]::Format(
|
||||||
|
'{0}{1}',
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value $ThresholdValue),
|
||||||
|
$IcingaThresholds.Unit
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif ($NotMatches) {
|
||||||
|
# Checks if the InputValue not Matches the Threshold
|
||||||
|
if ($InputValue -NotLike $ThresholdValue) {
|
||||||
|
$IcingaThresholds.InRange = $FALSE;
|
||||||
|
$IcingaThresholds.Message = 'is not matching threshold';
|
||||||
|
$IcingaThresholds.Range = [string]::Format(
|
||||||
|
'{0}{1}',
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value $ThresholdValue),
|
||||||
|
$IcingaThresholds.Unit
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif ($IsBetween) {
|
||||||
|
if ($InputValue -gt $Minium -And $InputValue -lt $Maximum) {
|
||||||
|
$IcingaThresholds.InRange = $FALSE;
|
||||||
|
$IcingaThresholds.Message = 'is inside range';
|
||||||
|
$IcingaThresholds.Range = [string]::Format(
|
||||||
|
'{0} and {1}',
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $Minium -OriginalUnit $IcingaThresholds.OriginalUnit)),
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $Maximum -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($IcingaThresholds.Unit -eq '%') {
|
||||||
|
$IcingaThresholds.RawThreshold = [string]::Format(
|
||||||
|
'{0}% ({2}) {1}% ({3})',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $Minium),
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $Maximum),
|
||||||
|
(Convert-IcingaPluginValueToString -Unit $Unit -Value $Minium -OriginalUnit $IcingaThresholds.OriginalUnit),
|
||||||
|
(Convert-IcingaPluginValueToString -Unit $Unit -Value $Maximum -OriginalUnit $IcingaThresholds.OriginalUnit)
|
||||||
|
);
|
||||||
|
$IcingaThresholds.PercentValue = [string]::Format(
|
||||||
|
'@{0}:{1}',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $Minium),
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $Maximum)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif ($IsLowerEqual) {
|
||||||
|
if ($InputValue -le $ThresholdValue) {
|
||||||
|
$IcingaThresholds.InRange = $FALSE;
|
||||||
|
$IcingaThresholds.Message = 'is lower equal than threshold';
|
||||||
|
$IcingaThresholds.Range = [string]::Format(
|
||||||
|
'{0}',
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $ThresholdValue -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($IcingaThresholds.Unit -eq '%') {
|
||||||
|
$IcingaThresholds.RawThreshold = [string]::Format(
|
||||||
|
'{0}% ({1})',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $ThresholdValue),
|
||||||
|
(Convert-IcingaPluginValueToString -Unit $Unit -Value $ThresholdValue -OriginalUnit $IcingaThresholds.OriginalUnit)
|
||||||
|
);
|
||||||
|
$IcingaThresholds.PercentValue = [string]::Format(
|
||||||
|
'{0}:',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $ThresholdValue)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif ($IsGreaterEqual) {
|
||||||
|
if ($InputValue -ge $ThresholdValue) {
|
||||||
|
$IcingaThresholds.InRange = $FALSE;
|
||||||
|
$IcingaThresholds.Message = 'is greater equal than threshold';
|
||||||
|
$IcingaThresholds.Range = [string]::Format(
|
||||||
|
'{0}',
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $ThresholdValue -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($IcingaThresholds.Unit -eq '%') {
|
||||||
|
$IcingaThresholds.RawThreshold = [string]::Format(
|
||||||
|
'{0}% ({1})',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $ThresholdValue),
|
||||||
|
(Convert-IcingaPluginValueToString -Unit $Unit -Value $ThresholdValue -OriginalUnit $IcingaThresholds.OriginalUnit)
|
||||||
|
);
|
||||||
|
|
||||||
|
$IcingaThresholds.PercentValue = [string]::Format(
|
||||||
|
'~:{0}',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $ThresholdValue)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((Test-Numeric $ThresholdValue)) {
|
||||||
|
if ($InputValue -gt $ThresholdValue -Or $InputValue -lt 0) {
|
||||||
|
$IcingaThresholds.InRange = $FALSE;
|
||||||
|
$IcingaThresholds.Message = 'is greater than threshold';
|
||||||
|
$IcingaThresholds.Range = [string]::Format('{0}', (Convert-IcingaPluginValueToString -Unit $Unit -Value $ThresholdValue -OriginalUnit $IcingaThresholds.OriginalUnit));
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaThresholds.CompareValue = [decimal]$ThresholdValue;
|
||||||
|
|
||||||
|
if ($IcingaThresholds.Unit -eq '%') {
|
||||||
|
$IcingaThresholds.RawThreshold = [string]::Format('{0}% ({1})', $ThresholdValue, (Convert-IcingaPluginValueToString -Unit $Unit -Value (ConvertFrom-Percent -Value $BaseValue -Percent $ThresholdValue) -OriginalUnit $IcingaThresholds.OriginalUnit));
|
||||||
|
|
||||||
|
$IcingaThresholds.PercentValue = [string]::Format(
|
||||||
|
'{0}',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $ThresholdValue)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
# Transform our provided thresholds to split everything into single objects
|
||||||
|
[array]$thresholds = $ThresholdValue.Split(':');
|
||||||
|
[string]$rangeMin = $thresholds[0];
|
||||||
|
[string]$rangeMax = $thresholds[1];
|
||||||
|
[bool]$IsNegating = $rangeMin.Contains('@');
|
||||||
|
[string]$rangeMin = $rangeMin.Replace('@', '');
|
||||||
|
|
||||||
|
if ((Test-Numeric ($rangeMin.Replace('@', '').Replace('~', '')))) {
|
||||||
|
$IcingaThresholds.MinRangeValue = [decimal]($rangeMin.Replace('@', '').Replace('~', ''));
|
||||||
|
}
|
||||||
|
if ((Test-Numeric $rangeMax)) {
|
||||||
|
$IcingaThresholds.MaxRangeValue = [decimal]$rangeMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($IsNegating -eq $FALSE -And (Test-Numeric $rangeMin) -And (Test-Numeric $rangeMax)) {
|
||||||
|
# Handles: 30:40
|
||||||
|
# Error on: < 30 or > 40
|
||||||
|
# Ok on: between {30 .. 40}
|
||||||
|
|
||||||
|
if ($InputValue -lt $rangeMin -Or $InputValue -gt $rangeMax) {
|
||||||
|
$IcingaThresholds.InRange = $FALSE;
|
||||||
|
$IcingaThresholds.Message = 'is outside range';
|
||||||
|
$IcingaThresholds.Range = [string]::Format(
|
||||||
|
'{0} and {1}',
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $rangeMin -OriginalUnit $IcingaThresholds.OriginalUnit)),
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $rangeMax -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($IcingaThresholds.Unit -eq '%') {
|
||||||
|
$IcingaThresholds.RawThreshold = [string]::Format(
|
||||||
|
'{0}% ({2}) and {1}% ({3})',
|
||||||
|
$rangeMin,
|
||||||
|
$rangeMax,
|
||||||
|
(Convert-IcingaPluginValueToString -Unit $Unit -Value (ConvertFrom-Percent -Value $BaseValue -Percent $rangeMin -OriginalUnit $IcingaThresholds.OriginalUnit)),
|
||||||
|
(Convert-IcingaPluginValueToString -Unit $Unit -Value (ConvertFrom-Percent -Value $BaseValue -Percent $rangeMax -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
|
||||||
|
$IcingaThresholds.PercentValue = [string]::Format(
|
||||||
|
'{0}:{1}',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $rangeMin),
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $rangeMax)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif ((Test-Numeric $rangeMin) -And [string]::IsNullOrEmpty($rangeMax) -eq $TRUE) {
|
||||||
|
# Handles: 20:
|
||||||
|
# Error on: 20:
|
||||||
|
# Ok on: between 20 .. ∞
|
||||||
|
|
||||||
|
if ($InputValue -lt $rangeMin) {
|
||||||
|
$IcingaThresholds.InRange = $FALSE;
|
||||||
|
$IcingaThresholds.Message = 'is lower than threshold';
|
||||||
|
$IcingaThresholds.Range = [string]::Format(
|
||||||
|
'{0}',
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $rangeMin -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($IcingaThresholds.Unit -eq '%') {
|
||||||
|
$IcingaThresholds.RawThreshold = [string]::Format(
|
||||||
|
'{0}% ({1})',
|
||||||
|
$rangeMin,
|
||||||
|
(Convert-IcingaPluginValueToString -Unit $Unit -Value (ConvertFrom-Percent -Value $BaseValue -Percent $rangeMin -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
|
||||||
|
$IcingaThresholds.PercentValue = [string]::Format(
|
||||||
|
'{0}:',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $rangeMin)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif ($rangeMin -eq '~' -And (Test-Numeric $rangeMax)) {
|
||||||
|
# Handles: ~:20
|
||||||
|
# Error on: > 20
|
||||||
|
# Ok on: between -∞ .. 20
|
||||||
|
|
||||||
|
if ($InputValue -gt $rangeMax) {
|
||||||
|
$IcingaThresholds.InRange = $FALSE;
|
||||||
|
$IcingaThresholds.Message = 'is greater than threshold';
|
||||||
|
$IcingaThresholds.Range = [string]::Format(
|
||||||
|
'{0}',
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $rangeMax -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($IcingaThresholds.Unit -eq '%') {
|
||||||
|
$IcingaThresholds.RawThreshold = [string]::Format(
|
||||||
|
'{0}% ({1})',
|
||||||
|
$rangeMax,
|
||||||
|
(Convert-IcingaPluginValueToString -Unit $Unit -Value (ConvertFrom-Percent -Value $BaseValue -Percent $rangeMax -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
|
||||||
|
$IcingaThresholds.PercentValue = [string]::Format(
|
||||||
|
'~:{0}',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $rangeMax)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif ($IsNegating -And (Test-Numeric $rangeMin) -And (Test-Numeric $rangeMax)) {
|
||||||
|
# Handles: @30:40
|
||||||
|
# Error on: ≥ 30 and ≤ 40
|
||||||
|
# Ok on: -∞ .. 29 and 41 .. ∞
|
||||||
|
|
||||||
|
if ($InputValue -ge $rangeMin -And $InputValue -le $rangeMax) {
|
||||||
|
$IcingaThresholds.InRange = $FALSE;
|
||||||
|
$IcingaThresholds.Message = 'is inside range';
|
||||||
|
$IcingaThresholds.Range = [string]::Format(
|
||||||
|
'{0} and {1}',
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $rangeMin -OriginalUnit $IcingaThresholds.OriginalUnit)),
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $rangeMax -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($IcingaThresholds.Unit -eq '%') {
|
||||||
|
$IcingaThresholds.RawThreshold = [string]::Format(
|
||||||
|
'{0}% ({2}) {1}% ({3})',
|
||||||
|
$rangeMin,
|
||||||
|
$rangeMax,
|
||||||
|
(Convert-IcingaPluginValueToString -Unit $Unit -Value (ConvertFrom-Percent -Value $BaseValue -Percent $rangeMin -OriginalUnit $IcingaThresholds.OriginalUnit)),
|
||||||
|
(Convert-IcingaPluginValueToString -Unit $Unit -Value (ConvertFrom-Percent -Value $BaseValue -Percent $rangeMax -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
|
||||||
|
$IcingaThresholds.PercentValue = [string]::Format(
|
||||||
|
'@{0}:{1}',
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $rangeMin),
|
||||||
|
(ConvertFrom-Percent -Value $BaseValue -Percent $rangeMax)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ([string]::IsNullOrEmpty($Threshold) -eq $FALSE) {
|
||||||
|
# Unhandled
|
||||||
|
$IcingaThresholds.ErrorMessage = [string]::Format(
|
||||||
|
'Invalid range specified for threshold: InputValue "{0}" and Threshold {1}',
|
||||||
|
$InputValue,
|
||||||
|
$Threshold
|
||||||
|
);
|
||||||
|
$IcingaThresholds.HasError = $TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$PluginOutputMessage = [System.Text.StringBuilder]::New();
|
||||||
|
|
||||||
|
[string]$PluginCurrentValue = [string]::Format(
|
||||||
|
'{0}',
|
||||||
|
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $IcingaThresholds.Value -OriginalUnit $IcingaThresholds.OriginalUnit))
|
||||||
|
);
|
||||||
|
|
||||||
|
[string]$PluginThresholdValue = $IcingaThresholds.Range;
|
||||||
|
|
||||||
|
if ($UseDynamicPercentage -And $Unit -ne '%') {
|
||||||
|
$IcingaThresholds.IcingaThreshold = $IcingaThresholds.PercentValue;
|
||||||
|
$PluginCurrentValue = [string]::Format('{0}% ({1})', ([math]::Round($IcingaThresholds.Value, 2)), (Convert-IcingaPluginValueToString -Unit $Unit -Value $IcingaThresholds.RawValue -OriginalUnit $IcingaThresholds.OriginalUnit));
|
||||||
|
$PluginThresholdValue = $IcingaThresholds.RawThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaThresholds.HeaderValue = $PluginCurrentValue;
|
||||||
|
$PluginOutputMessage.Append($PluginCurrentValue) | Out-Null;
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($IcingaThresholds.Message) -eq $FALSE) {
|
||||||
|
$PluginOutputMessage.Append(' ') | Out-Null;
|
||||||
|
$PluginOutputMessage.Append($IcingaThresholds.Message) | Out-Null;
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($PluginThresholdValue) -eq $FALSE) {
|
||||||
|
$PluginOutputMessage.Append(' ') | Out-Null;
|
||||||
|
$PluginOutputMessage.Append($PluginThresholdValue) | Out-Null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Lets build our full message for adding on the value
|
||||||
|
$IcingaThresholds.FullMessage = $PluginOutputMessage.ToString();
|
||||||
|
|
||||||
|
return $IcingaThresholds;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
function ConvertTo-IcingaPluginOutputTranslation()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
$Value = $null,
|
||||||
|
[hashtable]$Translation = @{ }
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($null -eq $Value) {
|
||||||
|
return 'Nothing';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($null -eq $Translation -Or $Translation.Count -eq 0) {
|
||||||
|
return $Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[array]$TranslationKeys = $Translation.Keys;
|
||||||
|
[array]$TranslationValues = $Translation.Values;
|
||||||
|
[int]$Index = 0;
|
||||||
|
[bool]$FoundTranslation = $FALSE;
|
||||||
|
|
||||||
|
foreach ($entry in $TranslationKeys) {
|
||||||
|
if (([string]($Value)).ToLower() -eq ([string]($entry)).ToLower()) {
|
||||||
|
$FoundTranslation = $TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$Index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($FoundTranslation -eq $FALSE) {
|
||||||
|
return $Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $TranslationValues[$Index];
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load diff
189
lib/icinga/plugin/New-IcingaCheckBaseObject.psm1
Normal file
189
lib/icinga/plugin/New-IcingaCheckBaseObject.psm1
Normal file
|
|
@ -0,0 +1,189 @@
|
||||||
|
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 ScriptMethod -Name '__SetCheckCommand' -Value {
|
||||||
|
$CallStack = Get-PSCallStack;
|
||||||
|
|
||||||
|
foreach ($entry in $CallStack) {
|
||||||
|
[string]$CheckCommand = $entry.Command;
|
||||||
|
if ($CheckCommand.ToLower() -Like 'invoke-icingacheck*') {
|
||||||
|
$this.__CheckCommand = $CheckCommand;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($null -eq $Global:Icinga) {
|
||||||
|
$Global:Icinga = @{ };
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($Global:Icinga.ContainsKey('ThresholdCache') -eq $FALSE) {
|
||||||
|
$Global:Icinga.Add('ThresholdCache', @{ });
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($Global:Icinga.ThresholdCache.ContainsKey($this.__CheckCommand)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$Global:Icinga.ThresholdCache.Add(
|
||||||
|
$this.__CheckCommand,
|
||||||
|
(Get-IcingaCacheData -Space 'sc_daemon' -CacheStore 'checkresult' -KeyName $this.__CheckCommand)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetParent' -Value {
|
||||||
|
param ($Parent);
|
||||||
|
|
||||||
|
$this.__Parent = $Parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetParent' -Value {
|
||||||
|
return $this.__Parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__IsHidden' -Value {
|
||||||
|
return $this.__Hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetHidden' -Value {
|
||||||
|
param ([bool]$Hidden);
|
||||||
|
|
||||||
|
$this.__Hidden = $Hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetName' -Value {
|
||||||
|
return $this.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetIndention' -Value {
|
||||||
|
param ($Indention);
|
||||||
|
|
||||||
|
$this.__Indention = $Indention;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetIndention' -Value {
|
||||||
|
return $this.__Indention;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__NewIndention' -Value {
|
||||||
|
return ($this.__Indention + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetCheckState' -Value {
|
||||||
|
return $this.__CheckState;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetCheckCommand' -Value {
|
||||||
|
return $this.__CheckCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Force -Name '__SetCheckOutput' -Value {
|
||||||
|
param ($PluginOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetCheckOutput' -Value {
|
||||||
|
|
||||||
|
if ($this.__IsHidden()) {
|
||||||
|
return ''
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($this._CanOutput() -eq $FALSE) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
[string]::Format(
|
||||||
|
'{0}{1}',
|
||||||
|
(New-StringTree -Spacing $this.__GetIndention()),
|
||||||
|
$this.__CheckOutput
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name 'Compile' -Value {
|
||||||
|
$this.__ValidateThresholdInput();
|
||||||
|
$this.__SetCheckOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetVerbosity' -Value {
|
||||||
|
param ($Verbosity);
|
||||||
|
|
||||||
|
$this.Verbose = $Verbosity;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetVerbosity' -Value {
|
||||||
|
return $this.Verbose;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Shared function
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetHeaderOutputValue' -Value {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '_CanOutput' -Value {
|
||||||
|
# Always allow the output of the top parent elements
|
||||||
|
if ($this.__GetIndention() -eq 0) {
|
||||||
|
return $TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($this.Verbose) {
|
||||||
|
0 { # Only print states not being OK
|
||||||
|
if ($this.__CheckState -ne $IcingaEnums.IcingaExitCode.Ok) {
|
||||||
|
return $TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this.__ObjectType -eq 'IcingaCheckPackage') {
|
||||||
|
return $this.__HasNotOkChecks();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $FALSE;
|
||||||
|
};
|
||||||
|
1 { # Print states not being OK and all content of affected check packages
|
||||||
|
if ($this.__CheckState -ne $IcingaEnums.IcingaExitCode.Ok) {
|
||||||
|
return $TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this.__ObjectType -eq 'IcingaCheckPackage') {
|
||||||
|
return $this.__HasNotOkChecks();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this.__GetParent().__ObjectType -eq 'IcingaCheckPackage') {
|
||||||
|
return $this.__GetParent().__HasNotOkChecks();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $FALSE;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
# For any other verbosity, print everything
|
||||||
|
return $TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__GetPerformanceData' -Value {
|
||||||
|
return $this.__CheckPerfData;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__ValidateThresholdInput' -Value {
|
||||||
|
# Shared function
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name 'HasChecks' -Value {
|
||||||
|
# Shared function
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckBaseObject.__SetCheckCommand();
|
||||||
|
|
||||||
|
return $IcingaCheckBaseObject;
|
||||||
|
}
|
||||||
|
|
@ -1,456 +1,342 @@
|
||||||
Import-IcingaLib icinga\enums;
|
|
||||||
Import-IcingaLib core\tools;
|
|
||||||
|
|
||||||
function New-IcingaCheckPackage()
|
function New-IcingaCheckPackage()
|
||||||
{
|
{
|
||||||
param(
|
param (
|
||||||
[string]$Name,
|
[string]$Name = '',
|
||||||
[switch]$OperatorAnd,
|
[switch]$OperatorAnd = $FALSE,
|
||||||
[switch]$OperatorOr,
|
[switch]$OperatorOr = $FALSE,
|
||||||
[switch]$OperatorNone,
|
[switch]$OperatorNone = $FALSE,
|
||||||
[int]$OperatorMin = -1,
|
[int]$OperatorMin = -1,
|
||||||
[int]$OperatorMax = -1,
|
[int]$OperatorMax = -1,
|
||||||
[array]$Checks = @(),
|
[array]$Checks = @(),
|
||||||
[int]$Verbose = 0,
|
[int]$Verbose = 0,
|
||||||
[switch]$IgnoreEmptyPackage = $FALSE,
|
[switch]$IgnoreEmptyPackage = $FALSE,
|
||||||
[switch]$Hidden = $FALSE
|
[switch]$Hidden = $FALSE,
|
||||||
|
[switch]$AddSummaryHeader = $FALSE
|
||||||
);
|
);
|
||||||
|
|
||||||
$Check = New-Object -TypeName PSObject;
|
$IcingaCheckPackage = New-IcingaCheckBaseObject;
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'name' -Value $Name;
|
|
||||||
$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;
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'opnone' -Value $OperatorNone;
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'opmin' -Value $OperatorMin;
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'opmax' -Value $OperatorMax;
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'spacing' -Value 0;
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'compiled' -Value $FALSE;
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'perfdata' -Value $FALSE;
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'checkcommand' -Value '';
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'headermsg' -Value '';
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'checkpackage' -Value $TRUE;
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'warningchecks' -Value @();
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'criticalchecks' -Value @();
|
|
||||||
$Check | Add-Member -MemberType NoteProperty -Name 'unknownchecks' -Value @();
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'HasChecks' -Value {
|
$IcingaCheckPackage.Name = $Name;
|
||||||
if ($this.checks -ne 0) {
|
$IcingaCheckPackage.__ObjectType = 'IcingaCheckPackage';
|
||||||
return $TRUE
|
$IcingaCheckPackage.__SetHidden($Hidden);
|
||||||
}
|
$IcingaCheckPackage.__SetVerbosity($Verbose);
|
||||||
|
|
||||||
return $FALSE;
|
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name 'OperatorAnd' -Value $OperatorAnd;
|
||||||
}
|
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name 'OperatorOr' -Value $OperatorOr;
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name 'OperatorNone' -Value $OperatorNone;
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name 'OperatorMin' -Value $OperatorMin;
|
||||||
|
$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 '__Checks' -Value @();
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name '__OkChecks' -Value @();
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name '__WarningChecks' -Value @();
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name '__CriticalChecks' -Value @();
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType NoteProperty -Name '__UnknownChecks' -Value @();
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'Initialise' -Value {
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Name 'ValidateOperators' -Value {
|
||||||
foreach ($check in $this.checks) {
|
if ($this.OperatorMin -ne -1) {
|
||||||
$this.InitCheck($check);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'InitCheck' -Value {
|
|
||||||
param($check);
|
|
||||||
|
|
||||||
if ($null -eq $check) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$check.verbose = $this.verbose;
|
if ($this.OperatorMax -ne -1) {
|
||||||
$check.AddSpacing();
|
|
||||||
$check.SilentCompile();
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'AddSpacing' -Value {
|
|
||||||
$this.spacing += 1;
|
|
||||||
foreach ($check in $this.checks) {
|
|
||||||
$check.spacing = $this.spacing;
|
|
||||||
$check.AddSpacing();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'AddCheck' -Value {
|
|
||||||
param($check);
|
|
||||||
|
|
||||||
if ($null -eq $check) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this.InitCheck($check);
|
if ($this.OperatorNone -ne $FALSE) {
|
||||||
$this.checks += $check;
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'GetWarnings' -Value {
|
|
||||||
foreach ($check in $this.checks) {
|
|
||||||
$this.warningchecks += $check.GetWarnings();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this.warningchecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'GetCriticals' -Value {
|
|
||||||
foreach ($check in $this.checks) {
|
|
||||||
$this.criticalchecks += $check.GetCriticals();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this.criticalchecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'GetUnknowns' -Value {
|
|
||||||
foreach ($check in $this.checks) {
|
|
||||||
$this.unknownchecks += $check.GetUnknowns();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this.unknownchecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'AssignCheckCommand' -Value {
|
|
||||||
param($CheckCommand);
|
|
||||||
|
|
||||||
$this.checkcommand = $CheckCommand;
|
|
||||||
|
|
||||||
foreach ($check in $this.checks) {
|
|
||||||
$check.AssignCheckCommand($CheckCommand);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'Compile' -Value {
|
|
||||||
param([bool]$Verbose);
|
|
||||||
|
|
||||||
if ($this.compiled) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this.compiled = $TRUE;
|
if ($this.OperatorOr -ne $FALSE) {
|
||||||
|
return;
|
||||||
if ($this.checks.Count -ne 0) {
|
|
||||||
if ($this.opand) {
|
|
||||||
if ($this.CheckAllOk() -eq $FALSE) {
|
|
||||||
$this.GetWorstExitCode();
|
|
||||||
}
|
|
||||||
} elseif ($this.opor) {
|
|
||||||
if ($this.CheckOneOk() -eq $FALSE) {
|
|
||||||
$this.GetWorstExitCode();
|
|
||||||
}
|
|
||||||
} elseif ($this.opnone) {
|
|
||||||
if ($this.CheckOneOk() -eq $TRUE) {
|
|
||||||
$this.GetWorstExitCode();
|
|
||||||
$this.exitcode = $IcingaEnums.IcingaExitCode.Critical;
|
|
||||||
} else {
|
|
||||||
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok;
|
|
||||||
}
|
|
||||||
} elseif ([int]$this.opmin -ne -1) {
|
|
||||||
if ($this.CheckMinimumOk() -eq $FALSE) {
|
|
||||||
$this.GetWorstExitCode();
|
|
||||||
} else {
|
|
||||||
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok;
|
|
||||||
}
|
|
||||||
} elseif ([int]$this.opmax -ne -1) {
|
|
||||||
if ($this.CheckMaximumOk() -eq $FALSE) {
|
|
||||||
$this.GetWorstExitCode();
|
|
||||||
} else {
|
|
||||||
$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) {
|
# If no operator is set, use And as default
|
||||||
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok;
|
$this.OperatorAnd = $TRUE;
|
||||||
}
|
|
||||||
|
|
||||||
if ($Verbose -eq $TRUE) {
|
|
||||||
$this.PrintOutputMessages();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this.exitcode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'SilentCompile' -Value {
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Name 'AddCheck' -Value {
|
||||||
$this.Compile($FALSE) | Out-Null;
|
param([array]$Checks);
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'GetOkCount' -Value {
|
if ($null -eq $Checks -Or $Checks.Count -eq 0) {
|
||||||
[int]$okCount = 0;
|
return;
|
||||||
foreach ($check in $this.checks) {
|
|
||||||
if ([int]$check.exitcode -eq [int]$IcingaEnums.IcingaExitCode.Ok) {
|
|
||||||
$okCount += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $okCount;
|
foreach ($check in $Checks) {
|
||||||
|
$check.__SetIndention($this.__NewIndention());
|
||||||
|
$check.__SetCheckOutput();
|
||||||
|
$check.__SetVerbosity($this.__GetVerbosity());
|
||||||
|
$check.__SetParent($this);
|
||||||
|
$this.__Checks += $check;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'CheckMinimumOk' -Value {
|
# Override shared function
|
||||||
if ($this.opmin -gt $this.checks.Count) {
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Force -Name '__SetIndention' -Value {
|
||||||
Write-IcingaPluginOutput (
|
param ($Indention);
|
||||||
[string]::Format(
|
|
||||||
'Unknown: The minimum argument ({0}) is exceeding the amount of assigned checks ({1}) to this package "{2}"',
|
$this.__Indention = $Indention;
|
||||||
$this.opmin, $this.checks.Count, $this.name
|
|
||||||
)
|
foreach ($check in $this.__Checks) {
|
||||||
|
$check.__SetIndention($this.__NewIndention());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Name '__SetCheckState' -Value {
|
||||||
|
param ($State);
|
||||||
|
|
||||||
|
if ($this.__GetCheckState() -lt $State) {
|
||||||
|
$this.__CheckState = $State;
|
||||||
|
$this.__SetCheckOutput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Override shared function
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Force -Name '__SetCheckOutput' -Value {
|
||||||
|
param ($PluginOutput);
|
||||||
|
|
||||||
|
$UnknownChecks = '';
|
||||||
|
$CriticalChecks = '';
|
||||||
|
$WarningChecks = '';
|
||||||
|
$CheckSummary = [System.Text.StringBuilder]::New();
|
||||||
|
[bool]$HasContent = $FALSE;
|
||||||
|
|
||||||
|
# Only apply this to the top parent package
|
||||||
|
if ($this.__GetIndention() -eq 0) {
|
||||||
|
if ($this.__UnknownChecks.Count -ne 0) {
|
||||||
|
$UnknownChecks = [string]::Format(' [UNKNOWN] {0}', ([string]::Join(', ', $this.__UnknownChecks)));
|
||||||
|
$HasContent = $TRUE;
|
||||||
|
$CheckSummary.Append(
|
||||||
|
[string]::Format(' {0} Unknown', $this.__UnknownChecks.Count)
|
||||||
|
) | Out-Null;
|
||||||
|
}
|
||||||
|
if ($this.__CriticalChecks.Count -ne 0) {
|
||||||
|
$CriticalChecks = [string]::Format(' [CRITICAL] {0}', ([string]::Join(', ', $this.__CriticalChecks)));
|
||||||
|
$HasContent = $TRUE;
|
||||||
|
$CheckSummary.Append(
|
||||||
|
[string]::Format(' {0} Critical', $this.__CriticalChecks.Count)
|
||||||
|
) | Out-Null;
|
||||||
|
}
|
||||||
|
if ($this.__WarningChecks.Count -ne 0) {
|
||||||
|
$WarningChecks = [string]::Format(' [WARNING] {0}', ([string]::Join(', ', $this.__WarningChecks)));
|
||||||
|
$HasContent = $TRUE;
|
||||||
|
$CheckSummary.Append(
|
||||||
|
[string]::Format(' {0} Warning', $this.__WarningChecks.Count)
|
||||||
|
) | Out-Null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ([string]::IsNullOrEmpty($this.__ErrorMessage) -eq $FALSE) {
|
||||||
|
$HasContent = $TRUE;
|
||||||
|
}
|
||||||
|
if ($this.__OkChecks.Count -ne 0) {
|
||||||
|
$CheckSummary.Append(
|
||||||
|
[string]::Format(' {0} Ok', $this.__OkChecks.Count)
|
||||||
|
) | Out-Null;
|
||||||
|
$HasContent = $TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this.AddSummaryHeader -eq $FALSE) {
|
||||||
|
$CheckSummary.Clear() | Out-Null;
|
||||||
|
$CheckSummary.Append('') | Out-Null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this.__CheckOutput = [string]::Format(
|
||||||
|
'{0} {1}{2}{3}{4}{5}{6}{7}{8}',
|
||||||
|
$IcingaEnums.IcingaExitCodeText[$this.__GetCheckState()],
|
||||||
|
$this.Name,
|
||||||
|
(&{ if ($HasContent) { return ':'; } else { return ''; } }),
|
||||||
|
$CheckSummary.ToString(),
|
||||||
|
([string]::Format('{0}{1}', (&{ if ($this.__ErrorMessage.Length -gt 1) { return ' '; } else { return ''; } }), $this.__ErrorMessage)),
|
||||||
|
$UnknownChecks,
|
||||||
|
$CriticalChecks,
|
||||||
|
$WarningChecks,
|
||||||
|
$this.__ShowPackageConfig()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckPackage | Add-Member -Force -MemberType ScriptMethod -Name 'Compile' -Value {
|
||||||
|
$this.__OkChecks.Clear();
|
||||||
|
$this.__WarningChecks.Clear();
|
||||||
|
$this.__CriticalChecks.Clear();
|
||||||
|
$this.__UnknownChecks.Clear();
|
||||||
|
|
||||||
|
$WorstState = $IcingaEnums.IcingaExitCode.Ok;
|
||||||
|
$BestState = $IcingaEnums.IcingaExitCode.Ok;
|
||||||
|
$NotOkChecks = 0;
|
||||||
|
$OkChecks = 0;
|
||||||
|
|
||||||
|
if ($this.__Checks.Count -eq 0 -And $this.IgnoreEmptyPackage -eq $FALSE) {
|
||||||
|
$this.__ErrorMessage = 'No checks added to this package';
|
||||||
|
$this.__SetCheckState($IcingaEnums.IcingaExitCode.Unknown);
|
||||||
|
$this.__SetCheckOutput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this.__Checks = $this.__Checks | Sort-Object -Property Name;
|
||||||
|
|
||||||
|
# Loop all checks to understand the content of result
|
||||||
|
foreach ($check in $this.__Checks) {
|
||||||
|
|
||||||
|
$check.Compile();
|
||||||
|
|
||||||
|
if ($WorstState -lt $check.__GetCheckState()) {
|
||||||
|
$WorstState = $check.__GetCheckState();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($BestState -gt $check.__GetCheckState()) {
|
||||||
|
$BestState = $check.__GetCheckState();
|
||||||
|
}
|
||||||
|
|
||||||
|
[string]$CheckStateOutput = [string]::Format(
|
||||||
|
'{0}{1}',
|
||||||
|
$check.__GetName(),
|
||||||
|
$check.__GetHeaderOutputValue()
|
||||||
);
|
);
|
||||||
$this.exitcode = $IcingaEnums.IcingaExitCode.Unknown;
|
|
||||||
return $FALSE;
|
switch ($check.__GetCheckState()) {
|
||||||
|
$IcingaEnums.IcingaExitCode.Ok {
|
||||||
|
$this.__OkChecks += $CheckStateOutput;
|
||||||
|
$OkChecks += 1;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
$IcingaEnums.IcingaExitCode.Warning {
|
||||||
|
$this.__WarningChecks += $CheckStateOutput;
|
||||||
|
$NotOkChecks += 1;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
$IcingaEnums.IcingaExitCode.Critical {
|
||||||
|
$this.__CriticalChecks += $CheckStateOutput;
|
||||||
|
$NotOkChecks += 1;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
$IcingaEnums.IcingaExitCode.Unknown {
|
||||||
|
$this.__UnknownChecks += $CheckStateOutput;
|
||||||
|
$NotOkChecks += 1;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[int]$okCount = $this.GetOkCount();
|
if ($this.OperatorAnd -And $NotOkChecks -ne 0) {
|
||||||
|
$this.__SetCheckState($WorstState);
|
||||||
|
} elseif ($this.OperatorOr -And $OkChecks -eq 0 ) {
|
||||||
|
$this.__SetCheckState($WorstState);
|
||||||
|
} elseif ($this.OperatorNone -And $OkChecks -ne 0 ) {
|
||||||
|
$this.__SetCheckState($WorstState);
|
||||||
|
} elseif ($this.OperatorMin -ne -1) {
|
||||||
|
if (-Not ($this.__Checks.Count -eq 0 -And $this.IgnoreEmptyPackage -eq $TRUE)) {
|
||||||
|
if ($this.OperatorMin -gt $this.__Checks.Count) {
|
||||||
|
$this.__SetCheckState($IcingaEnums.IcingaExitCode.Unknown);
|
||||||
|
$this.__ErrorMessage = [string]::Format('Minium check count ({0}) is larger than number of assigned checks ({1})', $this.OperatorMin, $this.__Checks.Count);
|
||||||
|
} elseif ($OkChecks -lt $this.OperatorMin) {
|
||||||
|
$this.__SetCheckState($WorstState);
|
||||||
|
$this.__ErrorMessage = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($this.OperatorMax -ne -1) {
|
||||||
|
if (-Not ($this.__Checks.Count -eq 0 -And $this.IgnoreEmptyPackage -eq $TRUE)) {
|
||||||
|
if ($this.OperatorMax -gt $this.__Checks.Count) {
|
||||||
|
$this.__SetCheckState($IcingaEnums.IcingaExitCode.Unknown);
|
||||||
|
$this.__ErrorMessage = [string]::Format('Maximum check count ({0}) is larger than number of assigned checks ({1})', $this.OperatorMax, $this.__Checks.Count);
|
||||||
|
} elseif ($OkChecks -gt $this.OperatorMax) {
|
||||||
|
$this.__SetCheckState($WorstState);
|
||||||
|
$this.__ErrorMessage = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this.opmin -le $okCount) {
|
$this.__SetCheckOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
# Override default behaviour from shared function
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Force -Name '__SetVerbosity' -Value {
|
||||||
|
param ($Verbosity);
|
||||||
|
# Do nothing for check packages
|
||||||
|
}
|
||||||
|
|
||||||
|
# Override default behaviour from shared function
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Force -Name '__GetCheckOutput' -Value {
|
||||||
|
|
||||||
|
if ($this.__IsHidden()) {
|
||||||
|
return ''
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($this._CanOutput() -eq $FALSE) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$CheckOutput = [string]::Format(
|
||||||
|
'{0}{1}',
|
||||||
|
(New-StringTree -Spacing $this.__GetIndention()),
|
||||||
|
$this.__CheckOutput
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($check in $this.__Checks) {
|
||||||
|
if ($check.__IsHidden()) {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($check._CanOutput() -eq $FALSE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$CheckOutput = [string]::Format(
|
||||||
|
'{0}{1}{2}',
|
||||||
|
$CheckOutput,
|
||||||
|
"`n",
|
||||||
|
$check.__GetCheckOutput()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $CheckOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Force -Name '__HasNotOkChecks' -Value {
|
||||||
|
|
||||||
|
if ($this.__WarningChecks.Count -ne 0) {
|
||||||
|
return $TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this.__CriticalChecks.Count -ne 0) {
|
||||||
|
return $TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this.__UnknownChecks.Count -ne 0) {
|
||||||
return $TRUE;
|
return $TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $FALSE;
|
return $FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'CheckMaximumOk' -Value {
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Force -Name '__ShowPackageConfig' -Value {
|
||||||
if ($this.opmax -gt $this.checks.Count) {
|
if ($this.__GetVerbosity() -lt 3) {
|
||||||
Write-IcingaPluginOutput (
|
return '';
|
||||||
[string]::Format(
|
|
||||||
'Unknown: The maximum argument ({0}) is exceeding the amount of assigned checks ({1}) to this package "{2}"',
|
|
||||||
$this.opmax, $this.checks.Count, $this.name
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this.exitcode = $IcingaEnums.IcingaExitCode.Unknown;
|
|
||||||
return $FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[int]$okCount = $this.GetOkCount();
|
if ($this.OperatorAnd) {
|
||||||
|
return ' (All must be [OK])';
|
||||||
if ($this.opmax -ge $okCount) {
|
}
|
||||||
return $TRUE;
|
if ($this.OperatorOr) {
|
||||||
|
return ' (Atleast one must be [OK])';
|
||||||
|
}
|
||||||
|
if ($this.OperatorMin -ne -1) {
|
||||||
|
return ([string]::Format(' (Atleast {0} must be [OK])', $this.OperatorMin));
|
||||||
|
}
|
||||||
|
if ($this.OperatorMax -ne -1) {
|
||||||
|
return ([string]::Format(' (Not more than {0} must be [OK])', $this.OperatorMax));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $FALSE;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'CheckAllOk' -Value {
|
# Override default behaviour from shared function
|
||||||
foreach ($check in $this.checks) {
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Force -Name '__GetPerformanceData' -Value {
|
||||||
if ([int]$check.exitcode -ne [int]$IcingaEnums.IcingaExitCode.Ok) {
|
|
||||||
return $FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'CheckOneOk' -Value {
|
|
||||||
foreach ($check in $this.checks) {
|
|
||||||
if ([int]$check.exitcode -eq [int]$IcingaEnums.IcingaExitCode.Ok) {
|
|
||||||
$this.exitcode = $check.exitcode;
|
|
||||||
return $TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'GetPackageConfigMessage' -Value {
|
|
||||||
if ($this.opand) {
|
|
||||||
return 'Match All';
|
|
||||||
} elseif ($this.opor) {
|
|
||||||
return 'Match Any';
|
|
||||||
} elseif ($this.opnone) {
|
|
||||||
return 'Match None';
|
|
||||||
} elseif ([int]$this.opmin -ne -1) {
|
|
||||||
return [string]::Format('Minimum {0}', $this.opmin)
|
|
||||||
} elseif ([int]$this.opmax -ne -1) {
|
|
||||||
return [string]::Format('Maximum {0}', $this.opmax)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'PrintOutputMessageSorted' -Value {
|
|
||||||
param($skipHidden, $skipExitCode);
|
|
||||||
|
|
||||||
if ($this.hidden -And $skipHidden) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
[hashtable]$MessageOrdering = @{};
|
|
||||||
foreach ($check in $this.checks) {
|
|
||||||
if ($this.verbose -eq 0) {
|
|
||||||
if ([int]$check.exitcode -eq $skipExitCode) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} elseif ($this.verbose -eq 1) {
|
|
||||||
if ([int]$check.exitcode -eq $skipExitCode -And $check.checkpackage) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($MessageOrdering.ContainsKey($check.Name) -eq $FALSE) {
|
|
||||||
$MessageOrdering.Add($check.name, $check);
|
|
||||||
} else {
|
|
||||||
[int]$DuplicateKeyIndex = 1;
|
|
||||||
while ($TRUE) {
|
|
||||||
$newCheckName = [string]::Format('{0}[{1}]', $check.Name, $DuplicateKeyIndex);
|
|
||||||
if ($MessageOrdering.ContainsKey($newCheckName) -eq $FALSE) {
|
|
||||||
$MessageOrdering.Add($newCheckName, $check);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$DuplicateKeyIndex += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$SortedArray = $MessageOrdering.GetEnumerator() | Sort-Object name;
|
|
||||||
|
|
||||||
foreach ($entry in $SortedArray) {
|
|
||||||
$entry.Value.PrintAllMessages();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'WriteAllOutput' -Value {
|
|
||||||
$this.PrintOutputMessageSorted($TRUE, $IcingaEnums.IcingaExitCode.Ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'PrintAllMessages' -Value {
|
|
||||||
$this.WritePackageOutputStatus();
|
|
||||||
$this.WriteAllOutput();
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'WriteCheckErrors' -Value {
|
|
||||||
$this.PrintOutputMessageSorted($FALSE, $IcingaEnums.IcingaExitCode.Ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'PrintNoChecksConfigured' -Value {
|
|
||||||
if ($this.checks.Count -eq 0) {
|
|
||||||
Write-IcingaPluginOutput (
|
|
||||||
[string]::Format(
|
|
||||||
'{0}{1} No checks configured for package "{2}"',
|
|
||||||
(New-StringTree ($this.spacing + 1)),
|
|
||||||
$IcingaEnums.IcingaExitCodeText.($this.exitcode),
|
|
||||||
$this.name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'WritePackageOutputStatus' -Value {
|
|
||||||
if ($this.hidden) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
[string]$outputMessage = '{0}{1} Check package "{2}"';
|
|
||||||
if ($this.verbose -ne 0) {
|
|
||||||
$outputMessage += ' ({3})';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this.exitcode -ne 0 -And $this.spacing -eq 0) {
|
|
||||||
$outputMessage += ' - {4}';
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-IcingaPluginOutput (
|
|
||||||
[string]::Format(
|
|
||||||
$outputMessage,
|
|
||||||
(New-StringTree $this.spacing),
|
|
||||||
$IcingaEnums.IcingaExitCodeText.($this.exitcode),
|
|
||||||
$this.name,
|
|
||||||
$this.GetPackageConfigMessage(),
|
|
||||||
$this.headermsg
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'PrintOutputMessages' -Value {
|
|
||||||
[bool]$printAll = $FALSE;
|
|
||||||
|
|
||||||
switch ($this.verbose) {
|
|
||||||
0 {
|
|
||||||
# Default value. Only print a package but not the services include
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
1 {
|
|
||||||
# Include the Operator into the check package result and OK checks of package
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
Default {
|
|
||||||
$printAll = $TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this.WritePackageOutputStatus();
|
|
||||||
|
|
||||||
if ($printAll) {
|
|
||||||
$this.WriteAllOutput();
|
|
||||||
$this.PrintNoChecksConfigured();
|
|
||||||
} else {
|
|
||||||
if ([int]$this.exitcode -ne $IcingaEnums.IcingaExitCode.Ok) {
|
|
||||||
$this.WriteCheckErrors();
|
|
||||||
$this.PrintNoChecksConfigured();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'AddUniqueSortedChecksToHeader' -Value {
|
|
||||||
param($checkarray, $state);
|
|
||||||
|
|
||||||
[hashtable]$CheckHash = @{};
|
|
||||||
|
|
||||||
foreach ($entry in $checkarray) {
|
|
||||||
if ($CheckHash.ContainsKey($entry) -eq $FALSE) {
|
|
||||||
$CheckHash.Add($entry, $TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[array]$SortedCheckArray = $CheckHash.GetEnumerator() | Sort-Object name;
|
|
||||||
|
|
||||||
if ($SortedCheckArray.Count -ne 0) {
|
|
||||||
$this.headermsg += [string]::Format(
|
|
||||||
'{0} {1} ',
|
|
||||||
$IcingaEnums.IcingaExitCodeText[$state],
|
|
||||||
[string]::Join(', ', $SortedCheckArray.Key)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'GetWorstExitCode' -Value {
|
|
||||||
if ([int]$this.exitcode -eq [int]$IcingaEnums.IcingaExitCode.Unknown) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($check in $this.checks) {
|
|
||||||
if ([int]$this.exitcode -lt $check.exitcode) {
|
|
||||||
$this.exitcode = $check.exitcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this.criticalchecks += $check.GetCriticals();
|
|
||||||
$this.warningchecks += $check.GetWarnings();
|
|
||||||
$this.unknownchecks += $check.GetUnknowns();
|
|
||||||
}
|
|
||||||
|
|
||||||
# Only apply this to our top package
|
|
||||||
if ($this.spacing -ne 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this.AddUniqueSortedChecksToHeader(
|
|
||||||
$this.criticalchecks, $IcingaEnums.IcingaExitCode.Critical
|
|
||||||
);
|
|
||||||
$this.AddUniqueSortedChecksToHeader(
|
|
||||||
$this.warningchecks, $IcingaEnums.IcingaExitCode.Warning
|
|
||||||
);
|
|
||||||
$this.AddUniqueSortedChecksToHeader(
|
|
||||||
$this.unknownchecks, $IcingaEnums.IcingaExitCode.Unknown
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$Check | Add-Member -MemberType ScriptMethod -Name 'GetPerfData' -Value {
|
|
||||||
[string]$perfData = '';
|
[string]$perfData = '';
|
||||||
[hashtable]$CollectedPerfData = @{};
|
[hashtable]$CollectedPerfData = @{ };
|
||||||
|
|
||||||
# At first lets collect all perf data, but ensure we only add possible label duplication only once
|
# At first lets collect all perf data, but ensure we only add possible label duplication only once
|
||||||
foreach ($check in $this.checks) {
|
foreach ($check in $this.__Checks) {
|
||||||
$data = $check.GetPerfData();
|
$data = $check.__GetPerformanceData();
|
||||||
|
|
||||||
if ($null -eq $data -Or $null -eq $data.label) {
|
if ($null -eq $data -Or $null -eq $data.label) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -463,22 +349,42 @@ function New-IcingaCheckPackage()
|
||||||
$CollectedPerfData.Add($data.label, $data);
|
$CollectedPerfData.Add($data.label, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Now sort the label output by name
|
|
||||||
$SortedArray = $CollectedPerfData.GetEnumerator() | Sort-Object name;
|
|
||||||
|
|
||||||
# Buold the performance data output based on the sorted result
|
|
||||||
foreach ($entry in $SortedArray) {
|
|
||||||
$perfData += $entry.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return @{
|
return @{
|
||||||
'label' = $this.name;
|
'label' = $this.Name;
|
||||||
'perfdata' = $CollectedPerfData;
|
'perfdata' = $CollectedPerfData;
|
||||||
'package' = $TRUE;
|
'package' = $TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$Check.Initialise();
|
# __GetTimeSpanThreshold(0, 'Core_30_20', 'Core_30')
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Force -Name '__GetTimeSpanThreshold' -Value {
|
||||||
|
param ($TimeSpanLabel, $Label);
|
||||||
|
|
||||||
return $Check;
|
foreach ($check in $this.__Checks) {
|
||||||
|
$Result = $check.__GetTimeSpanThreshold($TimeSpanLabel, $Label);
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($Result) -eq $FALSE) {
|
||||||
|
return $Result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return @{
|
||||||
|
'Warning' = '';
|
||||||
|
'Critical' = '';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
# Override shared function
|
||||||
|
$IcingaCheckPackage | Add-Member -MemberType ScriptMethod -Force -Name 'HasChecks' -Value {
|
||||||
|
if ($this.__Checks.Count -eq 0) {
|
||||||
|
return $FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheckPackage.ValidateOperators();
|
||||||
|
$IcingaCheckPackage.AddCheck($Checks);
|
||||||
|
|
||||||
|
return $IcingaCheckPackage;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,38 @@
|
||||||
Import-IcingaLib icinga\enums;
|
function New-IcingaCheckResult()
|
||||||
|
|
||||||
function New-IcingaCheckresult()
|
|
||||||
{
|
{
|
||||||
param(
|
param (
|
||||||
$Check,
|
$Check,
|
||||||
[bool]$NoPerfData,
|
[bool]$NoPerfData = $FALSE,
|
||||||
[switch]$Compile
|
[switch]$Compile = $FALSE
|
||||||
);
|
);
|
||||||
|
|
||||||
$CheckResult = New-Object -TypeName PSObject;
|
$IcingaCheckResult = New-Object -TypeName PSObject;
|
||||||
$CheckResult | Add-Member -MemberType NoteProperty -Name 'check' -Value $Check;
|
$IcingaCheckResult | Add-Member -MemberType NoteProperty -Name 'Check' -Value $Check;
|
||||||
$CheckResult | Add-Member -MemberType NoteProperty -Name 'noperfdata' -Value $NoPerfData;
|
$IcingaCheckResult | Add-Member -MemberType NoteProperty -Name 'NoPerfData' -Value $NoPerfData;
|
||||||
|
|
||||||
$CheckResult | Add-Member -MemberType ScriptMethod -Name 'Compile' -Value {
|
$IcingaCheckResult | Add-Member -MemberType ScriptMethod -Name 'Compile' -Value {
|
||||||
if ($null -eq $this.check) {
|
if ($null -eq $this.Check) {
|
||||||
return $IcingaEnums.IcingaExitCode.Unknown;
|
return $IcingaEnums.IcingaExitCode.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
$CheckCommand = (Get-PSCallStack)[2].Command;
|
|
||||||
|
|
||||||
# Compile the check / package if not already done
|
# Compile the check / package if not already done
|
||||||
$this.check.AssignCheckCommand($CheckCommand);
|
$this.Check.Compile();
|
||||||
$this.check.Compile($TRUE) | Out-Null;
|
|
||||||
|
|
||||||
if ([int]$this.check.exitcode -ne [int]$IcingaEnums.IcingaExitCode.Unknown -And -Not $this.noperfdata) {
|
Write-IcingaPluginOutput -Output ($this.Check.__GetCheckOutput());
|
||||||
Write-IcingaPluginPerfData -PerformanceData ($this.check.GetPerfData()) -CheckCommand $CheckCommand;
|
|
||||||
|
if ($this.NoPerfData -eq $FALSE) {
|
||||||
|
Write-IcingaPluginPerfData -IcingaCheck $this.Check;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this.check.exitcode;
|
# Ensure we reset our internal cache once the plugin was executed
|
||||||
|
$Global:Icinga.ThresholdCache[$this.Check.__GetCheckCommand()] = $null;
|
||||||
|
|
||||||
|
return $this.Check.__GetCheckState();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Compile) {
|
if ($Compile) {
|
||||||
return $CheckResult.Compile();
|
return $IcingaCheckResult.Compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $CheckResult;
|
return $IcingaCheckResult;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,19 @@ function New-IcingaPerformanceDataEntry()
|
||||||
param (
|
param (
|
||||||
$PerfDataObject,
|
$PerfDataObject,
|
||||||
$Label = $null,
|
$Label = $null,
|
||||||
$Value = $null
|
$Value = $null,
|
||||||
|
$Warning = $null,
|
||||||
|
$Critical = $null
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($null -eq $PerfDataObject) {
|
if ($null -eq $PerfDataObject) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
[string]$LabelName = $PerfDataObject.label;
|
[string]$LabelName = $PerfDataObject.label;
|
||||||
[string]$PerfValue = $PerfDataObject.value;
|
[string]$PerfValue = $PerfDataObject.value;
|
||||||
|
[string]$WarningValue = $PerfDataObject.warning;
|
||||||
|
[string]$CriticalValue = $PerfDataObject.critical;
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($Label) -eq $FALSE) {
|
if ([string]::IsNullOrEmpty($Label) -eq $FALSE) {
|
||||||
$LabelName = $Label;
|
$LabelName = $Label;
|
||||||
|
|
@ -20,6 +24,13 @@ function New-IcingaPerformanceDataEntry()
|
||||||
$PerfValue = $Value;
|
$PerfValue = $Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Override our warning/critical values only if the label does not match.
|
||||||
|
# Eg. Core_1 not matching Core_1_5 - this is only required for time span checks
|
||||||
|
if ([string]::IsNullOrEmpty($Label) -eq $FALSE -And $Label -ne $PerfDataObject.label) {
|
||||||
|
$WarningValue = $Warning;
|
||||||
|
$CriticalValue = $Critical;
|
||||||
|
}
|
||||||
|
|
||||||
$minimum = '';
|
$minimum = '';
|
||||||
$maximum = '';
|
$maximum = '';
|
||||||
|
|
||||||
|
|
@ -36,8 +47,8 @@ function New-IcingaPerformanceDataEntry()
|
||||||
$LabelName.ToLower(),
|
$LabelName.ToLower(),
|
||||||
(Format-IcingaPerfDataValue $PerfValue),
|
(Format-IcingaPerfDataValue $PerfValue),
|
||||||
$PerfDataObject.unit,
|
$PerfDataObject.unit,
|
||||||
(Format-IcingaPerfDataValue $PerfDataObject.warning),
|
(Format-IcingaPerfDataValue $WarningValue),
|
||||||
(Format-IcingaPerfDataValue $PerfDataObject.critical),
|
(Format-IcingaPerfDataValue $CriticalValue),
|
||||||
(Format-IcingaPerfDataValue $minimum),
|
(Format-IcingaPerfDataValue $minimum),
|
||||||
(Format-IcingaPerfDataValue $maximum)
|
(Format-IcingaPerfDataValue $maximum)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
function Write-IcingaPluginPerfData()
|
function Write-IcingaPluginPerfData()
|
||||||
{
|
{
|
||||||
param(
|
param (
|
||||||
$PerformanceData,
|
$IcingaCheck = $null
|
||||||
$CheckCommand
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($null -eq $IcingaCheck) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$PerformanceData = $IcingaCheck.__GetPerformanceData();
|
||||||
|
$CheckCommand = $IcingaCheck.__GetCheckCommand();
|
||||||
|
|
||||||
if ($PerformanceData.package -eq $FALSE) {
|
if ($PerformanceData.package -eq $FALSE) {
|
||||||
$PerformanceData = @{
|
$PerformanceData = @{
|
||||||
$PerformanceData.label = $PerformanceData;
|
$PerformanceData.label = $PerformanceData;
|
||||||
|
|
@ -13,13 +19,13 @@ function Write-IcingaPluginPerfData()
|
||||||
$PerformanceData = $PerformanceData.perfdata;
|
$PerformanceData = $PerformanceData.perfdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
$CheckResultCache = Get-IcingaCacheData -Space 'sc_daemon' -CacheStore 'checkresult' -KeyName $CheckCommand;
|
$CheckResultCache = $Global:Icinga.ThresholdCache[$CheckCommand];
|
||||||
|
|
||||||
if ($global:IcingaDaemonData.FrameworkRunningAsDaemon -eq $FALSE) {
|
if ($global:IcingaDaemonData.FrameworkRunningAsDaemon -eq $FALSE) {
|
||||||
[string]$PerfDataOutput = (Get-IcingaPluginPerfDataContent -PerfData $PerformanceData -CheckResultCache $CheckResultCache);
|
[string]$PerfDataOutput = (Get-IcingaPluginPerfDataContent -PerfData $PerformanceData -CheckResultCache $CheckResultCache -IcingaCheck $IcingaCheck);
|
||||||
Write-IcingaConsolePlain ([string]::Format('| {0}', $PerfDataOutput));
|
Write-IcingaConsolePlain ([string]::Format('| {0}', $PerfDataOutput));
|
||||||
} else {
|
} else {
|
||||||
[void](Get-IcingaPluginPerfDataContent -PerfData $PerformanceData -CheckResultCache $CheckResultCache -AsObject $TRUE);
|
[void](Get-IcingaPluginPerfDataContent -PerfData $PerformanceData -CheckResultCache $CheckResultCache -AsObject $TRUE -IcingaCheck $IcingaCheck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +34,8 @@ function Get-IcingaPluginPerfDataContent()
|
||||||
param(
|
param(
|
||||||
$PerfData,
|
$PerfData,
|
||||||
$CheckResultCache,
|
$CheckResultCache,
|
||||||
[bool]$AsObject = $FALSE
|
[bool]$AsObject = $FALSE,
|
||||||
|
$IcingaCheck = $null
|
||||||
);
|
);
|
||||||
|
|
||||||
[string]$PerfDataOutput = '';
|
[string]$PerfDataOutput = '';
|
||||||
|
|
@ -36,13 +43,16 @@ function Get-IcingaPluginPerfDataContent()
|
||||||
foreach ($package in $PerfData.Keys) {
|
foreach ($package in $PerfData.Keys) {
|
||||||
$data = $PerfData[$package];
|
$data = $PerfData[$package];
|
||||||
if ($data.package) {
|
if ($data.package) {
|
||||||
$PerfDataOutput += (Get-IcingaPluginPerfDataContent -PerfData $data.perfdata -CheckResultCache $CheckResultCache -AsObject $AsObject);
|
$PerfDataOutput += (Get-IcingaPluginPerfDataContent -PerfData $data.perfdata -CheckResultCache $CheckResultCache -AsObject $AsObject -IcingaCheck $IcingaCheck);
|
||||||
} else {
|
} else {
|
||||||
foreach ($checkresult in $CheckResultCache.PSobject.Properties) {
|
foreach ($checkresult in $CheckResultCache.PSobject.Properties) {
|
||||||
|
|
||||||
$SearchPattern = [string]::Format('{0}_', $data.label);
|
$SearchPattern = [string]::Format('{0}_', $data.label);
|
||||||
$SearchEntry = $checkresult.Name;
|
$SearchEntry = $checkresult.Name;
|
||||||
if ($SearchEntry -like "$SearchPattern*") {
|
if ($SearchEntry -like "$SearchPattern*") {
|
||||||
$cachedresult = (New-IcingaPerformanceDataEntry -PerfDataObject $data -Label $SearchEntry -Value $checkresult.Value);
|
$TimeSpan = $IcingaCheck.__GetTimeSpanThreshold($SearchEntry, $data.label);
|
||||||
|
|
||||||
|
$cachedresult = (New-IcingaPerformanceDataEntry -PerfDataObject $data -Label $SearchEntry -Value $checkresult.Value -Warning $TimeSpan.Warning -Critical $TimeSpan.Critical);
|
||||||
|
|
||||||
if ($AsObject) {
|
if ($AsObject) {
|
||||||
# New behavior with local thread separated results
|
# New behavior with local thread separated results
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue