Fixes multi interface support on interface discover

* Fixes issue on hosts with mulitple interfaces that provide virtual
interfaces, causing problems on Director Self-Service creation
* Adds support for Windows 2008 R2
This commit is contained in:
Lord Hepipud 2020-04-17 16:24:25 +02:00
parent 77815898e2
commit 162f8102fb
3 changed files with 56 additions and 4 deletions

View file

@ -13,6 +13,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Bugfixes
* [#059](https://github.com/Icinga/icinga-powershell-framework/issues/059), [#060](https://github.com/Icinga/icinga-powershell-framework/pull/060) Fixes interface handling for multiple interfaces and returns only the main interface by fallback to routing table and adds support for Windows 2008 R2
* [#127](https://github.com/Icinga/icinga-powershell-framework/issues/127) Fixes wrong error message on failed MSSQL connection due to database not reachable by using `-IntegratedSecurity`
* [#128](https://github.com/Icinga/icinga-powershell-framework/issues/128) Fixes unhandled output from loading `System.Reflection.Assembly` which can cause weird side effects for plugin outputs
* [#130](https://github.com/Icinga/icinga-powershell-framework/issues/130) Fix crash while running services as background task to collect metrics over time by missing Performance Counter cache initialisation

View file

@ -36,6 +36,13 @@ function Get-IcingaNetworkInterface()
return $null;
}
# Ensure that we can still process on older Windows system where
# Get-NetRoute ist not available
if ((Test-IcingaFunction 'Get-NetRoute') -eq $FALSE) {
Write-IcingaConsoleWarning 'Your Windows system does not support "Get-NetRoute". A fallback solution is used to fetch the IP of the first Network Interface routing through 0.0.0.0'
return (Get-IcingaNetworkRoute).Interface;
}
try {
[array]$IP = ([System.Net.Dns]::GetHostAddresses($IP)).IPAddressToString;
} catch {
@ -151,13 +158,20 @@ function Get-IcingaNetworkInterface()
}
$InternalCount = 0;
$UseInterface = '';
[array]$UseInterface = @();
foreach ($interface in $ExternalInterfaces.Keys) {
$currentCount = $ExternalInterfaces[$interface].count;
if ($currentCount -gt $InternalCount) {
$InternalCount = $currentCount;
$UseInterface = $interface;
$UseInterface += $interface;
}
}
return $UseInterface;
# In case we found multiple interfaces, fallback to our
# 'route print' function and return this interface instead
if ($UseInterface.Count -ne 1) {
return (Get-IcingaNetworkRoute).Interface;
}
return $UseInterface[0];
}

View file

@ -0,0 +1,37 @@
<#
.SYNOPSIS
Fetch the used interface for our Windows System
.DESCRIPTION
Newer Windows systems provide a Cmdlet 'Get-NetRoute' for fetching the
network route configurations. Older systems however do not provide this
and to ensure some sort of backwards compatibility, we will have a look
on our route configuration and return the first valid interface found
.FUNCTIONALITY
This Cmdlet will return first valid IP for our interface
.EXAMPLE
PS>Get-IcingaNetworkRoute
.OUTPUTS
System.Array
.LINK
https://github.com/Icinga/icinga-powershell-framework
.NOTES
#>
function Get-IcingaNetworkRoute()
{
$RouteConfig = (&route print | Where-Object {
$_.TrimStart() -Like "0.0.0.0*";
}).Split() | Where-Object {
return $_;
};
$Interface = @{
'Destination' = $RouteConfig[0];
'Netmask' = $RouteConfig[1];
'Gateway' = $RouteConfig[2];
'Interface' = $RouteConfig[3];
'Metric' = $RouteConfig[4];
}
return $Interface;
}