From 6900a1694fd5f64ba4090e96919cc2ee9247838b Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 7 Oct 2019 00:04:30 +0200 Subject: [PATCH] Added proper support for custom plugins / lib elements --- core/init.ps1 | 1 + custom/lib/README.md | 3 +++ custom/plugins/README.md | 3 +++ icinga-module-windows.psd1 | 2 +- icinga-module-windows.psm1 | 16 ++++++++++++++-- lib/core/tools/New-IcingaCheckCommand.psm1 | 2 +- 6 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 custom/lib/README.md create mode 100644 custom/plugins/README.md diff --git a/core/init.ps1 b/core/init.ps1 index ac4b829..99b7756 100644 --- a/core/init.ps1 +++ b/core/init.ps1 @@ -10,6 +10,7 @@ Set-Variable -Name Icinga2 -Option Constant -Value @{ 'Use-Icinga', 'Import-IcingaLib', 'Get-IcingaPluginDir', + 'Get-IcingaCustomPluginDir', 'Get-IcingaCacheDir', 'Get-IcingaPowerShellConfigDir', 'Get-Icinga-Lib', diff --git a/custom/lib/README.md b/custom/lib/README.md new file mode 100644 index 0000000..751fa67 --- /dev/null +++ b/custom/lib/README.md @@ -0,0 +1,3 @@ +# Custom Libraries + +Here you can place your own libraries for the module. You can either extend the module with this or override existing libraries without having to worry about breaking future updates diff --git a/custom/plugins/README.md b/custom/plugins/README.md new file mode 100644 index 0000000..b74aded --- /dev/null +++ b/custom/plugins/README.md @@ -0,0 +1,3 @@ +# Custom Plugins + +Here you can place your own custom plugins or override existing ones. This will ensure future updates of the module will not rever your changes diff --git a/icinga-module-windows.psd1 b/icinga-module-windows.psd1 index 3ae95d2..a64d8ac 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 = @( 'Use-Icinga', 'Import-IcingaLib', 'Get-IcingaPluginDir', 'Get-IcingaCacheDir', 'Get-IcingaPowerShellConfigDir', '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', 'Get-IcingaPluginDir', 'Get-IcingaCustomPluginDir', 'Get-IcingaCacheDir', 'Get-IcingaPowerShellConfigDir', '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 adfe97a..bc3850b 100644 --- a/icinga-module-windows.psm1 +++ b/icinga-module-windows.psm1 @@ -18,6 +18,8 @@ function Use-Icinga() # This function will allow us to load this entire module including possible # actions, making it available within our shell environment + # First load our custom modules + Import-IcingaLib '\' -Init -Custom; Import-IcingaLib '\' -Init; if ($LibOnly -eq $FALSE) { @@ -48,7 +50,8 @@ function Import-IcingaLib() # 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, - [switch]$Init + [switch]$Init, + [switch]$Custom ); # This is just to only allow a global loading of the module. Import-IcingaLib is ignored on every other @@ -57,7 +60,11 @@ function Import-IcingaLib() return; } - [string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'lib\'; + if ($Custom) { + [string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'custom\'; + } else { + [string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'lib\'; + } [string]$module = Join-Path -Path $directory -ChildPath $Lib; [string]$moduleName = ''; @@ -99,6 +106,11 @@ function Get-IcingaPluginDir() return (Join-Path -Path $PSScriptRoot -ChildPath 'lib\plugins\'); } +function Get-IcingaCustomPluginDir() +{ + return (Join-Path -Path $PSScriptRoot -ChildPath 'custom\plugins\'); +} + function Get-IcingaCacheDir() { return (Join-Path -Path $PSScriptRoot -ChildPath 'cache'); diff --git a/lib/core/tools/New-IcingaCheckCommand.psm1 b/lib/core/tools/New-IcingaCheckCommand.psm1 index 56c8a92..f3a1787 100644 --- a/lib/core/tools/New-IcingaCheckCommand.psm1 +++ b/lib/core/tools/New-IcingaCheckCommand.psm1 @@ -29,7 +29,7 @@ function New-IcingaCheckCommand() $CommandName ); - [string]$ScriptFile = Join-Path -Path (Get-IcingaPluginDir) -ChildPath $CommandFile; + [string]$ScriptFile = Join-Path -Path (Get-IcingaCustomPluginDir) -ChildPath $CommandFile; if ((Test-Path $ScriptFile) -eq $TRUE) { throw 'This Check-Command does already exist.';