Skip to content

Commit 3d87563

Browse files
committed
Feature Requests: Add Proxy Server support
Also re-arranges web content by using old content from lib/web into lib/webserver, while new lib/web contains the proxy configuration. Fixes #19
1 parent 8302903 commit 3d87563

36 files changed

+262
-19
lines changed

doc/06-Framework-Usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The Icinga PowerShell Framework ships with a bunch of Cmdlets for monitoring, me
55
## Framework Management
66

77
* [Automated Framework and Component deployment](frameworkusage/01-Automated-Framework-and-Component-Deployment.md)
8+
* [Enable Proxy Server](frameworkusage/02-Enable-Proxy-Server.md)
89

910
## Icinga Agent Management
1011

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1313

1414
### Enhancements
1515

16+
* [#19](https://github.com/Icinga/icinga-powershell-framework/issues/19) Add support for proxy servers for web calls and re-arranges content from lib/web to lib/webserver and uses lib/web for new proxy/web calls
1617
* [#136](https://github.com/Icinga/icinga-powershell-framework/pull/136) Adds support to ignore empty check packages and return `Ok` instead of `Unknown` if `-IgnoreEmptyPackage` is set on `New-IcingaCheckPackage`
1718
* [#137](https://github.com/Icinga/icinga-powershell-framework/issues/137) Adds Cmdlet to compare a DateTime object with the current DateTime and return the offset as Integer in seconds
1819
* [#139](https://github.com/Icinga/icinga-powershell-framework/pull/139) Add Cmdlet `Start-IcingaShellAsUser` to open an Icinga Shell as different user for testing
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Enable Proxy Server
2+
3+
With Icinga PowerShell Framework v1.3.0 we added support for using Proxy servers while using web requests to download and fetch information. For this we added a custom function `Invoke-IcingaWebRequest` as wrapper function for `Invoke-WebRequest`.
4+
5+
## Enable Proxy Server Support
6+
7+
To enable the proxy server support, you simply have to use the Cmdlet `Set-IcingaFrameworkProxyServer` and set your proxy server:
8+
9+
```powershell
10+
Set-IcingaFrameworkProxyServer -Server 'http://example.com:8080';
11+
```
12+
13+
Once set, the Framework will automatically use this server configuration for all web requests.
14+
15+
## Disable Proxy Server Support
16+
17+
To disable the proxy server, you can use the same Cmdlet again, but leaving the argument empty.
18+
19+
```powershell
20+
Set-IcingaFrameworkProxyServer;
21+
```
22+
23+
Now all web requests are executed without the proxy server.

lib/apis/Get-IcingaDirectorSelfServiceConfig.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function Get-IcingaDirectorSelfServiceConfig()
4242

4343
$EndpointUrl = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/powershell-parameters?key={0}', $ApiKey));
4444

45-
$response = Invoke-WebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST';
45+
$response = Invoke-IcingaWebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST';
4646

4747
if ($response.StatusCode -ne 200) {
4848
throw $response.Content;

lib/apis/Get-IcingaDirectorSelfServiceTicket.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function Get-IcingaDirectorSelfServiceTicket()
4242

4343
[string]$url = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/ticket?key={0}', $ApiKey));
4444

45-
$response = Invoke-WebRequest -Uri $url -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST';
45+
$response = Invoke-IcingaWebRequest -Uri $url -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST';
4646

4747
if ($response.StatusCode -ne 200) {
4848
throw $response.Content;

lib/apis/Register-IcingaDirectorSelfServiceHost.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function Register-IcingaDirectorSelfServiceHost()
6060

6161
$EndpointUrl = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/register-host?name={0}&key={1}', $Hostname, $ApiKey));
6262

63-
$response = Invoke-WebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST' -Body $DirectorConfigJson;
63+
$response = Invoke-IcingaWebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST' -Body $DirectorConfigJson;
6464

6565
if ($response.StatusCode -ne 200) {
6666
throw $response.Content;

lib/core/framework/Get-IcingaFrameworkServiceBinary.psm1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function Get-IcingaFrameworkServiceBinary()
3636

3737
if ([string]::IsNullOrEmpty($FrameworkServiceUrl)) {
3838
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you provide a custom source of the service binary?' -Default 'n').result -eq 1) {
39-
$LatestRelease = (Invoke-WebRequest -Uri 'https://github.com/Icinga/icinga-powershell-service/releases/latest' -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
39+
$LatestRelease = (Invoke-IcingaWebRequest -Uri 'https://github.com/Icinga/icinga-powershell-service/releases/latest' -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
4040
$FrameworkServiceUrl = $LatestRelease.Replace('/tag/', '/download/');
4141
$Tag = $FrameworkServiceUrl.Split('/')[-1];
4242
$FrameworkServiceUrl = [string]::Format('{0}/icinga-service-{1}.zip', $FrameworkServiceUrl, $Tag);
@@ -64,9 +64,7 @@ function Get-IcingaFrameworkServiceBinary()
6464
$UpdateBin = Join-Path -Path $ServiceDirectory -ChildPath 'icinga-service.exe.update';
6565
$ServiceBin = Join-Path -Path $ServiceDirectory -ChildPath 'icinga-service.exe';
6666

67-
try {
68-
Invoke-WebRequest -Uri $FrameworkServiceUrl -UseBasicParsing -OutFile $ZipArchive;
69-
} catch {
67+
if ((Invoke-IcingaWebRequest -Uri $FrameworkServiceUrl -UseBasicParsing -OutFile $ZipArchive).HasErrors) {
7068
Write-IcingaConsoleError -Message 'Failed to download the Icinga Service Binary from "{0}". Please try again.' -Objects $FrameworkServiceUrl;
7169
return Get-IcingaFrameworkServiceBinary;
7270
}

lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ function Get-IcingaPowerShellModuleArchive()
7070
if ($branch.ToLower() -eq 'snapshot') {
7171
$DownloadUrl = [string]::Format('https://github.com/{0}/{1}/archive/master.zip', $GitHubUser, $Repository);
7272
} else {
73-
try {
74-
$LatestRelease = (Invoke-WebRequest -Uri ([string]::Format('https://github.com/{0}/{1}/releases/latest', $GitHubUser, $Repository)) -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
73+
$WebResponse = Invoke-IcingaWebRequest -Uri 'https://github.com/{0}/{1}/releases/latest' -Objects $GitHubUser, $Repository -UseBasicParsing;
74+
75+
if ($WebResponse.HasErrors -eq $FALSE) {
76+
$LatestRelease = $WebResponse.BaseResponse.ResponseUri.AbsoluteUri;
7577
$DownloadUrl = $LatestRelease.Replace('/releases/tag/', '/archive/');
7678
$Tag = $DownloadUrl.Split('/')[-1];
77-
} catch {
79+
} else {
7880
Write-IcingaConsoleError -Message 'Failed to fetch latest release for "{0}" from GitHub. Either the module or the GitHub account do not exist' -Objects $ModuleName;
7981
}
8082

@@ -110,13 +112,11 @@ function Get-IcingaPowerShellModuleArchive()
110112
};
111113
}
112114

113-
try {
114-
$DownloadDirectory = New-IcingaTemporaryDirectory;
115-
$DownloadDestination = (Join-Path -Path $DownloadDirectory -ChildPath ([string]::Format('{0}.zip', $Repository)));
116-
Write-IcingaConsoleNotice ([string]::Format('Downloading "{0}" into "{1}"', $ModuleName, $DownloadDirectory));
115+
$DownloadDirectory = New-IcingaTemporaryDirectory;
116+
$DownloadDestination = (Join-Path -Path $DownloadDirectory -ChildPath ([string]::Format('{0}.zip', $Repository)));
117+
Write-IcingaConsoleNotice ([string]::Format('Downloading "{0}" into "{1}"', $ModuleName, $DownloadDirectory));
117118

118-
Invoke-WebRequest -UseBasicParsing -Uri $DownloadUrl -OutFile $DownloadDestination;
119-
} catch {
119+
if ((Invoke-IcingaWebRequest -UseBasicParsing -Uri $DownloadUrl -OutFile $DownloadDestination).HasErrors) {
120120
Write-IcingaConsoleError ([string]::Format('Failed to download "{0}" into "{1}". Starting cleanup process', $ModuleName, $DownloadDirectory));
121121
Start-Sleep -Seconds 2;
122122
Remove-Item -Path $DownloadDirectory -Recurse -Force;

lib/core/icingaagent/getters/Get-IcingaAgentMSIPackage.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function Get-IcingaAgentMSIPackage()
2121
$LastUpdate = $null;
2222

2323
if ($Version -eq 'snapshot' -Or $Version -eq 'release') {
24-
$Content = (Invoke-WebRequest -Uri $Source -UseBasicParsing).RawContent.Split("`r`n");
24+
$Content = (Invoke-IcingaWebRequest -Uri $Source -UseBasicParsing).RawContent.Split("`r`n");
2525
$UsePackage = $null;
2626

2727
foreach ($line in $Content) {
@@ -62,7 +62,7 @@ function Get-IcingaAgentMSIPackage()
6262
if ($SkipDownload -eq $FALSE) {
6363
$DownloadPath = Join-Path $Env:TEMP -ChildPath $UsePackage;
6464
Write-IcingaConsoleNotice ([string]::Format('Downloading Icinga 2 Agent installer "{0}" into temp directory "{1}"', $UsePackage, $DownloadPath));
65-
Invoke-WebRequest -Uri (Join-WebPath -Path $Source -ChildPath $UsePackage) -OutFile $DownloadPath;
65+
Invoke-IcingaWebRequest -Uri (Join-WebPath -Path $Source -ChildPath $UsePackage) -OutFile $DownloadPath;
6666
}
6767

6868
return @{

lib/core/icingaagent/installer/Install-IcingaAgentCertificates.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ function Copy-IcingaAgentCACertificate()
272272
Set-IcingaTLSVersion;
273273
# It could also be a web ressource
274274
try {
275-
$response = Invoke-WebRequest $CAPath -UseBasicParsing;
275+
$response = Invoke-IcingaWebRequest $CAPath -UseBasicParsing;
276276
[int]$Index = $response.RawContent.IndexOf("`r`n`r`n") + 4;
277277

278278
[string]$CAContent = $response.RawContent.SubString(

0 commit comments

Comments
 (0)