Skip to content

Commit ce9257a

Browse files
committed
Improved code styling
1 parent 9adfe08 commit ce9257a

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

lib/core/tools/ConvertTo-IcingaIPv4BinaryString.psm1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ function ConvertTo-IcingaIPv4BinaryString()
2424
param(
2525
[string]$IP
2626
);
27+
2728
$IP = $IP -split '\.' | ForEach-Object {
28-
[System.Convert]::ToString($_,2).PadLeft(8,'0');
29+
[System.Convert]::ToString($_, 2).PadLeft(8, '0');
2930
}
3031
$IP = $IP -join '';
3132
$IP = $IP -replace '\s','';
3233

33-
return @{'value' = $IP; 'name' = 'IPv4'}
34-
}
34+
return @{
35+
'value' = $IP;
36+
'name' = 'IPv4'
37+
}
38+
}

lib/core/tools/ConvertTo-IcingaIPv6BinaryString.psm1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function ConvertTo-IcingaIPv6BinaryString()
2424
param(
2525
[string]$IP
2626
);
27-
[string]$IP = Expand-IcingaIPv6String $IP;
27+
[string]$IP = Expand-IcingaIPv6String $IP;
2828
[array]$IPArr = $IP.Split(':');
2929

3030
$IPArr = $IPArr.ToCharArray();
@@ -34,5 +34,8 @@ function ConvertTo-IcingaIPv6BinaryString()
3434
$IP = $IP -join '';
3535
$IP = $IP -replace '\s','';
3636

37-
return @{'value' = $IP; 'name' = 'IPv6'}
38-
}
37+
return @{
38+
'value' = $IP;
39+
'name' = 'IPv6'
40+
}
41+
}

lib/core/tools/Expand-IcingaIPv6String.psm1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ function Expand-IcingaIPv6String()
2828
[String]$IP
2929
);
3030

31-
$Counter = 0
32-
$RelV = -1
31+
$Counter = 0;
32+
$RelV = -1;
3333

34-
for($Index = 0; $Index -lt $IP.Length; $Index++) {
34+
for ($Index = 0; $Index -lt $IP.Length; $Index++) {
3535
if ($IP[$Index] -eq ':') {
36-
$Counter++
36+
$Counter++;
3737
if (($Index - 1) -ge 0 -and $IP[$Index - 1] -eq ':'){
38-
$RelV = $Index
38+
$RelV = $Index;
3939
}
4040
}
4141
}
@@ -46,7 +46,7 @@ function Expand-IcingaIPv6String()
4646
}
4747

4848
if ($Counter -lt 7) {
49-
$IP = $IP.Substring(0, $RelV) + (':'*(7 - $Counter)) + $IP.Substring($RelV)
49+
$IP = $IP.Substring(0, $RelV) + (':'*(7 - $Counter)) + $IP.Substring($RelV);
5050
}
5151

5252
$Result = @();
@@ -59,9 +59,9 @@ function Expand-IcingaIPv6String()
5959
[System.Globalization.CultureInfo]::InvariantCulture,
6060
[Ref]$Value
6161
) | Out-Null;
62-
$Result += ('{0:X4}' -f $Value)
62+
$Result += ('{0:X4}' -f $Value);
6363
}
6464
$Result = $Result -join ':';
6565

6666
return $Result;
67-
}
67+
}

lib/core/tools/Get-IcingaNetworkInterface.psm1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ function Get-IcingaNetworkInterface()
3131
[string]$IP
3232
);
3333

34+
if ([string]::IsNullOrEmpty($IP)) {
35+
Write-Host 'Please specify a valid IP-Address or FQDN';
36+
return $null;
37+
}
38+
3439
try {
3540
$IP = ([System.Net.Dns]::GetHostAddresses($IP)).IPAddressToString;
3641
} catch {
@@ -116,4 +121,4 @@ function Get-IcingaNetworkInterface()
116121
}
117122
}
118123
return ((Get-NetIPAddress -InterfaceIndex (Get-NetRoute | Where-Object -Property DestinationPrefix -like '0.0.0.0/0')[0].IfIndex -AddressFamily $IPBinStringMaster.name).IPAddress).split('%')[0];
119-
}
124+
}

0 commit comments

Comments
 (0)