diff --git a/core/init.ps1 b/core/init.ps1 index 3b604ef..e57c9e8 100644 --- a/core/init.ps1 +++ b/core/init.ps1 @@ -7,8 +7,8 @@ param ( # Create an internal 'namespace' for our environment Set-Variable -Name Icinga2 -Option Constant -Value @{ Function = @( + 'Use-Icinga', 'Import-IcingaLib', - 'Import-IcingaDirectoryModules', 'Get-Icinga-Lib', 'Get-Icinga-Object', 'Get-Icinga-Service', diff --git a/icinga-module-windows.psd1 b/icinga-module-windows.psd1 index 0a06bee..35e62cb 100644 --- a/icinga-module-windows.psd1 +++ b/icinga-module-windows.psd1 @@ -25,7 +25,7 @@ Description = 'Icinga 2 Windows Agent Module, which allows to entirely monitor t PowerShellVersion = '3.0' # Aus diesem Modul zu exportierende Funktionen. Um optimale Leistung zu erzielen, verwenden Sie keine Platzhalter und löschen den Eintrag nicht. Verwenden Sie ein leeres Array, wenn keine zu exportierenden Funktionen vorhanden sind. -FunctionsToExport = @( 'Import-IcingaLib', 'Import-IcingaDirectoryModules', 'Start-Icinga-Checker', 'Stop-Icinga-Checker', 'Get-Icinga-Lib', 'Get-Icinga-Object', 'Get-Icinga-Service', 'Start-Icinga-Service', 'Stop-Icinga-Service', 'Restart-Icinga-Service', 'Install-Icinga-Service', 'Uninstall-Icinga-Service', 'Get-Icinga-Setup', 'Install-Icinga', 'Start-Icinga-Daemon', 'Stop-Icinga-Daemon', 'Icinga-Client', 'Get-Icinga-Command', 'New-Icinga-Monitoring', 'Get-Icinga-Counter', 'Get-Icinga-Config', 'Set-Icinga-Config', 'Remove-Icinga-Config', 'New-Icinga-Config' ) +FunctionsToExport = @( 'Use-Icinga', 'Import-IcingaLib', 'Start-Icinga-Checker', 'Stop-Icinga-Checker', 'Get-Icinga-Lib', 'Get-Icinga-Object', 'Get-Icinga-Service', 'Start-Icinga-Service', 'Stop-Icinga-Service', 'Restart-Icinga-Service', 'Install-Icinga-Service', 'Uninstall-Icinga-Service', 'Get-Icinga-Setup', 'Install-Icinga', 'Start-Icinga-Daemon', 'Stop-Icinga-Daemon', 'Icinga-Client', 'Get-Icinga-Command', 'New-Icinga-Monitoring', 'Get-Icinga-Counter', 'Get-Icinga-Config', 'Set-Icinga-Config', 'Remove-Icinga-Config', 'New-Icinga-Config' ) # Aus diesem Modul zu exportierende Cmdlets. Um optimale Leistung zu erzielen, verwenden Sie keine Plat'zhalter und löschen den Eintrag nicht. Verwenden Sie ein leeres Array, wenn keine zu exportierenden Cmdlets vorhanden sind. CmdletsToExport = @() diff --git a/icinga-module-windows.psm1 b/icinga-module-windows.psm1 index e39a4c4..50a685a 100644 --- a/icinga-module-windows.psm1 +++ b/icinga-module-windows.psm1 @@ -9,6 +9,12 @@ #> +function Use-Icinga() +{ + # This function will allow us to load this entire module including possible + # actions, making it available within our shell environment +} + function Import-IcingaLib() { param( @@ -24,56 +30,38 @@ function Import-IcingaLib() [Switch]$ForceReload ); - [string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'lib'; + [string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'lib\'; [string]$module = Join-Path -Path $directory -ChildPath $Lib; - $module = $module.Replace('.psm1', ''); # Cut possible .psm1 ending - [string]$moduleName = $module.Split('\')[-1]; # Get the last element + [string]$moduleName = ''; - if ($ForceReload) { - $ListOfLoadedModules = Get-Module | Select-Object Name; - if ($ListOfLoadedModules -Like "*$moduleName*") { - Remove-Module -Name $moduleName; + $ListOfLoadedModules = Get-Module | Select-Object Name; + + # Load modules from directory + if ((Test-Path $module -PathType Container)) { + Get-ChildItem -Path $module -Recurse -Filter *.psm1 | + ForEach-Object { + [string]$modulePath = $_.FullName; + $moduleName = $_.Name.Replace('.psm1', ''); + + if ($ForceReload) { + if ($ListOfLoadedModules -like "*$moduleName*") { + Remove-Module -Name $moduleName + } + } + + Import-Module ([string]::Format('{0}', $modulePath)) -Global; } - } + } else { + $module = $module.Replace('.psm1', ''); # Cut possible .psm1 ending + $moduleName = $module.Split('\')[-1]; # Get the last element - Import-Module ([string]::Format('{0}.psm1', $module)) -Global; -} - -function Import-IcingaDirectoryModules() -{ - param( - [Parameter( - Position=0, - Mandatory=$true, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true) - ] - [String]$LibDirectory, - # The Force Reload will remove the module in case it's loaded and reload it to track - # possible development changes without having to create new PowerShell environments - [Switch]$ForceReload - ); - - $LibDirectory = $LibDirectory.Replace('.psm1', ''); - - if (-Not (Test-Path $LibDirectory)) { - Write-Output ([string]::Format('Include directory not found: {0}', $LibDirectory)); - return; - } - - Get-ChildItem -Path $LibDirectory -Recurse -Filter *.psm1 | - ForEach-Object { - [string]$modulePath = $_.FullName; - [string]$moduleName = $_.Name.Replace('.psm1', ''); - if ($ForceReload) { - $ListOfLoadedModules = Get-Module | Select-Object Name; - if ($ListOfLoadedModules -like "*$moduleName*") { - Remove-Module -Name $moduleName + if ($ListOfLoadedModules -Like "*$moduleName*") { + Remove-Module -Name $moduleName; } } - - Import-Module ([string]::Format('{0}', $modulePath)) -Global; + + Import-Module ([string]::Format('{0}.psm1', $module)) -Global; } } @@ -346,6 +334,10 @@ function Get-Icinga-Object() return $Icinga2; } +# Automaticly load the Help library including Plugins +Import-IcingaLib help\help; +Import-IcingaLib plugins; + # Initialise base configuration for our module $Icinga2 = & (Join-Path -Path $PSScriptRoot -ChildPath '\core\init.ps1') ` -RootDirectory $PSScriptRoot ` diff --git a/lib/core/tools.psm1 b/lib/core/tools.psm1 deleted file mode 100644 index 4ce1716..0000000 --- a/lib/core/tools.psm1 +++ /dev/null @@ -1 +0,0 @@ -Import-IcingaDirectoryModules -LibDirectory (Join-Path -Path $PSScriptRoot -ChildPath $MyInvocation.MyCommand.Name); diff --git a/lib/help/help.psm1 b/lib/help/help.psm1 deleted file mode 100644 index 4ce1716..0000000 --- a/lib/help/help.psm1 +++ /dev/null @@ -1 +0,0 @@ -Import-IcingaDirectoryModules -LibDirectory (Join-Path -Path $PSScriptRoot -ChildPath $MyInvocation.MyCommand.Name); diff --git a/lib/icinga/enums.psm1 b/lib/icinga/enums/Icinga_IcingaEnums.psm1 similarity index 100% rename from lib/icinga/enums.psm1 rename to lib/icinga/enums/Icinga_IcingaEnums.psm1 diff --git a/lib/icinga/plugin.psm1 b/lib/icinga/plugin.psm1 deleted file mode 100644 index 4ce1716..0000000 --- a/lib/icinga/plugin.psm1 +++ /dev/null @@ -1 +0,0 @@ -Import-IcingaDirectoryModules -LibDirectory (Join-Path -Path $PSScriptRoot -ChildPath $MyInvocation.MyCommand.Name);