mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Improved Check-Command Config generation
* Switch arguments will now use boolean data types in Director * Fixed an issue for Check Commands with integrated help, as arguments were not rendered properly * Fixed an issue on datafield ID lookup and assigning * Fixed an issue with assigning default values
This commit is contained in:
parent
516b915472
commit
fae69a3e69
1 changed files with 45 additions and 122 deletions
|
|
@ -82,34 +82,6 @@ function Get-IcingaCheckCommandConfig()
|
||||||
$Basket.Add('DataList', @{});
|
$Basket.Add('DataList', @{});
|
||||||
$Basket.Add('Command', @{});
|
$Basket.Add('Command', @{});
|
||||||
|
|
||||||
|
|
||||||
# "NoPerfData" gets added to all checks build and exported no matter what, so we add it from the start
|
|
||||||
if ($Basket.DataList.ContainsKey('PowerShell NoPerfData') -eq $FALSE) {
|
|
||||||
|
|
||||||
# DataList Content for NoPerfData
|
|
||||||
$Basket.DataList.Add(
|
|
||||||
'PowerShell NoPerfData', @{
|
|
||||||
'list_name' = 'PowerShell NoPerfData';
|
|
||||||
'owner' = $env:username;
|
|
||||||
'originalId' = '1';
|
|
||||||
'entries' = @(
|
|
||||||
@{
|
|
||||||
'entry_name' = '0';
|
|
||||||
'entry_value' = "yes";
|
|
||||||
'format' = 'string';
|
|
||||||
'allowed_roles' = $NULL;
|
|
||||||
},
|
|
||||||
@{
|
|
||||||
'entry_name' = '1';
|
|
||||||
'entry_value' = "no";
|
|
||||||
'format' = 'string';
|
|
||||||
'allowed_roles' = $NULL;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
# "Verbose" gets added to all Checks build and exported no matter what, so we add it from the start
|
# "Verbose" gets added to all Checks build and exported no matter what, so we add it from the start
|
||||||
if ($Basket.DataList.ContainsKey('PowerShell Verbose') -eq $FALSE) {
|
if ($Basket.DataList.ContainsKey('PowerShell Verbose') -eq $FALSE) {
|
||||||
$Basket.DataList.Add(
|
$Basket.DataList.Add(
|
||||||
|
|
@ -150,28 +122,26 @@ 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) {
|
||||||
|
|
||||||
[int]$FieldNumeration = 0;
|
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
||||||
# Add command Structure
|
# Add command Structure
|
||||||
$Basket.Command.Add(
|
$Basket.Command.Add(
|
||||||
$Data.Syntax.syntaxItem.Name, @{
|
$Data.Name, @{
|
||||||
'arguments'= @{
|
'arguments'= @{
|
||||||
# Gets set for every command as default
|
# Gets set for every command as default
|
||||||
'-C' = @{
|
'-C' = @{
|
||||||
'value' = [string]::Format('Use-Icinga; {0}', $Data.Syntax.syntaxItem.Name);
|
'value' = [string]::Format('Use-Icinga; {0}', $Data.Name);
|
||||||
'order' = '0';
|
'order' = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'command' = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe";
|
'command' = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe";
|
||||||
'disabled' = $FALSE;
|
'disabled' = $FALSE;
|
||||||
'fields' = @{};
|
'fields' = @();
|
||||||
'imports' = @();
|
'imports' = @();
|
||||||
'is_string' = $NULL;
|
'is_string' = $NULL;
|
||||||
'methods_execute' = 'PluginCheck';
|
'methods_execute' = 'PluginCheck';
|
||||||
'object_name' = $Data.Syntax.syntaxItem.Name;
|
'object_name' = $Data.Name;
|
||||||
'object_type' = 'object';
|
'object_type' = 'object';
|
||||||
'timeout' = '180';
|
'timeout' = '180';
|
||||||
'vars' = @{};
|
'vars' = @{};
|
||||||
|
|
@ -180,7 +150,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
);
|
);
|
||||||
|
|
||||||
# Loop through parameters of a given command
|
# Loop through parameters of a given command
|
||||||
foreach ($parameter in $Data.Syntax.syntaxItem.parameter) {
|
foreach ($parameter in $Data.parameters.parameter) {
|
||||||
|
|
||||||
# Filter for Parameter 'core', because its set by default
|
# Filter for Parameter 'core', because its set by default
|
||||||
if ($parameter.name -ne 'core') {
|
if ($parameter.name -ne 'core') {
|
||||||
|
|
@ -196,7 +166,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
|
|
||||||
# Add arguments to a given command
|
# Add arguments to a given command
|
||||||
if ($parameter.type.name -eq 'switch') {
|
if ($parameter.type.name -eq 'switch') {
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.Add(
|
$Basket.Command[$Data.Name].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';
|
||||||
|
|
@ -204,11 +174,11 @@ function Get-IcingaCheckCommandConfig()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add($parameter.Name, "0");
|
$Basket.Command[$Data.Name].vars.Add($parameter.Name, $FALSE);
|
||||||
|
|
||||||
# Conditional whether type of parameter is array
|
# Conditional whether type of parameter is array
|
||||||
} elseif ($parameter.type.name -eq 'array') {
|
} elseif ($parameter.type.name -eq 'array') {
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.Add(
|
$Basket.Command[$Data.Name].arguments.Add(
|
||||||
[string]::Format('-{0}', $parameter.Name), @{
|
[string]::Format('-{0}', $parameter.Name), @{
|
||||||
'value' = @{
|
'value' = @{
|
||||||
'type' = 'Function';
|
'type' = 'Function';
|
||||||
|
|
@ -225,7 +195,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
# Default to Object
|
# Default to Object
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.Add(
|
$Basket.Command[$Data.Name].arguments.Add(
|
||||||
[string]::Format('-{0}', $parameter.Name), @{
|
[string]::Format('-{0}', $parameter.Name), @{
|
||||||
'value' = $IcingaCustomVariable;
|
'value' = $IcingaCustomVariable;
|
||||||
'order' = $Order;
|
'order' = $Order;
|
||||||
|
|
@ -233,9 +203,9 @@ function Get-IcingaCheckCommandConfig()
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($parameter.name -ne 'Verbose') {
|
if ($parameter.name -ne 'Verbose') {
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add($parameter.Name, '$$null');
|
$Basket.Command[$Data.Name].vars.Add($parameter.Name, '$$null');
|
||||||
} else {
|
} else {
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add($parameter.Name, "0");
|
$Basket.Command[$Data.Name].vars.Add($parameter.Name, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -251,17 +221,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
$DataListName = [string]::Format('PowerShell {0}', $parameter.Name)
|
$DataListName = [string]::Format('PowerShell {0}', $parameter.Name)
|
||||||
|
|
||||||
if ($parameter.type.name -eq 'switch') {
|
if ($parameter.type.name -eq 'switch') {
|
||||||
$IcingaDataType='Datalist';
|
$IcingaDataType='Boolean';
|
||||||
if ($Basket.DataList.ContainsKey($DataListName) -eq $FALSE) {
|
|
||||||
$Basket.DataList.Add(
|
|
||||||
$DataListName, @{
|
|
||||||
'list_name' = $DataListName;
|
|
||||||
'owner' = $env:username;
|
|
||||||
'originalId' = '50'; #Gehört noch geändert
|
|
||||||
'entries' = @{};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} elseif ($parameter.type.name -eq 'Object') {
|
} elseif ($parameter.type.name -eq 'Object') {
|
||||||
if ($parameter.Name -eq 'Verbose') {
|
if ($parameter.Name -eq 'Verbose') {
|
||||||
$IcingaDataType='Datalist'
|
$IcingaDataType='Datalist'
|
||||||
|
|
@ -279,16 +239,11 @@ function Get-IcingaCheckCommandConfig()
|
||||||
$Basket.Datafield.Add(
|
$Basket.Datafield.Add(
|
||||||
'0', @{
|
'0', @{
|
||||||
'varname' = 'PowerShell_switch_NoPerfData';
|
'varname' = 'PowerShell_switch_NoPerfData';
|
||||||
'caption' = 'NoPerfData';
|
'caption' = 'Ignore Performance Data';
|
||||||
'description' = 'Specifies if the plugin will return performance data output or not';
|
'description' = 'Specifies if the plugin will return performance data output or not';
|
||||||
'datatype' = 'Icinga\\Module\\Director\\DataType\\DataTypeDatalist';
|
'datatype' = 'Icinga\Module\Director\DataType\DataTypeBoolean';
|
||||||
'format' = $NULL;
|
'format' = $NULL;
|
||||||
'originalId' = '0';
|
'originalId' = '0';
|
||||||
'settings' = @{
|
|
||||||
'datalist' = 'PowerShell NoPerfData';
|
|
||||||
'datatype' = 'string';
|
|
||||||
'behavior' = 'strict';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -296,10 +251,10 @@ function Get-IcingaCheckCommandConfig()
|
||||||
if($Basket.Datafield.ContainsKey('1') -eq $FALSE){
|
if($Basket.Datafield.ContainsKey('1') -eq $FALSE){
|
||||||
$Basket.Datafield.Add(
|
$Basket.Datafield.Add(
|
||||||
'1', @{
|
'1', @{
|
||||||
'varname' = 'PowerShell_switch_NoPerfData';
|
'varname' = 'PowerShell_Object_Verbose';
|
||||||
'caption' = 'Verbose';
|
'caption' = 'Verbose';
|
||||||
'description' = 'Specifies if the plugin will return performance data output or not';
|
'description' = 'Specifies if the plugin will return performance data output or not';
|
||||||
'datatype' = 'Icinga\\Module\\Director\\DataType\\DataTypeString';
|
'datatype' = 'Icinga\Module\Director\DataType\DataTypeString';
|
||||||
'format' = $NULL;
|
'format' = $NULL;
|
||||||
'originalId' = '1';
|
'originalId' = '1';
|
||||||
'settings' = @{
|
'settings' = @{
|
||||||
|
|
@ -313,8 +268,8 @@ function Get-IcingaCheckCommandConfig()
|
||||||
|
|
||||||
$IcingaDataType = [string]::Format('Icinga\Module\Director\DataType\DataType{0}', $IcingaDataType)
|
$IcingaDataType = [string]::Format('Icinga\Module\Director\DataType\DataType{0}', $IcingaDataType)
|
||||||
|
|
||||||
if ($Basket.Datafield.Values.varname -eq $IcingaCustomVariable) {
|
|
||||||
} else {
|
if ($Basket.Datafield.Values.varname -ne $IcingaCustomVariable) {
|
||||||
$Basket.Datafield.Add(
|
$Basket.Datafield.Add(
|
||||||
[string]$FieldID, @{
|
[string]$FieldID, @{
|
||||||
'varname' = $IcingaCustomVariable;
|
'varname' = $IcingaCustomVariable;
|
||||||
|
|
@ -326,7 +281,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($parameter.type.name -eq 'switch' -or $parameter.Name -eq 'Verbose') {
|
if ($parameter.Name -eq 'Verbose') {
|
||||||
$Basket.Datafield[[string]$FieldID].Add(
|
$Basket.Datafield[[string]$FieldID].Add(
|
||||||
'settings', @{
|
'settings', @{
|
||||||
'behavior' = 'strict';
|
'behavior' = 'strict';
|
||||||
|
|
@ -353,20 +308,20 @@ function Get-IcingaCheckCommandConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Increment FieldNumeation, so unique fields for a given command are added.
|
# Increment FieldNumeration, so unique fields for a given command are added.
|
||||||
[int]$FieldNumeration = [int]$FieldNumeration + 1;
|
[int]$FieldNumeration = [int]$FieldNumeration + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check whether or not noperfdata and verbose is set and add it if necessary
|
# Check whether or not noperfdata and verbose is set and add it if necessary
|
||||||
if ($Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.ContainsKey('-Verbose') -eq $FALSE) {
|
if ($Basket.Command[$Data.Name].arguments.ContainsKey('-Verbose') -eq $FALSE) {
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.Add(
|
$Basket.Command[$Data.Name].arguments.Add(
|
||||||
'-Verbose', @{
|
'-Verbose', @{
|
||||||
'value' = '$PowerShell_Object_Verbose$';
|
'value' = '$PowerShell_Object_Verbose$';
|
||||||
'order' = '99';
|
'order' = '99';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add(
|
$Basket.Command[$Data.Name].vars.Add(
|
||||||
'PowerShell_Object_Verbose', "0"
|
'PowerShell_Object_Verbose', "0"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -390,34 +345,15 @@ function Get-IcingaCheckCommandConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.ContainsKey('-NoPerfData') -eq $FALSE) {
|
if ($Basket.Command[$Data.Name].arguments.ContainsKey('-NoPerfData') -eq $FALSE) {
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.Add(
|
$Basket.Command[$Data.Name].arguments.Add(
|
||||||
'-NoPerfData', @{
|
'-NoPerfData', @{
|
||||||
'set_if' = '$PowerShell_switch_NoPerfData$';
|
'set_if' = '$PowerShell_switch_NoPerfData$';
|
||||||
'set_if_format' = 'string';
|
'set_if_format' = 'string';
|
||||||
'order' = '99';
|
'order' = '99';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add('PowerShell_switch_NoPerfData', "0");
|
$Basket.Command[$Data.Name].vars.Add('PowerShell_switch_NoPerfData', $FALSE);
|
||||||
|
|
||||||
if ($Basket.Datafield.Values.varname -eq $IcingaCustomVariable) {
|
|
||||||
} else {
|
|
||||||
$Basket.Datafield.Add(
|
|
||||||
[string]$FieldID, @{
|
|
||||||
'varname' = 'PowerShell_switch_NoPerfData';
|
|
||||||
'caption' = 'Perf Data';
|
|
||||||
'description' = 'Specifies if the plugin will return performance data output or not';
|
|
||||||
'datatype' = 'Icinga\Module\Director\DataType\DataTypeDatalist';
|
|
||||||
'format' = $NULL;
|
|
||||||
'originalId' = [string]$FieldID;
|
|
||||||
'settings' = @{
|
|
||||||
'behavior' = 'strict';
|
|
||||||
'data_type' = 'string';
|
|
||||||
'datalist' = 'PowerShell NoPerfData'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -426,38 +362,25 @@ function Get-IcingaCheckCommandConfig()
|
||||||
|
|
||||||
$Data = (Get-Help $check)
|
$Data = (Get-Help $check)
|
||||||
|
|
||||||
foreach ($parameter in $Data.Syntax.syntaxItem.parameter){
|
foreach ($parameter in $Data.parameters.parameter){
|
||||||
$IcingaCustomVariable = [string]::Format('PowerShell_{0}_{1}', $parameter.type.name, $parameter.Name);
|
$IcingaCustomVariable = [string]::Format('PowerShell_{0}_{1}', $parameter.type.name, $parameter.Name);
|
||||||
|
|
||||||
# Hashtable for Matching Command.Name.Fields to DataFields (and there given IDs)
|
# Todo: Should we improve this? Actually the handling would be identical, we just need to assign
|
||||||
[hashtable]$TranslationDataField = @{}
|
# the proper field for this
|
||||||
|
if ($IcingaCustomVariable -eq 'PowerShell_Int32_Verbose') {
|
||||||
# Looping through IDs of existing DataFields
|
$IcingaCustomVariable = 'PowerShell_Object_Verbose';
|
||||||
foreach ($DataFieldID in $Basket.Datafield.Keys)
|
|
||||||
{
|
|
||||||
# Ignore Default-Set Deatafield "NoPerfData"
|
|
||||||
if ($TranslationDataField.Contains('PowerShell_switch_NoPerfData') -eq $TRUE){
|
|
||||||
}else{
|
|
||||||
$TranslationDataField.Add($Basket.Datafield.$DataFieldID.varname, $DataFieldID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($key in $TranslationDataField.Keys)
|
foreach ($DataFieldID in $Basket.Datafield.Keys) {
|
||||||
{
|
[string]$varname = $Basket.Datafield[$DataFieldID].varname;
|
||||||
if ([string]$IcingaCustomVariable -eq [string]$key) {
|
if ([string]$varname -eq [string]$IcingaCustomVariable) {
|
||||||
$MatchedDataFieldID = $TranslationDataField[$IcingaCustomVariable];
|
$Basket.Command[$Data.Name].fields += @{
|
||||||
} else {}
|
'datafield_id' = [int]$DataFieldID;
|
||||||
}
|
|
||||||
|
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].fields.Add(
|
|
||||||
[string]$FieldNumeration, @{
|
|
||||||
'datafield_id' = [int]$MatchedDataFieldID;
|
|
||||||
'is_required' = $Required;
|
'is_required' = $Required;
|
||||||
'var_filter' = $NULL;
|
'var_filter' = $NULL;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
[int]$FieldNumeration = [int]$FieldNumeration + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue