Skip to content

Commit 0a2b39c

Browse files
authored
Merge pull request #298 from Icinga:feature/proper_isolating_of_functions_and_export_handling
Feature: Adds support for IfW 1.9.0 Adds support for Icinga for Windows v1.9.0 by adding the module isolation feature which now adds a compiled version of the module, only exporting public available functions instead of all functions.
2 parents 7cb6d38 + ac25708 commit 0a2b39c

31 files changed

+197
-256
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<#
2+
Icinga for Windows Component compilation file.
3+
Will be overwritten to defaults with every update and contains
4+
all code pre-compiled for faster execution and for providing
5+
private/public commands.
6+
7+
Fetches the current module and file location, reads all .psm1 files and compiles them into one large environment
8+
#>
9+
if ($null -eq (Get-Command -Name 'Write-IcingaForWindowsComponentCompilationFile' -ErrorAction SilentlyContinue)) {
10+
Write-Host '[' -NoNewline;
11+
Write-Host 'Error' -ForegroundColor Red -NoNewline;
12+
Write-Host ([string]::Format(']: Failed to compile Icinga for Windows component at location "{0}", because the required function "Write-IcingaForWindowsComponentCompilationFile" is not installed. Please ensure Icinga PowerShell Framework v1.9.0 or later is installed and try again.', $MyInvocation.MyCommand.Path));
13+
14+
return;
15+
}
16+
17+
Write-IcingaForWindowsComponentCompilationFile `
18+
-ScriptRootPath $PSScriptRoot `
19+
-CompiledFilePath ($MyInvocation.MyCommand.Path);

doc/31-Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1616
* [#283](https://github.com/Icinga/icinga-powershell-plugins/pull/283) Fixes random `Add-Type` exceptions during runtime compilation by replacing it with `Add-IcingaAddTypeLib`
1717
* [#286](https://github.com/Icinga/icinga-powershell-plugins/issues/286) Fixes `Invoke-IcingaCheckHTTPStatus` which is not returning the request time, in case the target website is not providing content
1818

19+
### Enhancements
20+
21+
* [#298](https://github.com/Icinga/icinga-powershell-plugins/pull/298) Adds support for Icinga for Windows v1.9.0 module isolation
22+
1923
## 1.8.0 (2022-02-08)
2024

2125
[Issue and PRs](https://github.com/Icinga/icinga-powershell-plugins/milestone/11?closed=1)

icinga-powershell-plugins.psd1

Lines changed: 43 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,85 +9,50 @@
99
PowerShellVersion = '4.0'
1010
RequiredModules = @(@{ModuleName = 'icinga-powershell-framework'; ModuleVersion = '1.9.0' })
1111
NestedModules = @(
12-
'.\plugins\Invoke-IcingaCheckBiosSerial.psm1',
13-
'.\plugins\Invoke-IcingaCheckCertificate.psm1',
14-
'.\plugins\Invoke-IcingaCheckCheckSum.psm1',
15-
'.\plugins\Invoke-IcingaCheckCPU.psm1',
16-
'.\plugins\Invoke-IcingaCheckDirectory.psm1',
17-
'.\plugins\Invoke-IcingaCheckDiskHealth.psm1',
18-
'.\plugins\Invoke-IcingaCheckEventlog.psm1',
19-
'.\plugins\Invoke-IcingaCheckFirewall.psm1',
20-
'.\plugins\Invoke-IcingaCheckHTTPStatus.psm1',
21-
'.\plugins\Invoke-IcingaCheckICMP.psm1',
22-
'.\plugins\Invoke-IcingaCheckMemory.psm1',
23-
'.\plugins\Invoke-IcingaCheckMPIO.psm1',
24-
'.\plugins\Invoke-IcingaCheckNetworkInterface.psm1',
25-
'.\plugins\Invoke-IcingaCheckNLA.psm1',
26-
'.\plugins\Invoke-IcingaCheckPerfcounter.psm1',
27-
'.\plugins\Invoke-IcingaCheckProcess.psm1',
28-
'.\plugins\Invoke-IcingaCheckProcessCount.psm1',
29-
'.\plugins\Invoke-IcingaCheckScheduledTask.psm1',
30-
'.\plugins\Invoke-IcingaCheckService.psm1',
31-
'.\plugins\Invoke-IcingaCheckStoragePool.psm1',
32-
'.\plugins\Invoke-IcingaCheckTCP.psm1',
33-
'.\plugins\Invoke-IcingaCheckTimeSync.psm1',
34-
'.\plugins\Invoke-IcingaCheckUNCPath.psm1',
35-
'.\plugins\Invoke-IcingaCheckUpdates.psm1',
36-
'.\plugins\Invoke-IcingaCheckUptime.psm1',
37-
'.\plugins\Invoke-IcingaCheckUsedPartitionSpace.psm1',
38-
'.\plugins\Invoke-IcingaCheckUsers.psm1',
39-
'.\provider\bios\Icinga_ProviderBios.psm1',
40-
'.\provider\bios\Show-IcingaBiosData.psm1',
41-
'.\provider\certificate\Icinga_ProviderCertificate.psm1',
42-
'.\provider\certificate\Test-IcingaCertificateExcludePattern.psm1',
43-
'.\provider\connection\Test-IcingaICMPConnection.psm1',
44-
'.\provider\cpu\Icinga_ProviderCpu.psm1',
45-
'.\provider\cpu\Show-IcingaCPUData.psm1',
46-
'.\provider\directory\Icinga_Provider_Directory.psm1',
47-
'.\provider\disks\Get-IcingaDiskAttributes.psm1',
48-
'.\provider\disks\Get-IcingaDiskPartitionAssignment.psm1',
49-
'.\provider\disks\Get-IcingaPartitionSpace.psm1',
50-
'.\provider\disks\Get-IcingaPhysicalDiskInfo.psm1',
51-
'.\provider\disks\Get-IcingaUNCPathSize.psm1',
52-
'.\provider\disks\Icinga_ProviderDisks.psm1',
53-
'.\provider\disks\Show-IcingaDiskData.psm1',
54-
'.\provider\enums\IcingaGeneralPlugins_Exceptions.psm1',
55-
'.\provider\enums\Icinga_ProviderEnums.psm1',
56-
'.\provider\eventlog\Get-IcingaEventLog.psm1',
57-
'.\provider\http\Get-IcingaCheckHTTPQuery.psm1',
58-
'.\provider\memory\Get-IcingaMemoryPerformanceCounter.psm1',
59-
'.\provider\memory\Get-IcingaMemoryUsage.psm1',
60-
'.\provider\memory\Icinga_ProviderMemory.psm1',
61-
'.\provider\memory\Show-IcingaMemoryData.psm1',
62-
'.\provider\mpio\Get-IcingaMPIOData.psm1',
63-
'.\provider\mpio\Test-IcingaMPIOInstalled.psm1',
64-
'.\provider\network\Get-IcingaNetworkDeviceInfo.psm1',
65-
'.\provider\network\Get-IcingaNetworkInterfaceTeamInfo.psm1',
66-
'.\provider\network\Get-IcingaNetworkSpeedChecks.psm1',
67-
'.\provider\network\Join-icingaNetworkDeviceDataPerfCounter.psm1',
68-
'.\provider\ntp\Get-IcingaNtpData.psm1',
69-
'.\provider\process\Icinga_ProviderProcess.psm1',
70-
'.\provider\services\Add-IcingaServiceSummary.psm1',
71-
'.\provider\services\ConvertTo-ServiceStatusCode.psm1',
72-
'.\provider\services\Get-IcingaServiceCheckName.psm1',
73-
'.\provider\services\New-IcingaWindowsServiceCheckObject.psm1',
74-
'.\provider\storage\Get-IcingaConvertToGigaByte.psm1',
75-
'.\provider\storage\Get-IcingaStoragePoolInfo.psm1',
76-
'.\provider\tasks\Get-IcingaScheduledTask.psm1',
77-
'.\provider\tasks\New-IcingaTaskObject.psm1',
78-
'.\provider\tcp\Measure-IcingaTCPConnection.psm1',
79-
'.\provider\updates\Get-IcingaUpdatesHotfix.psm1',
80-
'.\provider\updates\Get-IcingaUpdatesInstalled.psm1',
81-
'.\provider\updates\Get-IcingaWindowsUpdatesPending.psm1',
82-
'.\provider\users\Get-IcingaLoggedOnUsers.psm1',
83-
'.\provider\users\Get-IcingaUsers.psm1',
84-
'.\provider\windows\Icinga_ProviderWindows.psm1',
85-
'.\provider\windows\Show-IcingaWindowsData.psm1'
12+
'.\compiled\icinga-powershell-plugins.ifw_compilation.psm1'
13+
)
14+
FunctionsToExport = @(
15+
'Import-IcingaPowerShellComponentPlugins',
16+
'Invoke-IcingaCheckBiosSerial',
17+
'Invoke-IcingaCheckCertificate',
18+
'Invoke-IcingaCheckCheckSum',
19+
'Invoke-IcingaCheckCPU',
20+
'Invoke-IcingaCheckDirectory',
21+
'Invoke-IcingaCheckDiskHealth',
22+
'Invoke-IcingaCheckEventlog',
23+
'Invoke-IcingaCheckFirewall',
24+
'Invoke-IcingaCheckHTTPStatus',
25+
'Invoke-IcingaCheckICMP',
26+
'Invoke-IcingaCheckMemory',
27+
'Invoke-IcingaCheckMPIO',
28+
'Invoke-IcingaCheckNetworkInterface',
29+
'Invoke-IcingaCheckNLA',
30+
'Invoke-IcingaCheckPerfCounter',
31+
'Invoke-IcingaCheckProcess',
32+
'Invoke-IcingaCheckProcessCount',
33+
'Invoke-IcingaCheckScheduledTask',
34+
'Invoke-IcingaCheckService',
35+
'Invoke-IcingaCheckStoragePool',
36+
'Invoke-IcingaCheckTCP',
37+
'Invoke-IcingaCheckTimeSync',
38+
'Invoke-IcingaCheckUNCPath',
39+
'Invoke-IcingaCheckUpdates',
40+
'Invoke-IcingaCheckUptime',
41+
'Invoke-IcingaCheckPartitionSpace',
42+
'Invoke-IcingaCheckUsedPartitionSpace',
43+
'Invoke-IcingaCheckUsers',
44+
'Get-IcingaCPUCount',
45+
'Get-IcingaPhysicalDiskInfo',
46+
'Get-IcingaMemoryPerformanceCounter'
47+
)
48+
CmdletsToExport = @(
49+
)
50+
VariablesToExport = @(
51+
'ProviderEnums',
52+
'IcingaPluginExceptions'
53+
)
54+
AliasesToExport = @(
8655
)
87-
FunctionsToExport = @('*')
88-
CmdletsToExport = @('*')
89-
VariablesToExport = '*'
90-
AliasesToExport = @( '*' )
9156
PrivateData = @{
9257
PSData = @{
9358
Tags = @( 'icinga', 'icinga2', 'monitoringplugins', 'icingaplugins', 'icinga2plugins', 'windowsplugins', 'icingawindows')

icinga-powershell-plugins.psm1

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
1-
function Use-IcingaPlugins()
1+
function Import-IcingaPowerShellComponentPlugins()
22
{
3-
Import-IcingaPlugins -Directory 'provider';
3+
# Allows other components to load this component
44
}
55

6-
function Import-IcingaPlugins()
7-
{
8-
param (
9-
[Parameter(
10-
Position=0,
11-
Mandatory=$true,
12-
ValueFromPipeline=$true,
13-
ValueFromPipelineByPropertyName=$true)
14-
]
15-
[String]$Directory
16-
);
17-
18-
[string]$module = Join-Path -Path $PSScriptRoot -ChildPath $Directory;
19-
20-
if ((Test-Path $module) -eq $FALSE) {
21-
return;
22-
}
23-
24-
# Load modules from directory
25-
if ((Test-Path $module -PathType Container)) {
26-
Get-ChildItem -Path $module -Recurse -Filter *.psm1 |
27-
ForEach-Object {
28-
[string]$modulePath = $_.FullName;
29-
Import-Module ([string]::Format('{0}', $modulePath)) -Global;
30-
}
31-
} else {
32-
$module = $module.Replace('.psm1', ''); # Cut possible .psm1 ending
33-
Import-Module ([string]::Format('{0}.psm1', $module)) -Global;
34-
}
35-
}
6+
Export-ModuleMember -Variable @('ProviderEnums', 'IcingaPluginExceptions');

provider/bios/Icinga_ProviderBios.psm1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Import-IcingaLib provider\enums;
21
function Get-IcingaBios()
32
{
43
<# Collects the most important BIOS informations,

provider/cpu/Icinga_ProviderCpu.psm1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Import-IcingaLib provider\enums;
21
function Get-IcingaCPUs()
32
{
43
<# Collects the most important CPU informations,
@@ -258,7 +257,7 @@ function Get-IcingaCPUNumberOfLogicalProcessors()
258257
return @{'value' = $CPUNumberOfLogicalProcessors; 'name' = 'NumberOfLogicalProcessors'};
259258
}
260259

261-
function Get-IcingaCPUCount()
260+
function Global:Get-IcingaCPUCount()
262261
{
263262
param (
264263
$CounterArray = $null

provider/directory/Icinga_Provider_Directory.psm1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Import-IcingaLib core\tools;
2-
31
function Get-IcingaDirectoryAll()
42
{
53
param(

provider/disks/Get-IcingaPhysicalDiskInfo.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
https://github.com/Icinga/icinga-powershell-framework
2121
#>
2222

23-
function Get-IcingaPhysicalDiskInfo()
23+
function Global:Get-IcingaPhysicalDiskInfo()
2424
{
2525
param (
2626
[array]$DiskIds = @()

provider/disks/Icinga_ProviderDisks.psm1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Import-IcingaLib provider\enums;
2-
31
function Get-IcingaDiskInformation()
42
{
53
<# Fetches the information for other more specific Get-IcingaDisk-functions

provider/enums/IcingaGeneralPlugins_Exceptions.psm1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ if ($null -eq $IcingaPluginExceptions) {
1414
FileSystem = $FileSystem;
1515
}
1616
}
17-
18-
Export-ModuleMember -Variable @( 'IcingaPluginExceptions' );

provider/enums/Icinga_ProviderEnums.psm1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,5 +1085,3 @@
10851085
LoadBalancingAlgorithm = $LoadBalancingAlgorithm;
10861086
LoadBalancingAlgorithmName = $LoadBalancingAlgorithmName;
10871087
}
1088-
1089-
Export-ModuleMember -Variable @('ProviderEnums');

provider/eventlog/Get-IcingaEventLog.psm1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Import-IcingaLib icinga\exception;
2-
31
function Get-IcingaEventLog()
42
{
53
param(

provider/memory/Get-IcingaMemoryPerformanceCounter.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Get-IcingaMemoryPerformanceCounter()
1+
function Global:Get-IcingaMemoryPerformanceCounter()
22
{
33

44
if ((Test-IcingaPerformanceCounterCategory -Category 'Memory') -eq $FALSE) {

provider/memory/Icinga_ProviderMemory.psm1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Import-IcingaLib provider\enums;
21
function Get-IcingaMemory()
32
{
43
<# Collects the most important Memory informations,

0 commit comments

Comments
 (0)