mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Added improved import handler
This commit is contained in:
parent
392f0b2a61
commit
b2f8d33228
3 changed files with 71 additions and 1 deletions
|
|
@ -7,6 +7,8 @@ param (
|
|||
# Create an internal 'namespace' for our environment
|
||||
Set-Variable -Name Icinga2 -Option Constant -Value @{
|
||||
Function = @(
|
||||
'Import-IcingaLib',
|
||||
'Import-IcingaDirectoryModules',
|
||||
'Get-Icinga-Lib',
|
||||
'Get-Icinga-Object',
|
||||
'Get-Icinga-Service',
|
||||
|
|
|
|||
|
|
@ -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 = @( '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 = @( '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' )
|
||||
|
||||
# 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 = @()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,74 @@
|
|||
|
||||
#>
|
||||
|
||||
function Import-IcingaLib()
|
||||
{
|
||||
param(
|
||||
[Parameter(
|
||||
Position=0,
|
||||
Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true)
|
||||
]
|
||||
[String]$Lib,
|
||||
# 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
|
||||
);
|
||||
|
||||
[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
|
||||
|
||||
if ($ForceReload) {
|
||||
$ListOfLoadedModules = Get-Module | Select-Object Name;
|
||||
if ($ListOfLoadedModules -Like "*$moduleName*") {
|
||||
Remove-Module -Name $moduleName;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Import-Module ([string]::Format('{0}', $modulePath)) -Global;
|
||||
}
|
||||
}
|
||||
|
||||
function Install-Icinga()
|
||||
{
|
||||
[string]$command = Get-Icinga-Command('setup');
|
||||
|
|
|
|||
Loading…
Reference in a new issue