From ddefcf6775ab57a2f61939c9a5fbe66fe0b077fe Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Tue, 17 Dec 2019 17:51:44 +0100 Subject: [PATCH 01/26] Set version of master branch to v1.1.0 --- icinga-powershell-framework.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/icinga-powershell-framework.psd1 b/icinga-powershell-framework.psd1 index 7115173..224369d 100644 --- a/icinga-powershell-framework.psd1 +++ b/icinga-powershell-framework.psd1 @@ -18,7 +18,7 @@ ProjectUri = 'https://github.com/Icinga/icinga-powershell-framework' ReleaseNotes = 'https://github.com/Icinga/icinga-powershell-framework/releases' }; - Version = 'v1.0.0-rc1'; + Version = 'v1.1.0'; } HelpInfoURI = 'https://github.com/Icinga/icinga-powershell-framework' } From 5506c496dbaa6f85ea0b7803336f42ab0c6620a4 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Tue, 17 Dec 2019 17:58:45 +0100 Subject: [PATCH 02/26] Adding gitattributes file --- .gitattributes | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0f04751 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Exclude files related to git when generating an archive +.git* export-ignore + +# Include version information on `git archive' +VERSION export-subst From edacccd75a1b0bd92d62b4747cceaf1980fc6b73 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Wed, 15 Jan 2020 15:25:10 +0100 Subject: [PATCH 03/26] Improve interface detection for multi IP hosts Possibly Fix #38 --- .../tools/ConvertTo-IcingaIPBinaryString.psm1 | 30 ++-- .../tools/Get-IcingaNetworkInterface.psm1 | 139 +++++++++++------- 2 files changed, 106 insertions(+), 63 deletions(-) diff --git a/lib/core/tools/ConvertTo-IcingaIPBinaryString.psm1 b/lib/core/tools/ConvertTo-IcingaIPBinaryString.psm1 index 674634b..7f7bd8f 100644 --- a/lib/core/tools/ConvertTo-IcingaIPBinaryString.psm1 +++ b/lib/core/tools/ConvertTo-IcingaIPBinaryString.psm1 @@ -21,16 +21,22 @@ function ConvertTo-IcingaIPBinaryString() { - param( - $IP - ); - if ($IP -like '*.*') { - $IP = ConvertTo-IcingaIPv4BinaryString -IP $IP; - } elseif ($IP -like '*:*') { - $IP = ConvertTo-IcingaIPv6BinaryString -IP $IP; - } else { - return 'Invalid IP was provided!'; - } + param( + [string]$IP + ); - return $IP; -} \ No newline at end of file + $IPArray = $IP.Split(' '); + $IPList = @(); + + foreach ($entry in $IPArray) { + if ($entry -like '*.*') { + $IPList += ConvertTo-IcingaIPv4BinaryString -IP $entry; + } elseif ($entry -like '*:*') { + $IPList += ConvertTo-IcingaIPv6BinaryString -IP $entry; + } else { + return 'Invalid IP was provided!'; + } + } + + return $IPList; +} diff --git a/lib/core/tools/Get-IcingaNetworkInterface.psm1 b/lib/core/tools/Get-IcingaNetworkInterface.psm1 index f8f514e..7a962b7 100644 --- a/lib/core/tools/Get-IcingaNetworkInterface.psm1 +++ b/lib/core/tools/Get-IcingaNetworkInterface.psm1 @@ -37,7 +37,7 @@ function Get-IcingaNetworkInterface() } try { - $IP = ([System.Net.Dns]::GetHostAddresses($IP)).IPAddressToString; + [array]$IP = ([System.Net.Dns]::GetHostAddresses($IP)).IPAddressToString; } catch { Write-Host 'Invalid IP was provided!'; return $null; @@ -53,72 +53,109 @@ function Get-IcingaNetworkInterface() foreach ( $Info in $InterfaceInfo ) { $Counter++; - $Divide = $Info.DestinationPrefix; - $IP,$Mask = $Divide.Split('/'); + $Divide = $Info.DestinationPrefix; + $IP, $Mask = $Divide.Split('/'); + foreach ($destinationIP in $IPBinStringMaster) { + [string]$Key = ''; + [string]$MaskKey = ''; ############################################################################ ################################ IPv4 #################################### ############################################################################ - if ($IPBinStringMaster.name -eq 'IPv4') { - if ($IP -like '*.*') { + if ($destinationIP.name -eq 'IPv4') { + if ($IP -like '*.*') { ############################################################################ - if ([int]$Mask -lt 10) { - [string]$MaskKey = [string]::Format('00{0}', $Mask); - } else { - [string]$MaskKey = [string]::Format('0{0}', $Mask); - } - - [string]$Key = [string]::Format('{0}-{1}', $MaskKey, $Counter); - - $InterfaceData.Add( - $Key, @{ - 'Binary IP String' = (ConvertTo-IcingaIPBinaryString -IP $IP).value; - 'Mask' = $Mask; - 'Interface' = $Info.ifIndex; + if ([int]$Mask -lt 10) { + $MaskKey = [string]::Format('00{0}', $Mask); + } else { + $MaskKey = [string]::Format('0{0}', $Mask); } - ); ############################################################################ - } - } -############################################################################ -################################ IPv4 #################################### -############################################################################ - if ($IPBinStringMaster.name -eq 'IPv6') { - if ($IP -like '*:*') { -############################################################################ - if ([int]$Mask -lt 10) { - [string]$MaskKey = [string]::Format('00{0}', $Mask); - } elseif ([int]$Mask -lt 100) { - [string]$MaskKey = [string]::Format('0{0}', $Mask); - } else { - [string]$MaskKey = $Mask; } - - [string]$Key = [string]::Format('{0}-{1}', $MaskKey, $Counter); - - $InterfaceData.Add( - $Key, @{ - 'Binary IP String' = (ConvertTo-IcingaIPBinaryString -IP $IP); - 'Mask' = $Mask; - 'Interface' = $Info.ifIndex; - } - ); -############################################################################ } +############################################################################ +################################ IPv6 #################################### +############################################################################ + if ($destinationIP.name -eq 'IPv6') { + if ($IP -like '*:*') { +############################################################################ + if ([int]$Mask -lt 10) { + $MaskKey = [string]::Format('00{0}', $Mask); + } elseif ([int]$Mask -lt 100) { + $MaskKey = [string]::Format('0{0}', $Mask); + } else { + $MaskKey = $Mask; + } +############################################################################ + } + } + + $Key = [string]::Format('{0}-{1}', $MaskKey, $Counter); + + if ($InterfaceData.ContainsKey($Key)) { + continue; + } + + $InterfaceData.Add( + $Key, @{ + 'Binary IP String' = (ConvertTo-IcingaIPBinaryString -IP $IP).value; + 'Mask' = $Mask; + 'Interface' = $Info.ifIndex; + } + ); } } $InterfaceDataOrdered = $InterfaceData.GetEnumerator() | Sort-Object -Property Name -Descending; + $ExternalInterfaces = @{}; foreach ( $Route in $InterfaceDataOrdered ) { - [string]$RegexPattern = [string]::Format("^.{{{0}}}", $Route.Value.Mask); - [string]$ToBeMatched = $Route.Value."Binary IP String"; - $Match1=[regex]::Matches($ToBeMatched, $RegexPattern).Value; - $Match2=[regex]::Matches($IPBinStringMaster.Value, $RegexPattern).Value; + foreach ($destinationIP in $IPBinStringMaster) { + [string]$RegexPattern = [string]::Format("^.{{{0}}}", $Route.Value.Mask); + [string]$ToBeMatched = $Route.Value."Binary IP String"; + $Match1=[regex]::Matches($ToBeMatched, $RegexPattern).Value; + $Match2=[regex]::Matches($destinationIP.Value, $RegexPattern).Value; - If ($Match1 -like $Match2) { - return ((Get-NetIPAddress -InterfaceIndex $Route.Value.Interface -AddressFamily $IPBinStringMaster.name).IPAddress); + If ($Match1 -like $Match2) { + $ExternalInterface = ((Get-NetIPAddress -InterfaceIndex $Route.Value.Interface -AddressFamily $destinationIP.Name).IPAddress); + if ($ExternalInterfaces.ContainsKey($ExternalInterface)) { + $ExternalInterfaces[$ExternalInterface].count += 1; + } else { + $ExternalInterfaces.Add( + $ExternalInterface, + @{ + 'count' = 1 + } + ); + } + } } } - return ((Get-NetIPAddress -InterfaceIndex (Get-NetRoute | Where-Object -Property DestinationPrefix -like '0.0.0.0/0')[0].IfIndex -AddressFamily $IPBinStringMaster.name).IPAddress).split('%')[0]; + + if ($ExternalInterfaces.Count -eq 0) { + foreach ($destinationIP in $IPBinStringMaster) { + $ExternalInterface = ((Get-NetIPAddress -InterfaceIndex (Get-NetRoute | Where-Object -Property DestinationPrefix -like '0.0.0.0/0')[0].IfIndex -AddressFamily $destinationIP.name).IPAddress).split('%')[0]; + if ($ExternalInterfaces.ContainsKey($ExternalInterface)) { + $ExternalInterfaces[$ExternalInterface].count += 1; + } else { + $ExternalInterfaces.Add( + $ExternalInterface, + @{ + 'count' = 1 + } + ); + } + } + } + + $InternalCount = 0; + $UseInterface = ''; + foreach ($interface in $ExternalInterfaces.Keys) { + $currentCount = $ExternalInterfaces[$interface].count; + if ($currentCount -gt $InternalCount) { + $InternalCount = $currentCount; + $UseInterface = $interface; + } + } + return $UseInterface; } From d096e446de7a875299d87c86119f2d770ba41027 Mon Sep 17 00:00:00 2001 From: Crited <45196568+Crited@users.noreply.github.com> Date: Fri, 24 Jan 2020 09:12:03 +0100 Subject: [PATCH 04/26] Fix link in documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 353280d..4a66582 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Please take a look at the following content to get to know the possibilities of Developer Guide ------------ -If you wish to extend the Framework by yourself or write custom plugins for your environment, please have a look at the [Developer Guide](doc/04-DeveloperGuide.md) for detailed explanations of functions and code examples. +If you wish to extend the Framework by yourself or write custom plugins for your environment, please have a look at the [Developer Guide](doc/04-Developer-Guide.md) for detailed explanations of functions and code examples. Contributing ------------ From 61a6aaee7c8641a4ae8edaf6ea784cb86ef4590d Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 3 Feb 2020 10:27:18 +0100 Subject: [PATCH 05/26] Fixes url to repository --- doc/installation/01-Kickstart-Script.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/installation/01-Kickstart-Script.md b/doc/installation/01-Kickstart-Script.md index ae09dfb..4015660 100644 --- a/doc/installation/01-Kickstart-Script.md +++ b/doc/installation/01-Kickstart-Script.md @@ -1,7 +1,7 @@ Install the framework with the Kickstart Script === -The easiest way to install the framework is by using the Kickstart Script provided from [this repository](https://github.com/Icinga/icinga-framework-kickstart). +The easiest way to install the framework is by using the Kickstart Script provided from [this repository](https://github.com/Icinga/icinga-powershell-kickstart). The code provided there will ask questions on where to install the framework and where the framework files are provided from. The code below is a straight copy of the initial required code-block. Simply open a PowerShell instance as administrator and copy the following code block into it: From ac98e88626018eabab7e3ac56a2bedf107b98e9f Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Mon, 3 Feb 2020 17:28:31 +0100 Subject: [PATCH 06/26] Fixes broken switch arguments in basket configurator Fixes #39 --- lib/core/tools/Get-IcingaCheckCommandConfig.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 b/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 index e98769b..4f63c2d 100644 --- a/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 +++ b/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 @@ -148,7 +148,7 @@ function Get-IcingaCheckCommandConfig() } # Add arguments to a given command - if ($parameter.type.name -eq 'switch') { + if ($parameter.type.name -eq 'SwitchParameter') { $Basket.Command[$Data.Name].arguments.Add( [string]::Format('-{0}', $parameter.Name), @{ 'set_if' = $IcingaCustomVariable; @@ -160,7 +160,7 @@ function Get-IcingaCheckCommandConfig() $Basket.Command[$Data.Name].vars.Add($parameter.Name, $FALSE); # Conditional whether type of parameter is array - } elseif ($parameter.type.name -eq 'array') { + } elseif ($parameter.type.name -eq 'Array') { $Basket.Command[$Data.Name].arguments.Add( [string]::Format('-{0}', $parameter.Name), @{ 'value' = @{ From bec345923135de344de8e54b4010bb79bace83ad Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Mon, 3 Feb 2020 17:56:34 +0100 Subject: [PATCH 07/26] Adds proper handling for invalid inputs on byte conversion for plugin usage --- lib/core/tools/Convert-Bytes.psm1 | 5 +++-- lib/core/tools/ConvertTo-ByteUnitIEC.psm1 | 12 ++++++------ lib/core/tools/ConvertTo-ByteUnitSI.psm1 | 12 ++++++------ .../exception/Icinga_IcingaExceptionEnums.psm1 | 11 ++++++----- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/core/tools/Convert-Bytes.psm1 b/lib/core/tools/Convert-Bytes.psm1 index 421b8a5..b2e484a 100644 --- a/lib/core/tools/Convert-Bytes.psm1 +++ b/lib/core/tools/Convert-Bytes.psm1 @@ -30,11 +30,12 @@ function Convert-Bytes() default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } return @{'value' = $FinalValue; 'pastunit' = $CurrentUnit; 'endunit' = $Unit}; } - Throw 'Invalid input'; + + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } \ No newline at end of file diff --git a/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 b/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 index ec9256c..d1ac06b 100644 --- a/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 +++ b/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 @@ -14,7 +14,7 @@ function ConvertTo-ByteIEC() { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -38,7 +38,7 @@ function ConvertTo-KibiByte() { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -62,7 +62,7 @@ function ConvertTo-MibiByte() { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -86,7 +86,7 @@ function ConvertTo-GibiByte() { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -110,7 +110,7 @@ function ConvertTo-TibiByte() { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -134,7 +134,7 @@ function ConvertTo-PitiByte() { 'Piti', 'PitiByte' -contains $_ } { $result = $Value; $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } diff --git a/lib/core/tools/ConvertTo-ByteUnitSI.psm1 b/lib/core/tools/ConvertTo-ByteUnitSI.psm1 index 2602611..c01bdd9 100644 --- a/lib/core/tools/ConvertTo-ByteUnitSI.psm1 +++ b/lib/core/tools/ConvertTo-ByteUnitSI.psm1 @@ -30,7 +30,7 @@ function ConvertTo-ByteSI() { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -70,7 +70,7 @@ function ConvertTo-KiloByte() { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -110,7 +110,7 @@ function ConvertTo-MegaByte() { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -150,7 +150,7 @@ function ConvertTo-GigaByte() { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -190,7 +190,7 @@ function ConvertTo-TeraByte() { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -230,7 +230,7 @@ function ConvertTo-PetaByte() { 'PT', 'PetaByte' -contains $_ } { $result = $Value; $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } diff --git a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 index 41b8cbb..18c80ed 100644 --- a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 +++ b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 @@ -5,14 +5,15 @@ #> [hashtable]$Permission = @{ - PerformanceCounter = 'A Plugin failed to fetch Performance Counter information. This may be caused when the used Service User is not permitted to access these information. To fix this, please add the User the Icinga Agent is running on into the "Performance Log Users" group and restart the service.'; - CacheFolder = "A plugin failed to write new data into the configured cache directory. Please update the permissions of this folder to allow write access for the user the Icinga Service is running with or use another folder as cache directory."; + PerformanceCounter = 'A Plugin failed to fetch Performance Counter information. This may be caused when the used Service User is not permitted to access these information. To fix this, please add the User the Icinga Agent is running on into the "Performance Log Users" group and restart the service.'; + CacheFolder = "A plugin failed to write new data into the configured cache directory. Please update the permissions of this folder to allow write access for the user the Icinga Service is running with or use another folder as cache directory."; }; [hashtable]$Inputs = @{ - PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.'; - EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid LogName.'; - EventLog = 'Failed to fetch EventLog information. Please check your inputs for EntryTypes and other categories and try again.'; + PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.'; + EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid LogName.'; + EventLog = 'Failed to fetch EventLog information. Please check your inputs for EntryTypes and other categories and try again.'; + ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PT, Kibi, Mibi, Gibi, Tibi, Piti".'; }; <# From ff06ea5f135971e3d7f66421427676ff5dfd18e3 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Mon, 3 Feb 2020 18:03:40 +0100 Subject: [PATCH 08/26] Fixes unit naming for byte related types --- lib/core/tools/Convert-Bytes.psm1 | 14 ++-- lib/core/tools/ConvertTo-ByteUnitIEC.psm1 | 70 +++++++++---------- .../Icinga_IcingaExceptionEnums.psm1 | 2 +- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/lib/core/tools/Convert-Bytes.psm1 b/lib/core/tools/Convert-Bytes.psm1 index b2e484a..0ab5a5e 100644 --- a/lib/core/tools/Convert-Bytes.psm1 +++ b/lib/core/tools/Convert-Bytes.psm1 @@ -5,12 +5,12 @@ function Convert-Bytes() [string]$Unit ); - If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|Kibi|Mibi|Gibi|Tibi|Pibi)")) { + If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) { [single]$CurrentValue = $Matches[1]; [string]$CurrentUnit = $Matches[2]; switch ($CurrentUnit) { - { 'KiBi', 'Mibi', 'Gibi', 'Tibi', 'Pibi' -contains $_} { $CurrentValue = ConvertTo-ByteIEC $CurrentValue $CurrentUnit; $boolOption = $true;} + { 'KiB', 'MiB', 'GiB', 'TiB', 'PiB' -contains $_} { $CurrentValue = ConvertTo-ByteIEC $CurrentValue $CurrentUnit; $boolOption = $true;} { 'KB', 'MB', 'GB', 'TB', 'PB' -contains $_} { $CurrentValue = ConvertTo-ByteSI $CurrentValue $CurrentUnit; $boolOption = $true;} } @@ -22,11 +22,11 @@ function Convert-Bytes() { 'GB' -contains $_} { $FinalValue = ConvertTo-GigaByte $CurrentValue -Unit B; $boolOption = $true;} { 'TB' -contains $_} { $FinalValue = ConvertTo-TeraByte $CurrentValue -Unit B; $boolOption = $true;} { 'PT' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} - { 'Kibi' -contains $_} { $FinalValue = ConvertTo-KibiByte $CurrentValue -Unit B; $boolOption = $true;} - { 'Mibi' -contains $_} { $FinalValue = ConvertTo-MibiByte $CurrentValue -Unit B; $boolOption = $true;} - { 'Gibi' -contains $_} { $FinalValue = ConvertTo-GibiByte $CurrentValue -Unit B; $boolOption = $true;} - { 'Tibi' -contains $_} { $FinalValue = ConvertTo-TibiByte $CurrentValue -Unit B; $boolOption = $true;} - { 'Piti' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} + { 'KiB' -contains $_} { $FinalValue = ConvertTo-KiBByte $CurrentValue -Unit B; $boolOption = $true;} + { 'MiB' -contains $_} { $FinalValue = ConvertTo-MiBByte $CurrentValue -Unit B; $boolOption = $true;} + { 'GiB' -contains $_} { $FinalValue = ConvertTo-GiBByte $CurrentValue -Unit B; $boolOption = $true;} + { 'TiB' -contains $_} { $FinalValue = ConvertTo-TiBByte $CurrentValue -Unit B; $boolOption = $true;} + { 'PiB' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} default { if (-Not $boolOption) { diff --git a/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 b/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 index d1ac06b..fa8f4d3 100644 --- a/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 +++ b/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 @@ -7,11 +7,11 @@ function ConvertTo-ByteIEC() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -22,7 +22,7 @@ function ConvertTo-ByteIEC() return $result; } -function ConvertTo-KibiByte() +function ConvertTo-KiBByte() { param( [single]$Value, @@ -31,11 +31,11 @@ function ConvertTo-KibiByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -46,7 +46,7 @@ function ConvertTo-KibiByte() return $result; } -function ConvertTo-MibiByte() +function ConvertTo-MiBByte() { param( [single]$Value, @@ -55,11 +55,11 @@ function ConvertTo-MibiByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -70,7 +70,7 @@ function ConvertTo-MibiByte() return $result; } -function ConvertTo-GibiByte() +function ConvertTo-GiBByte() { param( [single]$Value, @@ -79,11 +79,11 @@ function ConvertTo-GibiByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -94,7 +94,7 @@ function ConvertTo-GibiByte() return $result; } -function ConvertTo-TibiByte() +function ConvertTo-TiBByte() { param( [single]$Value, @@ -103,11 +103,11 @@ function ConvertTo-TibiByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -118,7 +118,7 @@ function ConvertTo-TibiByte() return $result; } -function ConvertTo-PitiByte() +function ConvertTo-PiBByte() { param( [single]$Value, @@ -127,11 +127,11 @@ function ConvertTo-PitiByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 50)); $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; diff --git a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 index 18c80ed..d4dfded 100644 --- a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 +++ b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 @@ -13,7 +13,7 @@ PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.'; EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid LogName.'; EventLog = 'Failed to fetch EventLog information. Please check your inputs for EntryTypes and other categories and try again.'; - ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PT, Kibi, Mibi, Gibi, Tibi, Piti".'; + ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PT, KiB, MiB, GiB, TiB, PiB".'; }; <# From 499af2b92ee9f3eae9d4ef6e4b716bc99442fc1b Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Mon, 3 Feb 2020 18:09:03 +0100 Subject: [PATCH 09/26] Fixes PetaByte unit short name --- lib/core/tools/Convert-Bytes.psm1 | 2 +- lib/core/tools/ConvertTo-ByteUnitSI.psm1 | 12 ++++++------ .../exception/Icinga_IcingaExceptionEnums.psm1 | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/core/tools/Convert-Bytes.psm1 b/lib/core/tools/Convert-Bytes.psm1 index 0ab5a5e..ec9a6e2 100644 --- a/lib/core/tools/Convert-Bytes.psm1 +++ b/lib/core/tools/Convert-Bytes.psm1 @@ -21,7 +21,7 @@ function Convert-Bytes() { 'MB' -contains $_} { $FinalValue = ConvertTo-MegaByte $CurrentValue -Unit B; $boolOption = $true;} { 'GB' -contains $_} { $FinalValue = ConvertTo-GigaByte $CurrentValue -Unit B; $boolOption = $true;} { 'TB' -contains $_} { $FinalValue = ConvertTo-TeraByte $CurrentValue -Unit B; $boolOption = $true;} - { 'PT' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} + { 'PB' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} { 'KiB' -contains $_} { $FinalValue = ConvertTo-KiBByte $CurrentValue -Unit B; $boolOption = $true;} { 'MiB' -contains $_} { $FinalValue = ConvertTo-MiBByte $CurrentValue -Unit B; $boolOption = $true;} { 'GiB' -contains $_} { $FinalValue = ConvertTo-GiBByte $CurrentValue -Unit B; $boolOption = $true;} diff --git a/lib/core/tools/ConvertTo-ByteUnitSI.psm1 b/lib/core/tools/ConvertTo-ByteUnitSI.psm1 index c01bdd9..301fa49 100644 --- a/lib/core/tools/ConvertTo-ByteUnitSI.psm1 +++ b/lib/core/tools/ConvertTo-ByteUnitSI.psm1 @@ -27,7 +27,7 @@ function ConvertTo-ByteSI() { 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } - { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; } + { 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -67,7 +67,7 @@ function ConvertTo-KiloByte() { 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } - { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } + { 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -107,7 +107,7 @@ function ConvertTo-MegaByte() { 'MB', 'MegaByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } - { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } + { 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -147,7 +147,7 @@ function ConvertTo-GigaByte() { 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } - { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } + { 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -187,7 +187,7 @@ function ConvertTo-TeraByte() { 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } + { 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -227,7 +227,7 @@ function ConvertTo-PetaByte() { 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } - { 'PT', 'PetaByte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'PB', 'PetaByte' -contains $_ } { $result = $Value; $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; diff --git a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 index d4dfded..5422093 100644 --- a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 +++ b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 @@ -13,7 +13,7 @@ PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.'; EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid LogName.'; EventLog = 'Failed to fetch EventLog information. Please check your inputs for EntryTypes and other categories and try again.'; - ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PT, KiB, MiB, GiB, TiB, PiB".'; + ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB".'; }; <# From 80975bee24418c424ca2e056922744b71b71d6fc Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Tue, 4 Feb 2020 09:33:27 +0100 Subject: [PATCH 10/26] Fixes naming of byte data types and functions --- doc/developerguide/01-New-IcingaCheck.md | 8 +- lib/core/tools/Convert-Bytes.psm1 | 20 ++-- lib/core/tools/ConvertTo-ByteUnitIEC.psm1 | 34 +++---- lib/core/tools/ConvertTo-ByteUnitSI.psm1 | 110 +++++++++++----------- lib/icinga/enums/Icinga_IcingaEnums.psm1 | 8 +- 5 files changed, 90 insertions(+), 90 deletions(-) diff --git a/doc/developerguide/01-New-IcingaCheck.md b/doc/developerguide/01-New-IcingaCheck.md index 27e47fd..ac89545 100644 --- a/doc/developerguide/01-New-IcingaCheck.md +++ b/doc/developerguide/01-New-IcingaCheck.md @@ -42,10 +42,10 @@ For performance metrics you can provide a `Unit` to ensure your graphing is disp | ms | Milliseconds | The input is indicated as time in milliseconds | | us | Microseconds | The input is indicated as time in microseconds | | B | Bytes | The input is indicated as quantity in bytes | -| KB | Kilobytes | The input is indicated as quantity in kilobytes | -| MB | Megabytes | The input is indicated as quantity in megabytes | -| GB | Gigabytes | The input is indicated as quantity in gigabytes | -| TB | Terabytes | The input is indicated as quantity in terabytes | +| KB | Kilobytes | The input is indicated as quantity in Kilobytes | +| MB | Megabytes | The input is indicated as quantity in Megabytes | +| GB | Gigabytes | The input is indicated as quantity in Gigabytes | +| TB | Terabytes | The input is indicated as quantity in Terabytes | | c | Counter | A continues counter increasing values over time | ## Object Functions diff --git a/lib/core/tools/Convert-Bytes.psm1 b/lib/core/tools/Convert-Bytes.psm1 index ec9a6e2..2d7d9c8 100644 --- a/lib/core/tools/Convert-Bytes.psm1 +++ b/lib/core/tools/Convert-Bytes.psm1 @@ -17,16 +17,16 @@ function Convert-Bytes() switch ($Unit) { { 'B' -contains $_} { $FinalValue = $CurrentValue; $boolOption = $true;} - { 'KB' -contains $_} { $FinalValue = ConvertTo-KiloByte $CurrentValue -Unit B; $boolOption = $true;} - { 'MB' -contains $_} { $FinalValue = ConvertTo-MegaByte $CurrentValue -Unit B; $boolOption = $true;} - { 'GB' -contains $_} { $FinalValue = ConvertTo-GigaByte $CurrentValue -Unit B; $boolOption = $true;} - { 'TB' -contains $_} { $FinalValue = ConvertTo-TeraByte $CurrentValue -Unit B; $boolOption = $true;} - { 'PB' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} - { 'KiB' -contains $_} { $FinalValue = ConvertTo-KiBByte $CurrentValue -Unit B; $boolOption = $true;} - { 'MiB' -contains $_} { $FinalValue = ConvertTo-MiBByte $CurrentValue -Unit B; $boolOption = $true;} - { 'GiB' -contains $_} { $FinalValue = ConvertTo-GiBByte $CurrentValue -Unit B; $boolOption = $true;} - { 'TiB' -contains $_} { $FinalValue = ConvertTo-TiBByte $CurrentValue -Unit B; $boolOption = $true;} - { 'PiB' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} + { 'KB' -contains $_} { $FinalValue = ConvertTo-Kilobyte $CurrentValue -Unit B; $boolOption = $true;} + { 'MB' -contains $_} { $FinalValue = ConvertTo-Megabyte $CurrentValue -Unit B; $boolOption = $true;} + { 'GB' -contains $_} { $FinalValue = ConvertTo-Gigabyte $CurrentValue -Unit B; $boolOption = $true;} + { 'TB' -contains $_} { $FinalValue = ConvertTo-Terabyte $CurrentValue -Unit B; $boolOption = $true;} + { 'PB' -contains $_} { $FinalValue = ConvertTo-Petabyte $CurrentValue -Unit B; $boolOption = $true;} + { 'KiB' -contains $_} { $FinalValue = ConvertTo-Kibibyte $CurrentValue -Unit B; $boolOption = $true;} + { 'MiB' -contains $_} { $FinalValue = ConvertTo-Mebibyte $CurrentValue -Unit B; $boolOption = $true;} + { 'GiB' -contains $_} { $FinalValue = ConvertTo-Gibibyte $CurrentValue -Unit B; $boolOption = $true;} + { 'TiB' -contains $_} { $FinalValue = ConvertTo-Tebibyte $CurrentValue -Unit B; $boolOption = $true;} + { 'PiB' -contains $_} { $FinalValue = ConvertTo-Petabyte $CurrentValue -Unit B; $boolOption = $true;} default { if (-Not $boolOption) { diff --git a/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 b/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 index fa8f4d3..e169498 100644 --- a/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 +++ b/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 @@ -7,9 +7,9 @@ function ConvertTo-ByteIEC() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } - { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } + { 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; } default { @@ -22,7 +22,7 @@ function ConvertTo-ByteIEC() return $result; } -function ConvertTo-KiBByte() +function ConvertTo-Kibibyte() { param( [single]$Value, @@ -31,9 +31,9 @@ function ConvertTo-KiBByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'KiB', 'KiBByte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'KiB', 'Kibibyte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } - { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } + { 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } default { @@ -46,7 +46,7 @@ function ConvertTo-KiBByte() return $result; } -function ConvertTo-MiBByte() +function ConvertTo-Mebibyte() { param( [single]$Value, @@ -55,9 +55,9 @@ function ConvertTo-MiBByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } - { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } + { 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } default { @@ -70,7 +70,7 @@ function ConvertTo-MiBByte() return $result; } -function ConvertTo-GiBByte() +function ConvertTo-Gibibyte() { param( [single]$Value, @@ -79,9 +79,9 @@ function ConvertTo-GiBByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } - { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } + { 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'GiB', 'GiBByte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'GiB', 'Gibibyte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } default { @@ -94,7 +94,7 @@ function ConvertTo-GiBByte() return $result; } -function ConvertTo-TiBByte() +function ConvertTo-Tebibyte() { param( [single]$Value, @@ -103,9 +103,9 @@ function ConvertTo-TiBByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } - { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } + { 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } - { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } + { 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } default { @@ -118,7 +118,7 @@ function ConvertTo-TiBByte() return $result; } -function ConvertTo-PiBByte() +function ConvertTo-Pebibyte() { param( [single]$Value, @@ -127,9 +127,9 @@ function ConvertTo-PiBByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 50)); $boolOption = $true; } - { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } + { 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } - { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } + { 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } default { diff --git a/lib/core/tools/ConvertTo-ByteUnitSI.psm1 b/lib/core/tools/ConvertTo-ByteUnitSI.psm1 index 301fa49..8c94731 100644 --- a/lib/core/tools/ConvertTo-ByteUnitSI.psm1 +++ b/lib/core/tools/ConvertTo-ByteUnitSI.psm1 @@ -23,11 +23,11 @@ function ConvertTo-ByteSI() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'KB', 'KiloByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } - { 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } - { 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } - { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } - { 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; } + { 'KB', 'Kilobyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } + { 'MB', 'Megabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } + { 'GB', 'Gigabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } + { 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } + { 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -40,21 +40,21 @@ function ConvertTo-ByteSI() <# .SYNOPSIS - Converts unit sizes to kilobyte. + Converts unit sizes to Kilobyte. .DESCRIPTION - This module converts a given unit size to kilobyte. - e.g byte to kilobyte. + This module converts a given unit size to Kilobyte. + e.g byte to Kilobyte. More Information on https://github.com/Icinga/icinga-powershell-framework .EXAMPLE - PS> ConvertTo-KiloByte -Unit TB 200 + PS> ConvertTo-Kilobyte -Unit TB 200 200000000000 .LINK https://github.com/Icinga/icinga-powershell-framework .NOTES #> -function ConvertTo-KiloByte() +function ConvertTo-Kilobyte() { param( [single]$Value, @@ -63,11 +63,11 @@ function ConvertTo-KiloByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } - { 'KB', 'KiloByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } - { 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } - { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } - { 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } + { 'KB', 'Kilobyte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'MB', 'Megabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } + { 'GB', 'Gigabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } + { 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } + { 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -80,21 +80,21 @@ function ConvertTo-KiloByte() <# .SYNOPSIS - Converts unit sizes to megabyte. + Converts unit sizes to Megabyte. .DESCRIPTION - This module converts a given unit size to megabyte. - e.g byte to megabyte. + This module converts a given unit size to Megabyte. + e.g byte to Megabyte. More Information on https://github.com/Icinga/icinga-powershell-framework .EXAMPLE - PS> ConvertTo-KiloByte -Unit TB 200 + PS> ConvertTo-Kilobyte -Unit TB 200 200000000 .LINK https://github.com/Icinga/icinga-powershell-framework .NOTES #> -function ConvertTo-MegaByte() +function ConvertTo-Megabyte() { param( [single]$Value, @@ -103,11 +103,11 @@ function ConvertTo-MegaByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } - { 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } - { 'MB', 'MegaByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } - { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } - { 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } + { 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } + { 'MB', 'Megabyte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'GB', 'Gigabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } + { 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } + { 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -120,21 +120,21 @@ function ConvertTo-MegaByte() <# .SYNOPSIS - Converts unit sizes to gigabyte. + Converts unit sizes to Gigabyte. .DESCRIPTION - This module converts a given unit size to gigabyte. - e.g byte to gigabyte. + This module converts a given unit size to Gigabyte. + e.g byte to Gigabyte. More Information on https://github.com/Icinga/icinga-powershell-framework .EXAMPLE - PS> ConvertTo-GigaByte -Unit TB 200 + PS> ConvertTo-Gigabyte -Unit TB 200 200000 .LINK https://github.com/Icinga/icinga-powershell-framework .NOTES #> -function ConvertTo-GigaByte() +function ConvertTo-Gigabyte() { param( [single]$Value, @@ -143,11 +143,11 @@ function ConvertTo-GigaByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } - { 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } - { 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } - { 'GB', 'GigaByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } - { 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } + { 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } + { 'MB', 'Megabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } + { 'GB', 'Gigabyte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } + { 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -160,21 +160,21 @@ function ConvertTo-GigaByte() <# .SYNOPSIS - Converts unit sizes to terabyte. + Converts unit sizes to Terabyte. .DESCRIPTION - This module converts a given unit size to terabyte. - e.g byte to terabyte. + This module converts a given unit size to Terabyte. + e.g byte to Terabyte. More Information on https://github.com/Icinga/icinga-powershell-framework .EXAMPLE - PS> ConvertTo-TeraByte -Unit GB 2000000 + PS> ConvertTo-Terabyte -Unit GB 2000000 2000 .LINK https://github.com/Icinga/icinga-powershell-framework .NOTES #> -function ConvertTo-TeraByte() +function ConvertTo-Terabyte() { param( [single]$Value, @@ -183,11 +183,11 @@ function ConvertTo-TeraByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; } - { 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } - { 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } - { 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } - { 'TB', 'TeraByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } + { 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } + { 'MB', 'Megabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } + { 'GB', 'Gigabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } + { 'TB', 'Terabyte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -200,21 +200,21 @@ function ConvertTo-TeraByte() <# .SYNOPSIS - Converts unit sizes to petabyte. + Converts unit sizes to Petabyte. .DESCRIPTION - This module converts a given unit size to petabyte. - e.g byte to petabyte. + This module converts a given unit size to Petabyte. + e.g byte to Petabyte. More Information on https://github.com/Icinga/icinga-powershell-framework .EXAMPLE - PS> ConvertTo-PetaByte -Unit GB 2000000 + PS> ConvertTo-Petabyte -Unit GB 2000000 2 .LINK https://github.com/Icinga/icinga-powershell-framework .NOTES #> -function ConvertTo-PetaByte() +function ConvertTo-Petabyte() { param( [single]$Value, @@ -223,11 +223,11 @@ function ConvertTo-PetaByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 15)); $boolOption = $true; } - { 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; } - { 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } - { 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } - { 'TB', 'TeraByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } - { 'PB', 'PetaByte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; } + { 'MB', 'Megabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } + { 'GB', 'Gigabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } + { 'TB', 'Terabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } + { 'PB', 'Petabyte' -contains $_ } { $result = $Value; $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; diff --git a/lib/icinga/enums/Icinga_IcingaEnums.psm1 b/lib/icinga/enums/Icinga_IcingaEnums.psm1 index c3fcd0f..0ffac3d 100644 --- a/lib/icinga/enums/Icinga_IcingaEnums.psm1 +++ b/lib/icinga/enums/Icinga_IcingaEnums.psm1 @@ -24,10 +24,10 @@ 'us' = 'microseconds'; '%' = 'percent'; 'B' = 'bytes'; - 'KB' = 'kilobytes'; - 'MB' = 'megabytes'; - 'GB' = 'gigabytes'; - 'TB' = 'terabytes'; + 'KB' = 'Kilobytes'; + 'MB' = 'Megabytes'; + 'GB' = 'Gigabytes'; + 'TB' = 'Terabytes'; 'c' = 'counter'; }; From a724f486f8f5741fbcf020e64c0593ed8ec59643 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Tue, 4 Feb 2020 09:34:01 +0100 Subject: [PATCH 11/26] Fixes missing error message from Icinga Director Self-Service API on Wizard --- lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 b/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 index 02e83a0..53b4556 100644 --- a/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 +++ b/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 @@ -79,7 +79,7 @@ function Start-IcingaAgentDirectorWizard() $SelfServiceAPIKey = Register-IcingaDirectorSelfServiceHost -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey -Hostname (Get-IcingaHostname @Arguments) -Endpoint $Arguments.IcingaMaster; break; } catch { - $SelfServiceAPIKey = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Failed to register host within Icinga Director. Please re-enter your SelfService API Key. If this prompt continues, drop your host key at "Hosts -> {0} -> Agent"', (Get-IcingaHostname @Arguments))) -Default 'v' -DefaultInput $SelfServiceAPIKey).answer; + $SelfServiceAPIKey = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Failed to register host within Icinga Director. Full error: "{0}". Please re-enter your SelfService API Key. If this prompt continues ensure you are using an Agent template or drop your host key at "Hosts -> {1} -> Agent"', $_.Exception.Message, (Get-IcingaHostname @Arguments))) -Default 'v' -DefaultInput $SelfServiceAPIKey).answer; } } From 9b6941c4b9bd396b1d75ce8e015d0057610f6c10 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Fri, 7 Feb 2020 11:06:57 +0100 Subject: [PATCH 12/26] Fixes exceptions during interface discovery Fix #38 --- .../tools/ConvertTo-IcingaIPBinaryString.psm1 | 21 +++++-------- .../ConvertTo-IcingaIPv4BinaryString.psm1 | 30 +++++++++++-------- .../tools/Get-IcingaNetworkInterface.psm1 | 12 +++++++- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/lib/core/tools/ConvertTo-IcingaIPBinaryString.psm1 b/lib/core/tools/ConvertTo-IcingaIPBinaryString.psm1 index 7f7bd8f..d21db80 100644 --- a/lib/core/tools/ConvertTo-IcingaIPBinaryString.psm1 +++ b/lib/core/tools/ConvertTo-IcingaIPBinaryString.psm1 @@ -22,21 +22,16 @@ function ConvertTo-IcingaIPBinaryString() { param( - [string]$IP + $IP ); - $IPArray = $IP.Split(' '); - $IPList = @(); - - foreach ($entry in $IPArray) { - if ($entry -like '*.*') { - $IPList += ConvertTo-IcingaIPv4BinaryString -IP $entry; - } elseif ($entry -like '*:*') { - $IPList += ConvertTo-IcingaIPv6BinaryString -IP $entry; - } else { - return 'Invalid IP was provided!'; - } + if ($IP -like '*.*') { + $IP = ConvertTo-IcingaIPv4BinaryString -IP $IP; + } elseif ($IP -like '*:*') { + $IP = ConvertTo-IcingaIPv6BinaryString -IP $IP; + } else { + return 'Invalid IP was provided!'; } - return $IPList; + return $IP; } diff --git a/lib/core/tools/ConvertTo-IcingaIPv4BinaryString.psm1 b/lib/core/tools/ConvertTo-IcingaIPv4BinaryString.psm1 index a6c9133..dfeb0a2 100644 --- a/lib/core/tools/ConvertTo-IcingaIPv4BinaryString.psm1 +++ b/lib/core/tools/ConvertTo-IcingaIPv4BinaryString.psm1 @@ -21,18 +21,24 @@ function ConvertTo-IcingaIPv4BinaryString() { - param( - [string]$IP - ); + param( + [string]$IP + ); - $IP = $IP -split '\.' | ForEach-Object { - [System.Convert]::ToString($_, 2).PadLeft(8, '0'); - } - $IP = $IP -join ''; - $IP = $IP -replace '\s',''; - - return @{ - 'value' = $IP; - 'name' = 'IPv4' + try { + $IP = $IP -split '\.' | ForEach-Object { + [System.Convert]::ToString($_, 2).PadLeft(8, '0'); + } + $IP = $IP -join ''; + $IP = $IP -replace '\s',''; + } catch { + # Todo: Should we handle errors? It might happen due to faulty routes or unhandled route config + # we throw errors which should have no effect at all + return $null; + } + + return @{ + 'value' = $IP; + 'name' = 'IPv4' } } diff --git a/lib/core/tools/Get-IcingaNetworkInterface.psm1 b/lib/core/tools/Get-IcingaNetworkInterface.psm1 index 7a962b7..ad72151 100644 --- a/lib/core/tools/Get-IcingaNetworkInterface.psm1 +++ b/lib/core/tools/Get-IcingaNetworkInterface.psm1 @@ -113,11 +113,21 @@ function Get-IcingaNetworkInterface() foreach ($destinationIP in $IPBinStringMaster) { [string]$RegexPattern = [string]::Format("^.{{{0}}}", $Route.Value.Mask); [string]$ToBeMatched = $Route.Value."Binary IP String"; + if ($null -eq $ToBeMatched) { + continue; + } + $Match1=[regex]::Matches($ToBeMatched, $RegexPattern).Value; $Match2=[regex]::Matches($destinationIP.Value, $RegexPattern).Value; If ($Match1 -like $Match2) { - $ExternalInterface = ((Get-NetIPAddress -InterfaceIndex $Route.Value.Interface -AddressFamily $destinationIP.Name).IPAddress); + $ExternalInterface = ((Get-NetIPAddress -InterfaceIndex $Route.Value.Interface -AddressFamily $destinationIP.Name -ErrorAction SilentlyContinue).IPAddress); + + # If no interface was found -> skip this entry + if ($null -eq $ExternalInterface) { + continue; + } + if ($ExternalInterfaces.ContainsKey($ExternalInterface)) { $ExternalInterfaces[$ExternalInterface].count += 1; } else { From 58d2aa7403cd678b3b22b424cf742c0e0251578f Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Fri, 7 Feb 2020 11:21:53 +0100 Subject: [PATCH 13/26] Fixes TLS error on old PowerShell versions for GitHub connections Fixes #41 --- lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 b/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 index aeabe5b..1746f6d 100644 --- a/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 +++ b/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 @@ -8,6 +8,8 @@ function Get-IcingaPowerShellModuleArchive() $ProgressPreference = "SilentlyContinue"; $Tag = 'master'; + # Fix TLS errors while connecting to GitHub with old PowerShell versions + [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11"; if ([string]::IsNullOrEmpty($DownloadUrl)) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you provide a custom repository for "{0}"?', $ModuleName)) -Default 'n').result -eq 1) { From f2a8f50154b70721894f750df02aee655e16c977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dirk=20G=C3=B6tz?= Date: Fri, 7 Feb 2020 11:41:24 +0100 Subject: [PATCH 14/26] README: Fix link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a66582..99945d3 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Please take a look at the following content to get to know the possibilities of * [Introduction](doc/01-Introduction.md) * [Installation Guide](doc/02-Installation.md) -* [Icinga Integration](doc/05-IcingaIntegration.md) +* [Icinga Integration](doc/05-Icinga-Integration.md) Developer Guide ------------ From e07f7f148246864ee78507186893ae72cb0afc93 Mon Sep 17 00:00:00 2001 From: Alexander Stoll Date: Fri, 7 Feb 2020 15:07:29 +0100 Subject: [PATCH 15/26] Add first draft unit determination tools --- lib/core/tools/Get-UnitPrefixIEC.psm1 | 21 +++++++++++++++++++++ lib/core/tools/Get-UnitPrefixSI.psm1 | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 lib/core/tools/Get-UnitPrefixIEC.psm1 create mode 100644 lib/core/tools/Get-UnitPrefixSI.psm1 diff --git a/lib/core/tools/Get-UnitPrefixIEC.psm1 b/lib/core/tools/Get-UnitPrefixIEC.psm1 new file mode 100644 index 0000000..a637e5f --- /dev/null +++ b/lib/core/tools/Get-UnitPrefixIEC.psm1 @@ -0,0 +1,21 @@ +function Get-UnitPrefixIEC() +{ + param( + [single]$Value + ); + + If ( $Value / [math]::Pow(2, 50) -ge 1 ) { + return 'PiB' + } elseif ( $Value / [math]::Pow(2, 40) -ge 1 ) { + return 'TiB' + } elseif ( $Value / [math]::Pow(2, 30) -ge 1 ) { + return 'GiB' + } elseif ( $Value / [math]::Pow(2, 20) -ge 1 ) { + return 'MiB' + } elseif ( $Value / [math]::Pow(2, 10) -ge 1 ) { + return 'KiB' + } else { + return 'B' + } +} + diff --git a/lib/core/tools/Get-UnitPrefixSI.psm1 b/lib/core/tools/Get-UnitPrefixSI.psm1 new file mode 100644 index 0000000..a10609c --- /dev/null +++ b/lib/core/tools/Get-UnitPrefixSI.psm1 @@ -0,0 +1,20 @@ +function Get-UnitPrefixSI() +{ + param( + [single]$Value + ); + + If ( $Value / [math]::Pow(10, 15) -ge 1 ) { + return 'PB' + } elseif ( $Value / [math]::Pow(10, 12) -ge 1 ) { + return 'TB' + } elseif ( $Value / [math]::Pow(10, 9) -ge 1 ) { + return 'GB' + } elseif ( $Value / [math]::Pow(10, 6) -ge 1 ) { + return 'MB' + } elseif ( $Value / [math]::Pow(10, 3) -ge 1 ) { + return 'KB' + } else { + return 'B' + } +} From c23d9cef6cec6ffc32ff4f3c10ea42d2f3693702 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Fri, 7 Feb 2020 18:17:40 +0100 Subject: [PATCH 16/26] Adds documentation for background daemons and windows service --- doc/02-Installation.md | 7 ++ .../01-Install-Service.md} | 17 +++- doc/service/02-Register-Daemons.md | 60 +++++++++++++ doc/service/10-Register-Service-Checks.md | 85 +++++++++++++++++++ 4 files changed, 168 insertions(+), 1 deletion(-) rename doc/{10-Install-Service.md => service/01-Install-Service.md} (59%) create mode 100644 doc/service/02-Register-Daemons.md create mode 100644 doc/service/10-Register-Service-Checks.md diff --git a/doc/02-Installation.md b/doc/02-Installation.md index acf6c39..459067c 100644 --- a/doc/02-Installation.md +++ b/doc/02-Installation.md @@ -21,3 +21,10 @@ Use-Icinga This command will initialise the entire module and load all available Cmdlets. Whenever you intend to use specific Cmdlets of the framework for Icinga Plugins, Testing or configuration you will require to run this command for each new PowerShell instance to initialise the framework. + +Service Installation +--- + +You can install a service which will allow you to run the PowerShell Framework as background daemon. This will add the possibility to register functions to run frequently for collecting data or execute different tasks on the system. + +To install the service you can either follow the `IcingaAgentInstallWizard` or do it [manually](service/01-Install-Service.md) diff --git a/doc/10-Install-Service.md b/doc/service/01-Install-Service.md similarity index 59% rename from doc/10-Install-Service.md rename to doc/service/01-Install-Service.md index b35441c..aebcb6e 100644 --- a/doc/10-Install-Service.md +++ b/doc/service/01-Install-Service.md @@ -1,4 +1,4 @@ -Run the PowerShell Module as Windows Service +Run the PowerShell Framework as Windows Service === Requirements @@ -8,6 +8,11 @@ As PowerShell Scripts / Modules can not be installed directly as Windows Service In order to make this work, you will require the Icinga Windows Service which can be downloaded directly from the [GitHub Repository](https://github.com/Icinga/icinga-powershell-service). +Benefits +--- + +Running the PowerShell Framework as background service will add the possibility to register certain functions which are executed depending on their configuration / coding. One example would be to frequently collect monitoring metrics from the installed plugins, allowing you to receice an average of time for the CPU load for example. + Install the Service --- @@ -36,3 +41,13 @@ Install-IcingaFrameworkService -Path 'C:\Program Files\Icinga-Framework-Service\ You can validate if the service has been installed properly by using the Get Service Cmdlet: Each enabled background daemon component is afterwards being started and executed. + +Register Functions +--- + +As the service is now installed we can start to [register daemons](02-Register-Daemons.md) which are executed within an own thread within a PowerShell session. Depending on the registered function/module, additional configuration may be required. + +Background Service Check +--- + +Once you registered the Daemon `Start-IcingaServiceCheckDaemon` with the [register functions](02-Register-Daemons.md) feature you will be able to [register service checks](10-Register-Service-Checks.md) which are frequently executed to collect metrics from plugins. diff --git a/doc/service/02-Register-Daemons.md b/doc/service/02-Register-Daemons.md new file mode 100644 index 0000000..ba86c28 --- /dev/null +++ b/doc/service/02-Register-Daemons.md @@ -0,0 +1,60 @@ +Register Background Daemons +=== + +One huge advantage of the entire PowerShell Framework for Icinga is to run the PowerShell environment as background service. Once you [installed the service](01-Install-Service.md) you can simply register functions which are executed. + +Register Daemon +--- + +To register daemons which are executed on the backkground daemon, you can use the build in command `Register-IcingaBackgroundDaemon`. An example would be to enable the frequent service check daemon which ships with this framework + +```powershell +Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon'; +``` + +The `Start-IcingaServiceCheckDaemon` is a directly integrated PowerShell function which will itself start an own thread for executing regular service checks which have been registered. + +Once you made changes, please remember to restart the PowerShell Service + +```powershell +Restart-IcingaService 'icingapowershell'; +``` + +List Enabled Daemons +--- + +To list all registered background daemons you can use a build-in command for this + +```powershell +Get-IcingaBackgroundDaemons; +``` + +Once executed you will receive a list of all daemons which are started + +```powershell +Name Value +---- ----- +Start-IcingaServiceCheckDaemon {} +``` + +Remove Daemons +--- + +Besides adding and displaying registered background daemons you can also use the unregister command to remove them + +```powershell +Unregister-IcingaBackgroundDaemon -BackgroundDaemon 'Start-IcingaServiceCheckDaemon'; +``` + +Once you restart the PowerShell service the pending changes are applied + +```powershell +Restart-IcingaService 'icingapowershell'; +``` + +Write Custom Daemons +--- + +In addition you are free to write your own extensions you can register within the framework. Every PowerShell daemon which is available within a single PowerShell session - even from different modules - can be used. + +Best practice would be to create an own custom PowerShell Module which will create a new thread and executing certain tasks. Once this module is available in your PowerShell session, you can simply register and use it. diff --git a/doc/service/10-Register-Service-Checks.md b/doc/service/10-Register-Service-Checks.md new file mode 100644 index 0000000..69bba95 --- /dev/null +++ b/doc/service/10-Register-Service-Checks.md @@ -0,0 +1,85 @@ +Register Background Service Checks +=== + +Once the PowerShell Framework is [installed as service](01-Install-Service.md) and you enabled the `Start-IcingaServiceCheckDaemon` daemon by [registering it](02-Register-Daemons.md), you are free to configure service checks which are frequently executed on a custom time period. + +Register Service Checks +--- + +Registering a service check will execute them frequently on a custom defined time. To do so you will have to register the check plugin you wish you collect metrics over time and add a execution time intervall including time indexes for which averages should be calculcated for. + +As example we want to frequently collect our `CPU load` values with an `check interval of 30 seconds` and calculate `averages for 1m, 3m, 5m, and 15m`. + +```powershell +Register-IcingaServiceCheck -CheckCommand 'Invoke-IcingaCheckCPU' -Interval 30 -TimeIndexes 1, 3, 5, 15; +``` + +Once you registered a service check, you will have to restart the PowerShell service + +```powershell +Restart-IcingaService 'icingapowershell'; +``` + +As collected metrics are written to disk as well, a restart will not flush previous data but load it again. A quick service restart will not cause missing data points. + +Once the service check is executed from the background daemon, it will add additional output to your regular check execution from Icinga 2. If we execute our `Invoke-IcingaCheckCPU` now again, we will see additional metrics based on our configuration + +```powershell +[OK] Check package "CPU Load" +| 'core_0_15'=1.17%;;;0;100 'core_0_3'=1.12%;;;0;100 'core_0_5'=1.65%;;;0;100 'core_0_1'=1.36%;;;0;100 'core_0'=0.19%;;;0;100 'core_1_1'=0.86%;;;0;100 'core_1_15'=4.59%;;;0;100 'core_1_5'=5.28%;;;0;100 'core_1_3'=1.15%;;;0;100 'core_total_5'=5.2%;;;0;100 'core_total_15'=4.32%;;;0;100 'core_total_1'=3.41%;;;0;100 'core_total_3'=3.79%;;;0;100 'core_total'=1.85%;;;0;100 +``` + +As you can see, each time index we added for the `TimeIndexes` argument is added as separat metric to our performance output. The calculation is done by all collected values over the execution period. + +List Service Checks +--- + +To list all registered service checks you can simply use + +```powershell +Show-IcingaRegisteredServiceChecks; +``` + +This will print a detailed list of all checks and their configuration + +```powershell +Service Id: 5275219864641021224811420224776891459631192206 + +Name Value +---- ----- +CheckCommand Invoke-IcingaCheckCPU +Interval 30 +Arguments +Id 5275219864641021224811420224776891459631192206 +TimeIndexes {1, 3, 5, 15} +``` + +Modify Service Checks +--- + +To modify service checks you can simply use the `Register-IcingaServiceCheck` command again with the identical check command, but overwritting interval and time indexes for example + +```powershell +Register-IcingaServiceCheck -CheckCommand 'Invoke-IcingaCheckCPU' -Interval 60 -TimeIndexes 1, 3, 5, 15, 20; +``` + +Once you modified a service check, you will have to restart the PowerShell service + +```powershell +Restart-IcingaService 'icingapowershell'; +``` + +Unregister Service Checks +--- + +If you wish to remove a service check from the daemon, you can simply unregister it with the `id` displayed on the `Show-IcingaRegisteredServiceChecks` Cmdlet + +```powershell +Unregister-IcingaServiceCheck -ServiceId 5275219864641021224811420224776891459631192206; +``` + +Once you removed a service check, you will have to restart the PowerShell service + +```powershell +Restart-IcingaService 'icingapowershell'; +``` From 64915b8fb6125c0a9ba604d822a1e734b19282ae Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Fri, 7 Feb 2020 18:19:21 +0100 Subject: [PATCH 17/26] Adds service installation doc to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4a66582..27e15a7 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Please take a look at the following content to get to know the possibilities of * [Introduction](doc/01-Introduction.md) * [Installation Guide](doc/02-Installation.md) * [Icinga Integration](doc/05-IcingaIntegration.md) +* [PowerShell as Service](doc/service/01-Install-Service.md) Developer Guide ------------ From 0bc047b6a3234dbefee4e232a27645eecf49378c Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Sun, 9 Feb 2020 14:31:34 +0100 Subject: [PATCH 18/26] Adds developer guide for writing custom daemons --- doc/developerguide/10-Custom-Daemons.md | 451 ++++++++++++++++++++++++ doc/service/02-Register-Daemons.md | 2 + 2 files changed, 453 insertions(+) create mode 100644 doc/developerguide/10-Custom-Daemons.md diff --git a/doc/developerguide/10-Custom-Daemons.md b/doc/developerguide/10-Custom-Daemons.md new file mode 100644 index 0000000..ea89c0e --- /dev/null +++ b/doc/developerguide/10-Custom-Daemons.md @@ -0,0 +1,451 @@ +Developer Guide: Custom Daemons +=== + +By [installing the PowerShell Framework as service](../service/01-Install-Service.md) you have the possibility to [register custom daemons](../service/02-Register-Daemons.md) which are executed in the background. This developer guide article will assist you in creating custom daemons. + +Creating A New Module +--- + +The best approach for creating a custom daemon is by creating an independent module which is installed in your PowerShell modules directly. This will ensure you are not overwriting your custom data with possible framework updates. + +In this guide, we will assume the name of the module is `icinga-psdaemon-agentservice`. + +At first we will have to create a new module. Navigate to the PowerShell modules folder the Framework itself is installed to. In this tutorial we will assume the location is + +```powershell +C:\Program Files\WindowsPowerShell\Modules +``` + +Now create a new folder with the name `icinga-psdaemon-agentservice` and navigate into it. + +As we require a `psm1` file which contains our code, we will create a new file with the name `icinga-psdaemon-agentservice.psm1`. This will allow the PowerShell autoloader to load the module automaticly. + +**Note:** It could be possible, depending on your [execution policies](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6), that your module is not loaded properly. If this is the case, you can try to unblock the file by opening a PowerShell and use the `Unblock-File` Cmdelet + +```powershell +Unblock-File -Path 'C:\Program Files\WindowsPowerShell\Modules\icinga-psdaemon-agentservice\icinga-psdaemon-agentservice.psm1' +``` + +Testing The Module +--- + +Once the modules files are created and unblocked, we can start testing if the autoloader is properly working and our module is detected. + +For this open the file `icinga-psdaemon-agentservice.psm1` in your prefered editor and add the following code snippet + +```powershell +function Test-MyIcingaAgentServiceCommand() +{ + Write-Host 'Module was loaded'; +} +``` + +Now open a **new** PowerShell terminal or write `powershell` into an already open PowerShell prompt and execute the command `Test-MyIcingaAgentServiceCommand`. + +If everything went properly, you should now read the output `Module was loaded` in our prompt. If not, you can try to import the module by using + +```powershell +Import-Module 'C:\Program Files\WindowsPowerShell\Modules\icinga-psdaemon-agentservice\icinga-psdaemon-agentservice.psm1'; +``` + +inside your console prompt. After that try again to execute the command `Test-MyIcingaAgentServiceCommand` and check if it works this time. If not, you might check the naming of your module to ensure `folder name` and `.psm1 file name` is identical. + +Create A New function +--- + +Once everything is working properly we can create our starting function we will later use for [registering our daemon](../service/02-Register-Daemons.md). + +For naming guidelines we will have to begin with the `Start` naming and an identifier of what are going to achieve with our daemon. In our example we will frequently check if the Icinga 2 agent service is active and running. In case it failed, we will restart the service. + +So lets get started with the function + +```powershell +function Start-IcingaAgentServiceTest() +{ + # Our code belongs here +} +``` + +Basic Daemon Architecture +--- + +A basic daemon contains of two parts. At first we require a `ScriptBlock` with our code to execute and second a `new thread` we can create with the Cmdlet `New-IcingaThreadInstance`. + +Each daemon must spawn within an own thread to ensure we are not blocking the execution of other deamons and interfere with the framework loader. + +Writing Our ScriptBlock +--- + +As we start a new thread, we will require at first a variable to contain our actual code we wish to execute inside the thread. This can be done by using `ScriptBlocks`. + +At first we will create a variable inside our `Start-IcingaAgentServiceTest` function. + +```powershell +function Start-IcingaAgentServiceTest() +{ + # Our ScriptBlock for the code being executed inside the thread + [ScriptBlock]$IcingaServiceTest = { + # Everything which will be executed inside the thread + # belongs here + }; +} +``` + +Depending on our daemon, later usage and possible sharing of data between all loaded daemons might be required. In addition we might want to spawn child threads as single tasks being executed. To do so, we will parse the frameworks `global` data to the thread. + +Our recommendation is to always do this for every daemon, as later changes might be more complicated and time consuming. + +To be able to parse an argument to your script block, we will use the `param` argument. + +```powershell +function Start-IcingaAgentServiceTest() +{ + # Our ScriptBlock for the code being executed inside the thread + [ScriptBlock]$IcingaServiceTest = { + # Allow us to parse the framework global data to this thread + param($IcingaDaemonData); + + # Everything which will be executed inside the thread + # belongs here + }; +} +``` + +Now as the basic part is finished, we will require to make our framework libraries aavailable within this thread. To do so, we will initialse the framework with the `Use-Icinga` Cmdlet, do however only import libraries and tell the framework that the wish to utilize it as `daemon`. The last part is important, as this will change the handling for writing console outputs and instead of an `exit` for certain failures the module will log them internally. + +```powershell +function Start-IcingaAgentServiceTest() +{ + # Our ScriptBlock for the code being executed inside the thread + [ScriptBlock]$IcingaServiceTest = { + # Allow us to parse the framework global data to this thread + param($IcingaDaemonData); + + # Import the framework library components and initialise it + # as daemon + Use-Icinga -LibOnly -Daemon; + }; +} +``` + +As we will parse the `global` framework data anyways, we should already make use of it. In this case, we will write the current service state of Icinga 2 into a global `synchronized` hashtable. Before we can do this, we will have to add a new hashtable to our background daemons + +```powershell +function Start-IcingaAgentServiceTest() +{ + # Our ScriptBlock for the code being executed inside the thread + [ScriptBlock]$IcingaServiceTest = { + # Allow us to parse the framework global data to this thread + param($IcingaDaemonData); + + # Import the framework library components and initialise it + # as daemon + Use-Icinga -LibOnly -Daemon; + + # Add a synchronized hashtable to the global data background + # daemon hashtable to write data to. In addition it will + # allow to share data collected from this daemon with others + $IcingaDaemonData.BackgroundDaemon.Add( + 'TestIcingaAgentService', + [hashtable]::Synchronized(@{}) + ); + # This will add another hashtable to our previous + # TestIcingaAgentService hashtable to store actual service + # information + $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add( + 'ServiceState', + [hashtable]::Synchronized(@{}) + ); + }; +} +``` + +As now our base skeleton for daemon is ready we can start to write the actual part which will execute the code to check for our Icinga Agent service state. + +Because the code is executed as separate thread, we will have to ensure it will run as long as the PowerShell service is being executed. This will be done with a simple `while` loop + +```powershell +function Start-IcingaAgentServiceTest() +{ + # Our ScriptBlock for the code being executed inside the thread + [ScriptBlock]$IcingaServiceTest = { + # Allow us to parse the framework global data to this thread + param($IcingaDaemonData); + + # Import the framework library components and initialise it + # as daemon + Use-Icinga -LibOnly -Daemon; + + # Add a synchronized hashtable to the global data background + # daemon hashtable to write data to. In addition it will + # allow to share data collected from this daemon with others + $IcingaDaemonData.BackgroundDaemon.Add( + 'TestIcingaAgentService', + [hashtable]::Synchronized(@{}) + ); + # This will add another hashtable to our previous + # TestIcingaAgentService hashtable to store actual service + # information + $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add( + 'ServiceState', + [hashtable]::Synchronized(@{}) + ); + + # Keep our code excuted as long as the PowerShell service is + # being executed. This is required to ensure we will execute + # the code frequently instead of only once + while ($TRUE) { + } + }; +} +``` + +*ALWAYS* ensure you add some sort for `sleep` at the end of the `while` loop to allow your CPU some breaks. If you do not do this, you might suffer from high CPU loads. The `sleep duration` interval can depend either on a simple CPU cycle break or by telling the daemon to execute tasks only in certain intervalls. In our case we wish to execute the daemon every `5 seconds`. + +```powershell +function Start-IcingaAgentServiceTest() +{ + # Our ScriptBlock for the code being executed inside the thread + [ScriptBlock]$IcingaServiceTest = { + # Allow us to parse the framework global data to this thread + param($IcingaDaemonData); + + # Import the framework library components and initialise it + # as daemon + Use-Icinga -LibOnly -Daemon; + + # Add a synchronized hashtable to the global data background + # daemon hashtable to write data to. In addition it will + # allow to share data collected from this daemon with others + $IcingaDaemonData.BackgroundDaemon.Add( + 'TestIcingaAgentService', + [hashtable]::Synchronized(@{}) + ); + # This will add another hashtable to our previous + # TestIcingaAgentService hashtable to store actual service + # information + $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add( + 'ServiceState', + [hashtable]::Synchronized(@{}) + ); + + # Keep our code excuted as long as the PowerShell service is + # being executed. This is required to ensure we will execute + # the code frequently instead of only once + while ($TRUE) { + # ALWAYS add some sort of sleep at the end. Either to + # break the CPU cycle and give it some break or to + # ensure daemon tasks are executed on a certain interval + Start-Sleep -Seconds 5; + } + }; +} +``` + +This is basicly the foundation of every single daemon you will write. Now we will add the actual task our daemon will execute while it is running. As mentioned before, we will test if our Icinga 2 Agent service is running and restart it if it is stopped. To keep track of the current status and possible errors during restart, we will add additional `synchronized` hashtables to store the `value` of the current service status and possible `restart_error` counts. To count the `restart_error` we will have to initiliase a single variable we name `$RestartErrors` before we enter our `while` loop. + +```powershell +function Start-IcingaAgentServiceTest() +{ + # Our ScriptBlock for the code being executed inside the thread + [ScriptBlock]$IcingaServiceTest = { + # Allow us to parse the framework global data to this thread + param($IcingaDaemonData); + + # Import the framework library components and initialise it + # as daemon + Use-Icinga -LibOnly -Daemon; + + # Add a synchronized hashtable to the global data background + # daemon hashtable to write data to. In addition it will + # allow to share data collected from this daemon with others + $IcingaDaemonData.BackgroundDaemon.Add( + 'TestIcingaAgentService', + [hashtable]::Synchronized(@{}) + ); + # This will add another hashtable to our previous + # TestIcingaAgentService hashtable to store actual service + # information + $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add( + 'ServiceState', + [hashtable]::Synchronized(@{}) + ); + + # Initialise our error counter variable + [int]$RestartErrors = 0; + + # Keep our code excuted as long as the PowerShell service is + # being executed. This is required to ensure we will execute + # the code frequently instead of only once + while ($TRUE) { + # Get the current service information. If the service is + # not installed, continue silently to return $null + $ServiceState = Get-Service 'icinga2' -ErrorAction SilentlyContinue; + + # Only execute our code if the Icinga Agent service is + # installed + if ($null -ne $ServiceState) { + # Add the current service state to our hashtable. + Add-IcingaHashtableItem ` + -Hashtable $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState ` + -Key 'value' ` + -Value $ServiceState.Status ` + -Override | Out-Null; + + # Restart the service if it is not running + if ($ServiceState.Status -ne 'Running') { + try { + # Try to restart the service + Restart-Service 'icinga2'; + } catch { + # Add an error counter in case we failed + $RestartErrors += 1; + Add-IcingaHashtableItem ` + -Hashtable $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState ` + -Key 'restart_error' ` + -Value $RestartErrors ` + -Override | Out-Null; + } + } + } + # ALWAYS add some sort of sleep at the end. Either to + # break the CPU cycle and give it some break or to + # ensure daemon tasks are executed on a certain interval + Start-Sleep -Seconds 5; + } + }; +} +``` + +Calling Our ScriptBlock +--- + +Once our SciptBlock is completed we only require to call it once our daemon is registered. Do to so, we will use the Cmdlet `New-IcingaThreadInstance`. + +As arguments we will have to add a unique `name` to use for this thread as well as a `thread pool` we will add add the thread to. In our case we will use the Frameworks default pool. Last but not least we require to parse our `ScriptBlock`, possible `Arguments` and tell the thread to `Start` right after being created. For the arguments we will parse the frameworks `global` `IcingaDaemonData` we also use inside our ScriptBlock to store data in. + +The function will be a added at the very bottom of our `Start-IcingaAgentServiceTest` function + +```powershell +function Start-IcingaAgentServiceTest() +{ + # Our ScriptBlock for the code being executed inside the thread + [ScriptBlock]$IcingaServiceTest = { + # Allow us to parse the framework global data to this thread + param($IcingaDaemonData); + + # Import the framework library components and initialise it + # as daemon + Use-Icinga -LibOnly -Daemon; + + # Add a synchronized hashtable to the global data background + # daemon hashtable to write data to. In addition it will + # allow to share data collected from this daemon with others + $IcingaDaemonData.BackgroundDaemon.Add( + 'TestIcingaAgentService', + [hashtable]::Synchronized(@{}) + ); + # This will add another hashtable to our previous + # TestIcingaAgentService hashtable to store actual service + # information + $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add( + 'ServiceState', + [hashtable]::Synchronized(@{}) + ); + + # Initialise our error counter variable + [int]$RestartErrors = 0; + + # Keep our code excuted as long as the PowerShell service is + # being executed. This is required to ensure we will execute + # the code frequently instead of only once + while ($TRUE) { + # Get the current service information. If the service is + # not installed, continue silently to return $null + $ServiceState = Get-Service 'icinga2' -ErrorAction SilentlyContinue; + + # Only execute our code if the Icinga Agent service is + # installed + if ($null -ne $ServiceState) { + # Add the current service state to our hashtable. + Add-IcingaHashtableItem ` + -Hashtable $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState ` + -Key 'value' ` + -Value $ServiceState.Status ` + -Override | Out-Null; + + # Restart the service if it is not running + if ($ServiceState.Status -ne 'Running') { + try { + # Try to restart the service + Restart-Service 'icinga2'; + } catch { + # Add an error counter in case we failed + $RestartErrors += 1; + Add-IcingaHashtableItem ` + -Hashtable $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState ` + -Key 'restart_error' ` + -Value $RestartErrors ` + -Override | Out-Null; + } + } + } + # ALWAYS add some sort of sleep at the end. Either to + # break the CPU cycle and give it some break or to + # ensure daemon tasks are executed on a certain interval + Start-Sleep -Seconds 5; + } + }; + + # Now create a new thread for our ScriptBlock, assign a name and + # parse all required arguments to it. Last but not least start it + # directly + New-IcingaThreadInstance ` + -Name "Icinga_PowerShell_IcingaAgent_StateCheck" ` + -ThreadPool $global:IcingaDaemonData.IcingaThreadPool.BackgroundPool ` + -ScriptBlock $IcingaServiceTest ` + -Arguments @( $global:IcingaDaemonData ) ` + -Start; +} +``` + +Register Our Daemon +--- + +Now as our daemon is ready we can simply [register it](../service/02-Register-Daemons.md) by using the Framework commands + +```powershell +Register-IcingaBackgroundDaemon -Command 'Start-IcingaAgentServiceTest'; +``` + +Once registered, you will have to restart the PowerShell service itselfs to apply the changes + +```powershell +Restart-IcingaService 'icingapowershell'; +``` + +Thats it! Now the daemon is loaded with every start, checking for the Agent state and restart it if it is not running. + +**Note:** In order to restart the Icinga Agent service, the user the PowerShell service is running with requires these kind of priviliges. Otherwise it will throw an error and the error counter will increase + +Developer Console +--- + +During development you might want to test the current implementation and check if everything is working as intended. To do so, you require to open a PowerShell terminal as `administrator`. We would recommend to `stop` the PowerShell service in this case to prevent possible daemons writing files to the system and overwriting each others. + +Once the service is stopped and your `administrative PowerShell` is open, we will have to initialise the Framework and start the background daemon component + +```powershell +Use-Icinga; +Start-IcingaPowerShellDaemon; +``` + +Once done you will receive back your prompt, however all registered background daemons are running. To access the collected data from daemons, you can print the content of the `global` framework data. If you wish to check if your daemon was loaded properly and data is actually written, we can access our created hashtable and get the current service state of it + +```powershell +$global:IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState['value']; +``` + +In case your Icinga Agent service is intalled and your daemon is running properly, this should print the current state of the service. + +Of course for more complex daemons you are able to manipulate data directly or add more detailed debug output. diff --git a/doc/service/02-Register-Daemons.md b/doc/service/02-Register-Daemons.md index ba86c28..8936bc3 100644 --- a/doc/service/02-Register-Daemons.md +++ b/doc/service/02-Register-Daemons.md @@ -58,3 +58,5 @@ Write Custom Daemons In addition you are free to write your own extensions you can register within the framework. Every PowerShell daemon which is available within a single PowerShell session - even from different modules - can be used. Best practice would be to create an own custom PowerShell Module which will create a new thread and executing certain tasks. Once this module is available in your PowerShell session, you can simply register and use it. + +For a detailed guide you should check out the [daemon developer guide](../developerguide/10-Custom-Daemons.md). From 5799fe69884527252d11ba180febc4ab91be8fbc Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Sun, 9 Feb 2020 14:32:43 +0100 Subject: [PATCH 19/26] Add index for custom daemon developer guide --- doc/04-Developer-Guide.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/04-Developer-Guide.md b/doc/04-Developer-Guide.md index 09a08f8..1338a7d 100644 --- a/doc/04-Developer-Guide.md +++ b/doc/04-Developer-Guide.md @@ -12,3 +12,4 @@ A detailed overview of functions can be found below * [New-IcingaCheck](developerguide/01-New-IcingaCheck.md) * [New-IcingaCheckPackage](developerguide/02-New-IcingaCheckPackage.md) +* [Custom Daemons](developerguide/10-Custom-Daemons.md) From 401ac2ed53f8643294ac6839c271323c9321b937 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 13 Feb 2020 10:12:57 +0100 Subject: [PATCH 20/26] Fixes tail command with read limit Fixes #43 --- lib/core/icingaagent/readers/Read-IcingaAgentDebugLogFile.psm1 | 2 +- lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/icingaagent/readers/Read-IcingaAgentDebugLogFile.psm1 b/lib/core/icingaagent/readers/Read-IcingaAgentDebugLogFile.psm1 index 311ed75..992fb43 100644 --- a/lib/core/icingaagent/readers/Read-IcingaAgentDebugLogFile.psm1 +++ b/lib/core/icingaagent/readers/Read-IcingaAgentDebugLogFile.psm1 @@ -6,5 +6,5 @@ function Read-IcingaAgentDebugLogFile() return; } - Get-Content -Path $Logfile -Wait; + Get-Content -Path $Logfile -Tail 20 -Wait; } diff --git a/lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1 b/lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1 index f80a059..8ce56bf 100644 --- a/lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1 +++ b/lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1 @@ -6,5 +6,5 @@ function Read-IcingaAgentLogFile() return; } - Get-Content -Path $Logfile -Wait; + Get-Content -Path $Logfile -Tail 20 -Wait; } From 714827bc0ae046855a5f48e698e007fd0f414f35 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 13 Feb 2020 10:19:23 +0100 Subject: [PATCH 21/26] Adds script termination in case Agent is not installed for Agent Binary fetching --- lib/core/icingaagent/getters/Get-IcingaAgentBinary.psm1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/core/icingaagent/getters/Get-IcingaAgentBinary.psm1 b/lib/core/icingaagent/getters/Get-IcingaAgentBinary.psm1 index 4c4853f..f1fb417 100644 --- a/lib/core/icingaagent/getters/Get-IcingaAgentBinary.psm1 +++ b/lib/core/icingaagent/getters/Get-IcingaAgentBinary.psm1 @@ -1,6 +1,10 @@ function Get-IcingaAgentBinary() { $IcingaRootDir = Get-IcingaAgentRootDirectory; + if ([string]::IsNullOrEmpty($IcingaRootDir)) { + throw 'The Icinga Agent seems not to be installed'; + } + $IcingaBinary = (Join-Path -Path $IcingaRootDir -ChildPath '\sbin\icinga2.exe'); if ((Test-Path $IcingaBinary) -eq $FALSE) { From d0dcc0c1287e87167f46a1ed93991d1322056870 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 13 Feb 2020 12:32:56 +0100 Subject: [PATCH 22/26] Adds Icinga Agent object list wrapper implementation Fixes #44 --- .../finders/Find-IcingaAgentObjects.psm1 | 40 +++++++++++++++++++ .../getters/Get-IcingaAgentObjectList.psm1 | 7 ++++ .../writers/Write-IcingaAgentObjectList.psm1 | 14 +++++++ 3 files changed, 61 insertions(+) create mode 100644 lib/core/icingaagent/finders/Find-IcingaAgentObjects.psm1 create mode 100644 lib/core/icingaagent/getters/Get-IcingaAgentObjectList.psm1 create mode 100644 lib/core/icingaagent/writers/Write-IcingaAgentObjectList.psm1 diff --git a/lib/core/icingaagent/finders/Find-IcingaAgentObjects.psm1 b/lib/core/icingaagent/finders/Find-IcingaAgentObjects.psm1 new file mode 100644 index 0000000..8b74c7b --- /dev/null +++ b/lib/core/icingaagent/finders/Find-IcingaAgentObjects.psm1 @@ -0,0 +1,40 @@ +function Find-IcingaAgentObjects() +{ + param( + $Find = @(), + $OutFile = $null + ); + + if ($Find.Length -eq 0) { + throw 'Please specify content you want to look for'; + } + + [array]$ObjectList = (Get-IcingaAgentObjectList).Split("`r`n"); + [int]$lineIndex = 0; + [array]$Result = @(); + + foreach ($line in $ObjectList) { + if ([string]::IsNullOrEmpty($line)) { + continue; + } + + foreach ($entry in $Find) { + if ($line -like $entry) { + [string]$ResultLine = [string]::Format( + 'Line #{0} => "{1}"', + $lineIndex, + $line + ); + $Result += $ResultLine; + } + } + + $lineIndex += 1; + } + + if ([string]::IsNullOrEmpty($OutFile)) { + Write-Output $Result; + } else { + Set-Content -Path $OutFile -Value $Result; + } +} diff --git a/lib/core/icingaagent/getters/Get-IcingaAgentObjectList.psm1 b/lib/core/icingaagent/getters/Get-IcingaAgentObjectList.psm1 new file mode 100644 index 0000000..f79299d --- /dev/null +++ b/lib/core/icingaagent/getters/Get-IcingaAgentObjectList.psm1 @@ -0,0 +1,7 @@ +function Get-IcingaAgentObjectList() +{ + $Binary = Get-IcingaAgentBinary; + $ObjectList = Start-IcingaProcess -Executable $Binary -Arguments 'object list'; + + return $ObjectList.Message; +} diff --git a/lib/core/icingaagent/writers/Write-IcingaAgentObjectList.psm1 b/lib/core/icingaagent/writers/Write-IcingaAgentObjectList.psm1 new file mode 100644 index 0000000..ea2615b --- /dev/null +++ b/lib/core/icingaagent/writers/Write-IcingaAgentObjectList.psm1 @@ -0,0 +1,14 @@ +function Write-IcingaAgentObjectList() +{ + param( + [string]$Path + ); + + if ([string]::IsNullOrEmpty($Path)) { + throw 'Please specify a path to write the Icinga objects to'; + } + + $ObjectList = Get-IcingaAgentObjectList; + + Set-Content -Path $Path -Value $ObjectList; +} From cfd28f30e2f55c6d54a994776d7660e05589763a Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 13 Feb 2020 14:16:42 +0100 Subject: [PATCH 23/26] Fixes broken datalist data type configuration on Basket generation Fixes #45 --- lib/core/tools/Get-IcingaCheckCommandConfig.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 b/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 index 4f63c2d..8e52e0f 100644 --- a/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 +++ b/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 @@ -250,7 +250,7 @@ function Get-IcingaCheckCommandConfig() $Basket.Datafield[[string]$FieldID].Add( 'settings', @{ 'datalist' = $DataListName; - 'datatype' = 'string'; + 'data_type' = 'string'; 'behavior' = 'strict'; } ); From 3e86748dd0f5f41f065ea493a015703d265b7790 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 13 Feb 2020 16:28:06 +0100 Subject: [PATCH 24/26] Fixes plugin installation if wizard arguments are set Fixes #46 --- lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 b/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 index 9c8e3ad..1984232 100644 --- a/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 +++ b/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 @@ -424,6 +424,10 @@ function Start-IcingaAgentInstallWizard() } else { $InstallerArguments += "-InstallFrameworkPlugins 0"; } + } elseif ($InstallFrameworkPlugins -eq 1) { + $result = Install-IcingaFrameworkPlugins -PluginsUrl $PluginsUrl; + $InstallerArguments += "-InstallFrameworkPlugins 1"; + $InstallerArguments += "-PluginsUrl '$PluginsUrl'"; } if ($null -eq $InstallFrameworkService) { From 9e52d16a3d884894aafdc8e888be49fb7dbc9b16 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Tue, 18 Feb 2020 12:27:47 +0100 Subject: [PATCH 25/26] Adds service exclude and service exit code data fetching --- lib/core/tools/Get-IcingaServices.psm1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/core/tools/Get-IcingaServices.psm1 b/lib/core/tools/Get-IcingaServices.psm1 index a6e5a0f..4523f9e 100644 --- a/lib/core/tools/Get-IcingaServices.psm1 +++ b/lib/core/tools/Get-IcingaServices.psm1 @@ -1,7 +1,8 @@ function Get-IcingaServices() { param ( - [array]$Service + [array]$Service, + [array]$Exclude = @() ); $ServiceInformation = Get-Service -Name $Service -ErrorAction SilentlyContinue; @@ -25,6 +26,10 @@ function Get-IcingaServices() [array]$DependingServices = $null; [string]$ServiceUser = ''; + if ($Exclude -contains $service.ServiceName) { + continue; + } + foreach ($wmiService in $ServiceWmiInfo) { if ($wmiService.Name -eq $service.ServiceName) { $ServiceUser = $wmiService.StartName; @@ -77,6 +82,7 @@ function Get-IcingaServices() 'value' = $service.StartType; }; 'ServiceUser' = $ServiceUser; + 'ExitCode' = [int]$service.ExitCode; } } ); From 96314bfe8cb0a39826aa492aac0a9bbc14b2378d Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Tue, 18 Feb 2020 13:36:46 +0100 Subject: [PATCH 26/26] Fixes service exit code fetching --- lib/core/tools/Get-IcingaServices.psm1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/core/tools/Get-IcingaServices.psm1 b/lib/core/tools/Get-IcingaServices.psm1 index 4523f9e..4f744fa 100644 --- a/lib/core/tools/Get-IcingaServices.psm1 +++ b/lib/core/tools/Get-IcingaServices.psm1 @@ -24,6 +24,7 @@ function Get-IcingaServices() [array]$DependentServices = $null; [array]$DependingServices = $null; + $ServiceExitCode = 0; [string]$ServiceUser = ''; if ($Exclude -contains $service.ServiceName) { @@ -32,7 +33,8 @@ function Get-IcingaServices() foreach ($wmiService in $ServiceWmiInfo) { if ($wmiService.Name -eq $service.ServiceName) { - $ServiceUser = $wmiService.StartName; + $ServiceUser = $wmiService.StartName; + $ServiceExitCode = $wmiService.ExitCode; break; } } @@ -82,7 +84,7 @@ function Get-IcingaServices() 'value' = $service.StartType; }; 'ServiceUser' = $ServiceUser; - 'ExitCode' = [int]$service.ExitCode; + 'ExitCode' = $ServiceExitCode; } } );