From ba131e7bef4b0047304954f920a880a38e46ac18 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Fri, 20 Nov 2020 15:08:08 +0100 Subject: [PATCH] Adds error on config generator for 64 digit args --- doc/31-Changelog.md | 1 + doc/icingaintegration/01-Director-Baskets.md | 2 +- lib/core/tools/Get-IcingaCheckCommandConfig.psm1 | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index 22c3dec..675b57e 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -23,6 +23,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#142](https://github.com/Icinga/icinga-powershell-framework/pull/142) **Experimental:** Adds feature to cache the Framework code into a single file to speed up the entire loading process, mitigating the impact on performance on systems with few CPU cores. You enable disables this feature by using `Enable-IcingaFrameworkCodeCache` and `Disable-IcingaFrameworkCodeCache`. Updating the cache is done with `Write-IcingaFrameworkCodeCache` * [#149](https://github.com/Icinga/icinga-powershell-framework/pull/149) Adds support to add Wmi permissions for a specific user and namespace with `Add-IcingaWmiPermissions`. In addition you can remove users from Wmi namespaces by using `Remove-IcingaWmiPermissions` * [#155](https://github.com/Icinga/icinga-powershell-framework/pull/155) Adds support to write all objects collected by `Get-IcingaWindowsInformation` into the Windows EventLog in case the debug output for the Icinga PowerShell Framework is enabled. +* [#162](https://github.com/Icinga/icinga-powershell-framework/pull/162) Adds feature to test the length of plugin custom variables during config generation and throws error in case the total length is bigger than 64 digits, as imports into the Icinga Director by using baskets is not possible otherwise ### Bugfixes diff --git a/doc/icingaintegration/01-Director-Baskets.md b/doc/icingaintegration/01-Director-Baskets.md index 0590f47..296be33 100644 --- a/doc/icingaintegration/01-Director-Baskets.md +++ b/doc/icingaintegration/01-Director-Baskets.md @@ -31,7 +31,7 @@ Get-IcingaCheckCommandConfig -CheckName Invoke-IcingaCheckBiosSerial, Invoke-Ici Last but not least you can output the JSON-Basket directly into a file. To do this, simply use the `OutDirectory` argument. You only require to specify a directory here, as the file including a timestamp is generated by the Cmdlet itself ```powershell -Get-IcingaCheckCommandConfig -OutDirectory 'C:\Users\myuser\Documents\ +Get-IcingaCheckCommandConfig -OutDirectory 'C:\Users\myuser\Documents\' ``` Once the file is exported, you can navigate to your Icinga Director Basket menu and import the generated file. Afterwards all specified Check-Commands are available and ready to use diff --git a/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 b/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 index a18c80d..5148388 100644 --- a/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 +++ b/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 @@ -140,6 +140,11 @@ function Get-IcingaCheckCommandConfig() $IcingaCustomVariable = [string]::Format('${0}_{1}_{2}$', $PluginNameSpace, (Get-Culture).TextInfo.ToTitleCase($parameter.type.name), $parameter.Name); + if ($IcingaCustomVariable.Length -gt 66) { + Write-IcingaConsoleError 'The argument "{0}" for the plugin "{1}" is too long. The maximum size of generated custom variables is 64 digits. Current argument size: "{2}", Name: "{3}"' -Objects $parameter.Name, $check, ($IcingaCustomVariable.Length - 2), $IcingaCustomVariable.Replace('$', ''); + return; + } + # Todo: Should we improve this? Actually the handling would be identical, we just need to assign # the proper field for this if ($IcingaCustomVariable -like '*_Int32_Verbose$' -Or $IcingaCustomVariable -like '*_Int_Verbose$' -Or $IcingaCustomVariable -like '*_Object_Verbose$') {