mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Fixes check command generator for aliases
This commit is contained in:
parent
97ebe4613d
commit
6cb7743954
2 changed files with 15 additions and 11 deletions
|
|
@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
||||||
* [#376](https://github.com/Icinga/icinga-powershell-framework/pull/376) Fixes IMC error handling on invalid JSON for installation command/file
|
* [#376](https://github.com/Icinga/icinga-powershell-framework/pull/376) Fixes IMC error handling on invalid JSON for installation command/file
|
||||||
* [#377](https://github.com/Icinga/icinga-powershell-framework/issues/377) Fixes overhead for testing of modules being loaded, which returned invalid path values and wrong exceptions, which was unnecessary in first place
|
* [#377](https://github.com/Icinga/icinga-powershell-framework/issues/377) Fixes overhead for testing of modules being loaded, which returned invalid path values and wrong exceptions, which was unnecessary in first place
|
||||||
* [#381](https://github.com/Icinga/icinga-powershell-framework/issues/381) Fixes Repository Hash generator for new repositories, which always returned the same hash regardless of the files inside
|
* [#381](https://github.com/Icinga/icinga-powershell-framework/issues/381) Fixes Repository Hash generator for new repositories, which always returned the same hash regardless of the files inside
|
||||||
|
* [#386](https://github.com/Icinga/icinga-powershell-framework/pull/386) Fixes check command config generator for Icinga Director baskets/Icinga 2 conf files, in case we are using a check command with an alias as reference to a new name of a check command
|
||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -168,11 +168,13 @@ function Get-IcingaCheckCommandConfig()
|
||||||
# Loop through ${CheckName}, to get information on every command specified/all commands.
|
# Loop through ${CheckName}, to get information on every command specified/all commands.
|
||||||
foreach ($check in $CheckName) {
|
foreach ($check in $CheckName) {
|
||||||
|
|
||||||
|
[string]$check = [string]$check;
|
||||||
|
|
||||||
# Get necessary syntax-information and more through cmdlet "Get-Help"
|
# Get necessary syntax-information and more through cmdlet "Get-Help"
|
||||||
$Data = (Get-Help $check);
|
$Data = (Get-Help $check);
|
||||||
$ParameterList = (Get-Command -Name $check).Parameters;
|
$ParameterList = (Get-Command -Name $check).Parameters;
|
||||||
$CheckParamList = @( $ThresholdIntervalArg );
|
$CheckParamList = @( $ThresholdIntervalArg );
|
||||||
$PluginNameSpace = $Data.Name.Replace('Invoke-', '');
|
$PluginNameSpace = $check.Replace('Invoke-', '');
|
||||||
|
|
||||||
foreach ($entry in $Data.parameters.parameter) {
|
foreach ($entry in $Data.parameters.parameter) {
|
||||||
foreach ($BlackListArg in $BlacklistedArguments) {
|
foreach ($BlackListArg in $BlacklistedArguments) {
|
||||||
|
|
@ -195,17 +197,17 @@ function Get-IcingaCheckCommandConfig()
|
||||||
|
|
||||||
# Add command Structure
|
# Add command Structure
|
||||||
$Basket.Command.Add(
|
$Basket.Command.Add(
|
||||||
$Data.Name, @{
|
$check, @{
|
||||||
'arguments' = @{
|
'arguments' = @{
|
||||||
# Set the Command handling for every check command
|
# Set the Command handling for every check command
|
||||||
'-C' = @{
|
'-C' = @{
|
||||||
'value' = [string]::Format('try {{ Use-Icinga -Minimal; }} catch {{ Write-Output {1}The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details{1}; Write-Output {1}Error:{1} $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable {1}icinga-powershell-*{1} )`r`n{1}Module-Path:{1}`r`n$$($$Env:PSModulePath); exit 3; }}; Exit-IcingaExecutePlugin -Command {1}{0}{1} ', $Data.Name, "'");
|
'value' = [string]::Format('try {{ Use-Icinga -Minimal; }} catch {{ Write-Output {1}The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details{1}; Write-Output {1}Error:{1} $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable {1}icinga-powershell-*{1} )`r`n{1}Module-Path:{1}`r`n$$($$Env:PSModulePath); exit 3; }}; Exit-IcingaExecutePlugin -Command {1}{0}{1} ', $check, "'");
|
||||||
'order' = '0';
|
'order' = '0';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
'fields' = @();
|
'fields' = @();
|
||||||
'imports' = @( 'PowerShell Base' );
|
'imports' = @( 'PowerShell Base' );
|
||||||
'object_name' = $Data.Name;
|
'object_name' = $check;
|
||||||
'object_type' = 'object';
|
'object_type' = 'object';
|
||||||
'vars' = @{ };
|
'vars' = @{ };
|
||||||
}
|
}
|
||||||
|
|
@ -238,7 +240,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
|
|
||||||
# Add arguments to a given command
|
# Add arguments to a given command
|
||||||
if ($parameter.type.name -eq 'SwitchParameter') {
|
if ($parameter.type.name -eq 'SwitchParameter') {
|
||||||
$Basket.Command[$Data.Name].arguments.Add(
|
$Basket.Command[$check].arguments.Add(
|
||||||
[string]::Format('-{0}', $parameter.Name), @{
|
[string]::Format('-{0}', $parameter.Name), @{
|
||||||
'set_if' = $IcingaCustomVariable;
|
'set_if' = $IcingaCustomVariable;
|
||||||
'set_if_format' = 'string';
|
'set_if_format' = 'string';
|
||||||
|
|
@ -246,11 +248,11 @@ function Get-IcingaCheckCommandConfig()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$Basket.Command[$Data.Name].vars.Add($IcingaCustomVariable.Replace('$', ''), $FALSE);
|
$Basket.Command[$check].vars.Add($IcingaCustomVariable.Replace('$', ''), $FALSE);
|
||||||
|
|
||||||
} elseif ($parameter.type.name -eq 'Array') {
|
} elseif ($parameter.type.name -eq 'Array') {
|
||||||
# Conditional whether type of parameter is array
|
# Conditional whether type of parameter is array
|
||||||
$Basket.Command[$Data.Name].arguments.Add(
|
$Basket.Command[$check].arguments.Add(
|
||||||
[string]::Format('-{0}', $parameter.Name), @{
|
[string]::Format('-{0}', $parameter.Name), @{
|
||||||
'value' = @{
|
'value' = @{
|
||||||
'type' = 'Function';
|
'type' = 'Function';
|
||||||
|
|
@ -268,7 +270,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
);
|
);
|
||||||
} elseif ($parameter.type.name -eq 'SecureString') {
|
} elseif ($parameter.type.name -eq 'SecureString') {
|
||||||
# Convert out input string as SecureString
|
# Convert out input string as SecureString
|
||||||
$Basket.Command[$Data.Name].arguments.Add(
|
$Basket.Command[$check].arguments.Add(
|
||||||
[string]::Format('-{0}', $parameter.Name), @{
|
[string]::Format('-{0}', $parameter.Name), @{
|
||||||
'value' = (
|
'value' = (
|
||||||
[string]::Format(
|
[string]::Format(
|
||||||
|
|
@ -281,7 +283,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
# Default to Object
|
# Default to Object
|
||||||
$Basket.Command[$Data.Name].arguments.Add(
|
$Basket.Command[$check].arguments.Add(
|
||||||
[string]::Format('-{0}', $parameter.Name), @{
|
[string]::Format('-{0}', $parameter.Name), @{
|
||||||
'value' = $IcingaCustomVariable;
|
'value' = $IcingaCustomVariable;
|
||||||
'order' = $Order;
|
'order' = $Order;
|
||||||
|
|
@ -388,9 +390,10 @@ function Get-IcingaCheckCommandConfig()
|
||||||
|
|
||||||
foreach ($check in $CheckName) {
|
foreach ($check in $CheckName) {
|
||||||
[int]$FieldNumeration = 0;
|
[int]$FieldNumeration = 0;
|
||||||
|
[string]$check = [string]$check;
|
||||||
|
|
||||||
$Data = (Get-Help $check)
|
$Data = (Get-Help $check)
|
||||||
$PluginNameSpace = $Data.Name.Replace('Invoke-', '');
|
$PluginNameSpace = $check.Replace('Invoke-', '');
|
||||||
$CheckParamList = @( $ThresholdIntervalArg );
|
$CheckParamList = @( $ThresholdIntervalArg );
|
||||||
|
|
||||||
foreach ($entry in $Data.parameters.parameter) {
|
foreach ($entry in $Data.parameters.parameter) {
|
||||||
|
|
@ -409,7 +412,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
foreach ($DataFieldID in $Basket.Datafield.Keys) {
|
foreach ($DataFieldID in $Basket.Datafield.Keys) {
|
||||||
[string]$varname = $Basket.Datafield[$DataFieldID].varname;
|
[string]$varname = $Basket.Datafield[$DataFieldID].varname;
|
||||||
if ([string]$varname -eq [string]$IcingaCustomVariable) {
|
if ([string]$varname -eq [string]$IcingaCustomVariable) {
|
||||||
$Basket.Command[$Data.Name].fields += @{
|
$Basket.Command[$check].fields += @{
|
||||||
'datafield_id' = [int]$DataFieldID;
|
'datafield_id' = [int]$DataFieldID;
|
||||||
'is_required' = $Required;
|
'is_required' = $Required;
|
||||||
'var_filter' = $NULL;
|
'var_filter' = $NULL;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue