Skip to content

Commit

Permalink
Added proper support for custom plugins / lib elements
Browse files Browse the repository at this point in the history
  • Loading branch information
LordHepipud committed Oct 6, 2019
1 parent 1f15eee commit 843359d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions core/init.ps1
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion icinga-module-windows.psd1
Expand Up @@ -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 = @()
Expand Down
16 changes: 14 additions & 2 deletions icinga-module-windows.psm1
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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 = '';

Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/core/tools/New-IcingaCheckCommand.psm1
Expand Up @@ -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.';
Expand Down

0 comments on commit 843359d

Please sign in to comment.