mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 15:19:58 -05:00
Changed DataLists to Array; Added Synopsis, Description, Examples, Parameter, Inputs, Outputs, Link in Comment-Based-Help; Fixed 'self-export'; Changed codestyling; Deleted unnecessary code; Deleted unnecessary comments and added new one as deemed necessary
This commit is contained in:
parent
e7950c1616
commit
e137a4dbcf
1 changed files with 211 additions and 157 deletions
|
|
@ -1,112 +1,155 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Exports command as JSON for icinga director
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
Invoke-IcingaCheckCommandBasket returns a JSON-file of one or all 'Invoke-IcingaCheck'-Commands, which can be imported via Icinga-Director
|
||||||
|
When no single command is specified all commands will be exported, and vice versa.
|
||||||
|
|
||||||
|
More Information on https://github.com/LordHepipud/icinga-module-windows
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Invoke-IcingaCheckCommandBasket
|
||||||
|
The following commands have been exported:
|
||||||
|
- 'Invoke-IcingaCheckBiosSerial'
|
||||||
|
- 'Invoke-IcingaCheckCommandBasket'
|
||||||
|
- 'Invoke-IcingaCheckCPU'
|
||||||
|
- 'Invoke-IcingaCheckProcessCount'
|
||||||
|
- 'Invoke-IcingaCheckService'
|
||||||
|
- 'Invoke-IcingaCheckUpdates'
|
||||||
|
- 'Invoke-IcingaCheckUptime'
|
||||||
|
- 'Invoke-IcingaCheckUsedPartitionSpace'
|
||||||
|
- 'Invoke-IcingaCheckUsers'
|
||||||
|
JSON export created to 'C:\Program Files\WindowsPowerShell\Modules\icinga-module-windows\Checks.json'
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Invoke-IcingaCheckCommandBasket Invoke-IcingaCheckCPU
|
||||||
|
The following commands have been exported:
|
||||||
|
- 'Invoke-IcingaCheckCPU'
|
||||||
|
JSON export created to 'C:\Program Files\WindowsPowerShell\Modules\icinga-module-windows\Invoke-IcingaCheckCPU.json'
|
||||||
|
.PARAMETER CheckName
|
||||||
|
Used to specify a single command which should be exported.
|
||||||
|
Has to be a single string.
|
||||||
|
.INPUTS
|
||||||
|
System.String
|
||||||
|
|
||||||
|
.OUTPUTS
|
||||||
|
System.String
|
||||||
|
System.Object
|
||||||
|
|
||||||
|
.LINK
|
||||||
|
https://github.com/LordHepipud/icinga-module-windows
|
||||||
|
|
||||||
|
.NOTES
|
||||||
|
#>
|
||||||
|
|
||||||
function Invoke-IcingaCheckCommandBasket()
|
function Invoke-IcingaCheckCommandBasket()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
$CheckName
|
$CheckName
|
||||||
);
|
);
|
||||||
|
|
||||||
[hashtable]$AllChecks = @{};
|
# Check whether all Checks will be exported or just the single one specified
|
||||||
|
|
||||||
if ($NULL -eq $CheckName) {
|
if ($NULL -eq $CheckName) {
|
||||||
$CheckName = (Get-Command Invoke-IcingaCheck*).Name
|
$CheckName = (Get-Command Invoke-IcingaCheck*).Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Variable definition and initialization
|
||||||
[int]$FieldID = 0;
|
[int]$FieldID = 0;
|
||||||
[hashtable]$Basket = @{};
|
[hashtable]$Basket = @{};
|
||||||
|
|
||||||
|
# Define basic hashtable structure by adding fields: "Datafield", "DataList", "Command"
|
||||||
$Basket.Add('Datafield', @{});
|
$Basket.Add('Datafield', @{});
|
||||||
$Basket.Add('DataList', @{});
|
$Basket.Add('DataList', @{});
|
||||||
$Basket.Add('Command', @{});
|
$Basket.Add('Command', @{});
|
||||||
|
|
||||||
# DataList Entries (Default for NoPerfData)
|
|
||||||
if ($Basket.DataList.ContainsKey('PowerShell NoPerfData') -eq $FALSE) {
|
|
||||||
$Basket.DataList.Add(
|
|
||||||
'PowerShell NoPerfData', @{
|
|
||||||
'list_name' = 'PowerShell NoPerfData';
|
|
||||||
'owner' = $env:username;
|
|
||||||
'originalId' = '1'; #Gehört noch geändert
|
|
||||||
'entries' = @{};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$Basket.DataList["PowerShell NoPerfData"].entries.Add(
|
# "NoPerfData" gets added to all Checks build and exported no matter what, so we add it from the start
|
||||||
'0', @{
|
if ($Basket.DataList.ContainsKey('PowerShell NoPerfData') -eq $FALSE) {
|
||||||
'entry_name' = '0';
|
|
||||||
'entry_value:' = "yes";
|
|
||||||
'format' = 'string';
|
|
||||||
'allowed_roles' = $NULL;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$Basket.DataList["PowerShell NoPerfData"].entries.Add(
|
|
||||||
'1', @{
|
|
||||||
'entry_name' = '1';
|
|
||||||
'entry_value:' = "no";
|
|
||||||
'format' = 'string';
|
|
||||||
'allowed_roles' = $NULL;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
# DataList Entries (Default for Verbose)
|
# DataList Content for NoPerfData
|
||||||
if ($Basket.DataList.ContainsKey('PowerShell Verbose') -eq $FALSE) {
|
$Basket.DataList.Add(
|
||||||
$Basket.DataList.Add(
|
'PowerShell NoPerfData', @{
|
||||||
'PowerShell Verbose', @{
|
'list_name' = 'PowerShell NoPerfData';
|
||||||
'list_name' = 'PowerShell Verbose';
|
'owner' = $env:username;
|
||||||
'owner' = $env:username;
|
'originalId' = '1'; #Gehört noch geändert
|
||||||
'originalId' = '50'; #Gehört noch geändert
|
'entries' = @(
|
||||||
'entries' = @{};
|
@{
|
||||||
}
|
'entry_name' = '0';
|
||||||
|
'entry_value:' = "yes";
|
||||||
|
'format' = 'string';
|
||||||
|
'allowed_roles' = $NULL;
|
||||||
|
},
|
||||||
|
@{
|
||||||
|
'entry_name' = '1';
|
||||||
|
'entry_value:' = "no";
|
||||||
|
'format' = 'string';
|
||||||
|
'allowed_roles' = $NULL;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$Basket.DataList["PowerShell Verbose"].entries.Add(
|
);
|
||||||
'0', @{
|
}
|
||||||
|
# "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) {
|
||||||
|
$Basket.DataList.Add(
|
||||||
|
'PowerShell Verbose', @{
|
||||||
|
'list_name' = 'PowerShell Verbose';
|
||||||
|
'owner' = $env:username;
|
||||||
|
'originalId' = '50';
|
||||||
|
'entries' = @(
|
||||||
|
@{
|
||||||
'entry_name' = '0';
|
'entry_name' = '0';
|
||||||
'entry_value:' = "Show Default";
|
'entry_value:' = "Show Default";
|
||||||
'format' = 'string';
|
'format' = 'string';
|
||||||
'allowed_roles' = $NULL;
|
'allowed_roles' = $NULL;
|
||||||
}
|
},
|
||||||
);
|
@{
|
||||||
$Basket.DataList["PowerShell Verbose"].entries.Add(
|
|
||||||
'1', @{
|
|
||||||
'entry_name' = '1';
|
'entry_name' = '1';
|
||||||
'entry_value:' = "Show Operator";
|
'entry_value:' = "Show Operator";
|
||||||
'format' = 'string';
|
'format' = 'string';
|
||||||
'allowed_roles' = $NULL;
|
'allowed_roles' = $NULL;
|
||||||
}
|
},
|
||||||
);
|
@{
|
||||||
$Basket.DataList["PowerShell Verbose"].entries.Add(
|
|
||||||
'2', @{
|
|
||||||
'entry_name' = '2';
|
'entry_name' = '2';
|
||||||
'entry_value:' = "Show Problems";
|
'entry_value:' = "Show Problems";
|
||||||
'format' = 'string';
|
'format' = 'string';
|
||||||
'allowed_roles' = $NULL;
|
'allowed_roles' = $NULL;
|
||||||
}
|
},
|
||||||
)
|
@{
|
||||||
$Basket.DataList["PowerShell Verbose"].entries.Add(
|
|
||||||
'3', @{
|
|
||||||
'entry_name' = '3';
|
'entry_name' = '3';
|
||||||
'entry_value:' = "Show All";
|
'entry_value:' = "Show All";
|
||||||
'format' = 'string';
|
'format' = 'string';
|
||||||
'allowed_roles' = $NULL;
|
'allowed_roles' = $NULL;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
Loop through either:
|
||||||
|
$CheckName = (Get-Command Invoke-IcingaCheck*).Name
|
||||||
|
or one of $CheckName = 'Invoke-IcingaCheckCommand'
|
||||||
|
#>
|
||||||
foreach ($check in $CheckName) {
|
foreach ($check in $CheckName) {
|
||||||
|
if ($check -eq 'Invoke-IcingaCheckCommandBasket') {
|
||||||
|
} else {
|
||||||
|
|
||||||
# [hashtable]$Basket = @{};
|
# Get Necessary Syntax-Information and more through cmdlet "Get-Help"
|
||||||
|
|
||||||
# [int]$FieldID = 0;
|
|
||||||
|
|
||||||
$Data = (Get-Help $check)
|
$Data = (Get-Help $check)
|
||||||
|
|
||||||
|
# Add Command Structure
|
||||||
$Basket.Command.Add(
|
$Basket.Command.Add(
|
||||||
$Data.Syntax.syntaxItem.Name, @{
|
$Data.Syntax.syntaxItem.Name, @{
|
||||||
'arguments'= @{
|
'arguments'= @{
|
||||||
|
# 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.Syntax.syntaxItem.Name);
|
||||||
'order' = '0';
|
'order' = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'command' = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"; #Gehört noch geändert
|
'command' = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe";
|
||||||
'disabled' = $FALSE;
|
'disabled' = $FALSE;
|
||||||
'fields' = @{};
|
'fields' = @{};
|
||||||
'imports' = @();
|
'imports' = @();
|
||||||
|
|
@ -120,21 +163,21 @@ function Invoke-IcingaCheckCommandBasket()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# $Basket.Add('Datafield', @{});
|
# Loop through Parameter of a given command
|
||||||
# $Basket.Add('DataList', @{});
|
|
||||||
|
|
||||||
foreach ($parameter in $Data.Syntax.syntaxItem.parameter) {
|
foreach ($parameter in $Data.Syntax.syntaxItem.parameter) {
|
||||||
|
# Filter for Parameter 'core', because its set by default
|
||||||
if ($parameter.name -ne 'core') {
|
if ($parameter.name -ne 'core') {
|
||||||
# Is Numeric Check on position to determine the order value
|
|
||||||
If (Test-Numeric($parameter.position) -eq $TRUE) {
|
|
||||||
[string]$Order = [int]$parameter.position + 1
|
|
||||||
} else {
|
|
||||||
[string]$Order = 99
|
|
||||||
}
|
|
||||||
|
|
||||||
$IcingaCustomVariable = [string]::Format('$PowerShell_{0}_{1}$', $parameter.type.name, $parameter.Name);
|
# Is Numeric Check on position to determine the order value
|
||||||
|
If (Test-Numeric($parameter.position) -eq $TRUE) {
|
||||||
|
[string]$Order = [int]$parameter.position + 1
|
||||||
|
} else {
|
||||||
|
[string]$Order = 99
|
||||||
|
}
|
||||||
|
|
||||||
# Conditional whether type of parameter is switch
|
$IcingaCustomVariable = [string]::Format('$PowerShell_{0}_{1}$', $parameter.type.name, $parameter.Name);
|
||||||
|
|
||||||
|
#Adding 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.Syntax.syntaxItem.Name].arguments.Add(
|
||||||
[string]::Format('-{0}', $parameter.Name), @{
|
[string]::Format('-{0}', $parameter.Name), @{
|
||||||
|
|
@ -155,26 +198,31 @@ function Invoke-IcingaCheckCommandBasket()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
# Default to Object
|
# Default to Object
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.Add(
|
$Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.Add(
|
||||||
[string]::Format('-{0}', $parameter.Name), @{
|
[string]::Format('-{0}', $parameter.Name), @{
|
||||||
'value' = $IcingaCustomVariable;
|
'value' = $IcingaCustomVariable;
|
||||||
'order' = $Order;
|
'order' = $Order;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($parameter.name -ne 'Verbose') {
|
if ($parameter.name -ne 'Verbose') {
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add($parameter.Name, '$$null');
|
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add($parameter.Name, '$$null');
|
||||||
} else {
|
} else {
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add($parameter.Name, "0");
|
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add($parameter.Name, "0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# Fields
|
|
||||||
# Required?
|
# Fields
|
||||||
if ($parameter.required -eq $TRUE) {
|
|
||||||
|
# Determine wether a parameter is required based on given syntax-information
|
||||||
|
if ($parameter.required -eq $TRUE) {
|
||||||
$Required = 'y';
|
$Required = 'y';
|
||||||
} else {
|
} else {
|
||||||
$Required = 'n';
|
$Required = 'n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[int]$FieldID = $FieldID + 1;
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].fields.Add(
|
$Basket.Command[$Data.Syntax.syntaxItem.Name].fields.Add(
|
||||||
[string]$FieldID, @{
|
[string]$FieldID, @{
|
||||||
'datafield_id' = [int]$FieldID;
|
'datafield_id' = [int]$FieldID;
|
||||||
|
|
@ -190,14 +238,14 @@ function Invoke-IcingaCheckCommandBasket()
|
||||||
if ($parameter.type.name -eq 'switch') {
|
if ($parameter.type.name -eq 'switch') {
|
||||||
$IcingaDataType='Datalist';
|
$IcingaDataType='Datalist';
|
||||||
if ($Basket.DataList.ContainsKey($DataListName) -eq $FALSE) {
|
if ($Basket.DataList.ContainsKey($DataListName) -eq $FALSE) {
|
||||||
$Basket.DataList.Add(
|
$Basket.DataList.Add(
|
||||||
$DataListName, @{
|
$DataListName, @{
|
||||||
'list_name' = $DataListName;
|
'list_name' = $DataListName;
|
||||||
'owner' = $env:username;
|
'owner' = $env:username;
|
||||||
'originalId' = '50'; #Gehört noch geändert
|
'originalId' = '50'; #Gehört noch geändert
|
||||||
'entries' = @{};
|
'entries' = @{};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} elseif ($parameter.type.name -eq 'Object') {
|
} elseif ($parameter.type.name -eq 'Object') {
|
||||||
if ($parameter.Name -eq 'Verbose') {
|
if ($parameter.Name -eq 'Verbose') {
|
||||||
|
|
@ -209,84 +257,79 @@ function Invoke-IcingaCheckCommandBasket()
|
||||||
} else {
|
} else {
|
||||||
$IcingaDataType='String';
|
$IcingaDataType='String';
|
||||||
}
|
}
|
||||||
|
|
||||||
$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)
|
if ($Basket.Datafield.Values.varname -eq $IcingaCustomVariable) {
|
||||||
{
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[int]$FieldID = $FieldID + 1;
|
|
||||||
$Basket.Datafield.Add(
|
|
||||||
[string]$FieldID, @{
|
|
||||||
'varname' = $IcingaCustomVariable;
|
|
||||||
'caption' = $parameter.Name;
|
|
||||||
'description' = $NULL;
|
|
||||||
'datatype' = $IcingaDataType;
|
|
||||||
'format' = $NULL;
|
|
||||||
'originalId' = [string]$FieldID;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
if ($parameter.type.name -eq 'switch' -or $parameter.Name -eq 'Verbose') {
|
|
||||||
$Basket.Datafield[[string]$FieldID].Add(
|
|
||||||
'settings', @{
|
|
||||||
'behavior' = 'strict';
|
|
||||||
'datatype' = 'string';
|
|
||||||
'datalist' = $DataListName;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} elseif ($parameter.type.name -eq 'Object') {
|
|
||||||
$Basket.Datafield[[string]$FieldID].Add(
|
|
||||||
'settings', @{
|
|
||||||
'visbility' = 'visible';
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
$Basket.Datafield[[string]$FieldID].Add(
|
$Basket.Datafield.Add(
|
||||||
'settings', @{}
|
[string]$FieldID, @{
|
||||||
|
'varname' = $IcingaCustomVariable;
|
||||||
|
'caption' = $parameter.Name;
|
||||||
|
'description' = $NULL;
|
||||||
|
'datatype' = $IcingaDataType;
|
||||||
|
'format' = $NULL;
|
||||||
|
'originalId' = [string]$FieldID;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($parameter.type.name -eq 'switch' -or $parameter.Name -eq 'Verbose') {
|
||||||
|
$Basket.Datafield[[string]$FieldID].Add(
|
||||||
|
'settings', @{
|
||||||
|
'behavior' = 'strict';
|
||||||
|
'datatype' = 'string';
|
||||||
|
'datalist' = $DataListName;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} elseif ($parameter.type.name -eq 'Object') {
|
||||||
|
$Basket.Datafield[[string]$FieldID].Add(
|
||||||
|
'settings', @{
|
||||||
|
'visbility' = 'visible';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$Basket.Datafield[[string]$FieldID].Add(
|
||||||
|
'settings', @{}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[int]$FieldID = $FieldID + 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.Syntax.syntaxItem.Name].arguments.ContainsKey('-Verbose') -eq $FALSE) {
|
||||||
[int]$FieldID = $FieldID + 1;
|
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.Add(
|
$Basket.Command[$Data.Syntax.syntaxItem.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.Syntax.syntaxItem.Name].vars.Add(
|
||||||
'PowerShell_Object_Verbose', "0"
|
'PowerShell_Object_Verbose', "0"
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($Basket.Datafield.Values.varname -eq $IcingaCustomVariable) {
|
if ($Basket.Datafield.Values.varname -eq $IcingaCustomVariable) {
|
||||||
} else {
|
} else {
|
||||||
$Basket.Datafield.Add(
|
$Basket.Datafield.Add(
|
||||||
[string]$FieldID, @{
|
[string]$FieldID, @{
|
||||||
'varname' = 'PowerShell_Object_Verbose';
|
'varname' = 'PowerShell_Object_Verbose';
|
||||||
'caption' = 'Verbose';
|
'caption' = 'Verbose';
|
||||||
'description' = $NULL;
|
'description' = $NULL;
|
||||||
'datatype' = 'Icinga\Module\Director\DataType\DataTypeDatalist';
|
'datatype' = 'Icinga\Module\Director\DataType\DataTypeDatalist';
|
||||||
'format' = $NULL;
|
'format' = $NULL;
|
||||||
'originalId' = [string]$FieldID;
|
'originalId' = [string]$FieldID;
|
||||||
'settings' = @{
|
'settings' = @{
|
||||||
'behavior' = 'strict';
|
'behavior' = 'strict';
|
||||||
'data_type' = 'string';
|
'data_type' = 'string';
|
||||||
'datalist' = 'PowerShell Verbose'
|
'datalist' = 'PowerShell Verbose'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.ContainsKey('-NoPerfData') -eq $FALSE) {
|
if ($Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.ContainsKey('-NoPerfData') -eq $FALSE) {
|
||||||
[int]$FieldID = $FieldID + 1;
|
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.Add(
|
$Basket.Command[$Data.Syntax.syntaxItem.Name].arguments.Add(
|
||||||
'-NoPerfData', @{
|
'-NoPerfData', @{
|
||||||
'set_if' = '$PowerShell_switch_NoPerfData$';
|
'set_if' = '$PowerShell_switch_NoPerfData$';
|
||||||
|
|
@ -297,36 +340,47 @@ function Invoke-IcingaCheckCommandBasket()
|
||||||
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add(
|
$Basket.Command[$Data.Syntax.syntaxItem.Name].vars.Add(
|
||||||
'PowerShell_switch_NoPerfData', "0"
|
'PowerShell_switch_NoPerfData', "0"
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($Basket.Datafield.Values.varname -eq $IcingaCustomVariable) {
|
if ($Basket.Datafield.Values.varname -eq $IcingaCustomVariable) {
|
||||||
} else {
|
} else {
|
||||||
$Basket.Datafield.Add(
|
$Basket.Datafield.Add(
|
||||||
[string]$FieldID, @{
|
[string]$FieldID, @{
|
||||||
'varname' = 'PowerShell_switch_NoPerfData';
|
'varname' = 'PowerShell_switch_NoPerfData';
|
||||||
'caption' = 'Perf Data';
|
'caption' = 'Perf Data';
|
||||||
'description' = $NULL;
|
'description' = $NULL;
|
||||||
'datatype' = 'Icinga\Module\Director\DataType\DataTypeDatalist';
|
'datatype' = 'Icinga\Module\Director\DataType\DataTypeDatalist';
|
||||||
'format' = $NULL;
|
'format' = $NULL;
|
||||||
'originalId' = [string]$FieldID;
|
'originalId' = [string]$FieldID;
|
||||||
'settings' = @{
|
'settings' = @{
|
||||||
'behavior' = 'strict';
|
'behavior' = 'strict';
|
||||||
'data_type' = 'string';
|
'data_type' = 'string';
|
||||||
'datalist' = 'PowerShell NoPerfData'
|
'datalist' = 'PowerShell NoPerfData'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$AllChecks.Add($check, $Basket);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host $CheckName;
|
if ($CheckName.Count -eq 1) {
|
||||||
Write-Host $CheckName.Count;
|
$FileName = "${CheckName}.json";
|
||||||
|
} else {
|
||||||
|
$FileName = "Checks.json";
|
||||||
|
}
|
||||||
|
|
||||||
# if ([string]$CheckName.Count -eq '1') {
|
$output=ConvertTo-Json -D 100 $Basket > "$FileName";
|
||||||
$output=ConvertTo-Json -D 100 $Basket > Check.json;
|
|
||||||
# } else {
|
$FilePath = (Get-Location).Path
|
||||||
# $output=ConvertTo-Json -D 100 $AllChecks > Check.json;
|
|
||||||
# }
|
# Output-Text
|
||||||
|
Write-Host "The following commands have been exported:"
|
||||||
|
foreach ($check in $CheckName) {
|
||||||
|
if ($check -ne "Invoke-IcingaCheckCommandBasket") {
|
||||||
|
Write-Host "- '$check'"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host "JSON export created in '${FilePath}\${FileName}'"
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue