mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-22 23:59:46 -05:00
Merge branch 'master' into feature/support_knowledgebase_id_on_exception
This commit is contained in:
commit
8a0cddccc2
47 changed files with 378 additions and 30 deletions
|
|
@ -5,6 +5,7 @@ The Icinga PowerShell Framework ships with a bunch of Cmdlets for monitoring, me
|
|||
## Framework Management
|
||||
|
||||
* [Automated Framework and Component deployment](frameworkusage/01-Automated-Framework-and-Component-Deployment.md)
|
||||
* [Enable Proxy Server](frameworkusage/02-Enable-Proxy-Server.md)
|
||||
|
||||
## Icinga Agent Management
|
||||
|
||||
|
|
@ -12,3 +13,4 @@ The Icinga PowerShell Framework ships with a bunch of Cmdlets for monitoring, me
|
|||
* [Read Icinga Agent Log/DebugLog](frameworkusage/31-Read-Icinga-Agent_Log_DebugLog.md)
|
||||
* [Test Icinga Agent Environment](frameworkusage/32-Test-Icinga-Agent-Environment.md)
|
||||
* [Run Icinga Agent as other Service User](frameworkusage/33-Run-Icinga-Agent-As-Other-Service-User.md)
|
||||
* [Uninstall Icinga Agent](frameworkusage/34-Uninstall-Icinga-Agent.md)
|
||||
|
|
|
|||
|
|
@ -10,3 +10,4 @@ For this reason you will find a list of Icinga knowledge base entries below. Ent
|
|||
| --- | --- |
|
||||
| [IWKB000001](knowledgebase/IWKB000001.md) | The user you are running this command as does not have permission to access the requested Cim-Object. To fix this, please add the user the Agent is running with to the "Remote Management Users" groups and grant access to the WMI branch for the Class/Namespace mentioned above and add the permission "Remote enable". |
|
||||
| [IWKB000002](knowledgebase/IWKB000002.md) | Plugin execution fails because arguments could not be validated and properly set. An example error could be `The "*" was not recognized as the name of a program, cmdlet, function, script file, or executable. Check the spelling of the name and that the path is correct (if included), and repeat the process.` |
|
||||
| [IWKB000003](knowledgebase/IWKB000003.md) | The Icinga Agent service `icinga2` cannot be started/modified/added because it is marked for deletion. |
|
||||
|
|
@ -6,7 +6,15 @@ Specific version upgrades are described below. Please note that version updates
|
|||
|
||||
## Upgrading to v1.3.0 (pending)
|
||||
|
||||
*No special steps required*
|
||||
### Breaking Changes
|
||||
|
||||
#### Components
|
||||
|
||||
* Please have a look on the changes made on the [Icinga PowerShell Plugins](https://icinga.com/docs/windows/latest/plugins/doc/30-Upgrading-Plugins/) for a smooth upgrade process
|
||||
|
||||
#### Icinga PowerShell Kickstart
|
||||
|
||||
* In order to be able to use the [Icinga PowerShell Kickstart Script](https://github.com/Icinga/icinga-powershell-kickstart) with v1.3.0 of the Icinga PowerShell Framework, you will have to upgrade the kickstart script to [v1.2.0](https://github.com/Icinga/icinga-powershell-kickstart/releases)
|
||||
|
||||
## Upgrading to v1.2.0 (2020-08-28)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
|||
|
||||
### Enhancements
|
||||
|
||||
* [#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
|
||||
* [#121](https://github.com/Icinga/icinga-powershell-framework/issues/121) Adds feature allowing sharing of local variables with Icinga Shell, by using `-ArgumentList`. They can then be accessed by using `$IcingaShellArgs` with the correct array index id, following the order of items added to `-ArgumentList`
|
||||
* [#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`
|
||||
* [#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
|
||||
* [#139](https://github.com/Icinga/icinga-powershell-framework/pull/139) Add Cmdlet `Start-IcingaShellAsUser` to open an Icinga Shell as different user for testing
|
||||
|
|
@ -21,6 +23,9 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
|||
* [#142](https://github.com/Icinga/icinga-powershell-framework/pull/142) **Experimental:** Adds feature to cache the Framework code into a single file to speed up the entire loading process, mitigating the impact on performance on systems with few CPU cores. You enable disables this feature by using `Enable-IcingaFrameworkCodeCache` and `Disable-IcingaFrameworkCodeCache`. Updating the cache is done with `Write-IcingaFrameworkCodeCache`
|
||||
* [#149](https://github.com/Icinga/icinga-powershell-framework/pull/149) Adds support to add Wmi permissions for a specific user and namespace with `Add-IcingaWmiPermissions`. In addition you can remove users from Wmi namespaces by using `Remove-IcingaWmiPermissions`
|
||||
* [#153](https://github.com/Icinga/icinga-powershell-framework/pull/153) Adds support to add a knowledge base id to `Exit-IcingaThrowException` for easier referencing. This should mostly be used for custom messages, as we should track the main knowledge base id's inside the messages directly. Native messages should be split in a hashtable with a `Message` and `IWKB` key
|
||||
* [#155](https://github.com/Icinga/icinga-powershell-framework/pull/155) Adds support to write all objects collected by `Get-IcingaWindowsInformation` into the Windows EventLog in case the debug output for the Icinga PowerShell Framework is enabled.
|
||||
* [#162](https://github.com/Icinga/icinga-powershell-framework/pull/162) Adds feature to test the length of plugin custom variables during config generation and throws error in case the total length is bigger than 64 digits, as imports into the Icinga Director by using baskets is not possible otherwise
|
||||
* [#164](https://github.com/Icinga/icinga-powershell-framework/pull/164) Adds `exit` after calling `icinga` on Windows Terminal integration to ensure the shell will close in case the Icinga shell is closed
|
||||
|
||||
### Bugfixes
|
||||
|
||||
|
|
@ -34,6 +39,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
|||
* [#140](https://github.com/Icinga/icinga-powershell-framework/issues/140) Fixes version fetching for not loaded modules during upgrades/plugin calls with `Get-IcingaPowerShellModuleVersion`
|
||||
* [#143](https://github.com/Icinga/icinga-powershell-framework/issues/143) Fixes the annoying hint from the analyzer to check space before open brace
|
||||
* [#152](https://github.com/Icinga/icinga-powershell-framework/issues/152) Fixes incorrect rendering for empty arrays which used `$null` incorrectly instead of `@()` and fixed ValidateSet which now also supports arrays as data type
|
||||
* [#159](https://github.com/Icinga/icinga-powershell-framework/pull/159) Fixes crash during update of the Icinga Framework, caused by the newly introduced experimental feature for code caching
|
||||
|
||||
## 1.2.0 (2020-08-28)
|
||||
|
||||
|
|
|
|||
23
doc/frameworkusage/02-Enable-Proxy-Server.md
Normal file
23
doc/frameworkusage/02-Enable-Proxy-Server.md
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Enable Proxy Server
|
||||
|
||||
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`.
|
||||
|
||||
## Enable Proxy Server Support
|
||||
|
||||
To enable the proxy server support, you simply have to use the Cmdlet `Set-IcingaFrameworkProxyServer` and set your proxy server:
|
||||
|
||||
```powershell
|
||||
Set-IcingaFrameworkProxyServer -Server 'http://example.com:8080';
|
||||
```
|
||||
|
||||
Once set, the Framework will automatically use this server configuration for all web requests.
|
||||
|
||||
## Disable Proxy Server Support
|
||||
|
||||
To disable the proxy server, you can use the same Cmdlet again, but leaving the argument empty.
|
||||
|
||||
```powershell
|
||||
Set-IcingaFrameworkProxyServer;
|
||||
```
|
||||
|
||||
Now all web requests are executed without the proxy server.
|
||||
33
doc/frameworkusage/34-Uninstall-Icinga-Agent.md
Normal file
33
doc/frameworkusage/34-Uninstall-Icinga-Agent.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Uninstall Icinga Agent
|
||||
|
||||
While the main purpose of the Icinga for Windows solution is check your systems and provided all required tools, including the Icinga Agent, it might be required to entirely uninstall the Icinga Agent. This sometimes might even include to flush the entire `ProgramData` folder, where certificates and other configurations are stored.
|
||||
|
||||
**Note:** Before using any of the commands below you will have to initialize the Icinga PowerShell Framework inside a new PowerShell instance with `Use-Icinga`. Starting with version `1.2.0` of the Framework you can also simply type `icinga` into the command line.
|
||||
|
||||
## Uninstalling the Icinga Agent
|
||||
|
||||
### Keep ProgramData Content
|
||||
|
||||
If you only want to uninstall the Icinga Agent itself, but keep configuration files and certificates, you can use the `Uninstall-IcingaAgent` Cmdlet.
|
||||
|
||||
```powershell
|
||||
Uninstall-IcingaAgent;
|
||||
```
|
||||
|
||||
By default there are not special arguments required and once completed you will be prompted with a message that the Icinga Agent has been removed
|
||||
|
||||
### Remove ProgramData Content
|
||||
|
||||
In some cases it might be helpful for troubleshooting to uninstall the Icinga Agent entirely, including the `ProgramData` content. We can do this with the same command, but add another argument:
|
||||
|
||||
```powershell
|
||||
Uninstall-IcingaAgent -RemoveDataFolder;
|
||||
```
|
||||
|
||||
Now the Icinga Agent will be installed and afterwards the entire content at `C:\ProgramData\ICINGA2` will be deleted.
|
||||
|
||||
**Note**: If you missed to add `-RemoveDataFolder` on your first attempt, you can run the command with the argument set again. In case the Icinga Agent is not installed, this part will be skipped and the `ProgramData` folder content will be flushed.
|
||||
|
||||
## Icinga Agent Service is "Marked for Deletion"
|
||||
|
||||
This issue can happen during installation/uninstallation/upgrading processes. We have written the [Knowledge Base Article IWKB000003](../knowledgebase/IWKB000003.md) for this scenario.
|
||||
|
|
@ -31,7 +31,7 @@ Get-IcingaCheckCommandConfig -CheckName Invoke-IcingaCheckBiosSerial, Invoke-Ici
|
|||
Last but not least you can output the JSON-Basket directly into a file. To do this, simply use the `OutDirectory` argument. You only require to specify a directory here, as the file including a timestamp is generated by the Cmdlet itself
|
||||
|
||||
```powershell
|
||||
Get-IcingaCheckCommandConfig -OutDirectory 'C:\Users\myuser\Documents\
|
||||
Get-IcingaCheckCommandConfig -OutDirectory 'C:\Users\myuser\Documents\'
|
||||
```
|
||||
|
||||
Once the file is exported, you can navigate to your Icinga Director Basket menu and import the generated file. Afterwards all specified Check-Commands are available and ready to use
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ To install the Icinga Shell as native shell in your Windows Terminal dropdown, s
|
|||
|
||||
"guid": "{fcd7a805-a41b-49f9-afee-9d17a2b76d42}",
|
||||
"name": "Icinga",
|
||||
"commandline" : "powershell.exe -noe -c \"&{ icinga }\"",
|
||||
"commandline" : "powershell.exe -noe -c \"&{ icinga; exit }\"",
|
||||
"hidden": false,
|
||||
"icon" : "ms-appdata:///roaming/icingawhite.png",
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,20 @@ Add-IcingaWmiPermissions -User 'icinga' -Namespace 'root\Microsoft\Windows\Stora
|
|||
|
||||
The above command will grant the user `icinga` the read and remote access permission for the `root\Microsoft\Windows\Storage` namespace. In addition by using `-Recurse` we will set the permissions for `subnamespaces` in addition.
|
||||
|
||||
To fully apply the changes, it might be required to restart the Wmi service `Winmgmt`. How ever, you are running a Hyper-V server for example, the command
|
||||
|
||||
```powershell
|
||||
Restart-Service Winmgmt;
|
||||
```
|
||||
|
||||
might return an error, because this service has dependencies for other services. To enforce this, you can run
|
||||
|
||||
```powershell
|
||||
Restart-Service Winmgmt -Force;
|
||||
```
|
||||
|
||||
which will restart this and all other depending services. Please ensure that this is done while doing maintenance on the systems to not interrupt production services.
|
||||
|
||||
### Permission Table
|
||||
|
||||
| Flag | Description |
|
||||
|
|
|
|||
26
doc/knowledgebase/IWKB000003.md
Normal file
26
doc/knowledgebase/IWKB000003.md
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Icinga Knowledge Base - IWKB000003
|
||||
|
||||
## Short Message
|
||||
|
||||
The service cannot be started/modified/added because it is marked for deletion. Re-Installing the Icinga Agent fails and starting it is also not possible.
|
||||
|
||||
## Example Exception
|
||||
|
||||
The service cannot be started because it is marked for deletion.
|
||||
|
||||
## Reason
|
||||
|
||||
In some edge cases it can happen that the `icinga2` service is not removed during an upgrade or uninstallation process. The reason for this is that another tool might have a `lock` on the service, preventing Windows from deleting it. For example this could be the `services` window on where you can manage service, like restarting them or a PowerShell instance you used to work with to modify the service itself.
|
||||
|
||||
## Solution
|
||||
|
||||
The easiest way of course is to simply reboot the system - this will remove any lock on the service and once Windows is rebooted, the service is deleted.
|
||||
|
||||
As this solution is how ever not really usable in enterprise environments, the best approach would be to close all windows which could interact with the service or you interacted with. This includes:
|
||||
|
||||
* Windows Task Manager
|
||||
* PowerShell / Cmd instances
|
||||
* Services.msc
|
||||
* Visual Studio Code / PowerShell ISE (because of the PowerShell instance)
|
||||
|
||||
Once you found the tool locking the service, it will be removed and you can reinstall the Icinga Agent properly.
|
||||
|
|
@ -314,7 +314,8 @@ function Invoke-IcingaCommand()
|
|||
[CmdletBinding()]
|
||||
param (
|
||||
$ScriptBlock,
|
||||
[switch]$SkipHeader = $FALSE
|
||||
[switch]$SkipHeader = $FALSE,
|
||||
[array]$ArgumentList = @()
|
||||
);
|
||||
|
||||
Import-LocalizedData `
|
||||
|
|
@ -336,9 +337,10 @@ function Invoke-IcingaCommand()
|
|||
}
|
||||
|
||||
powershell.exe -NoExit -Command {
|
||||
$Script = $args[0];
|
||||
$RootPath = $args[1];
|
||||
$Version = $args[2];
|
||||
$Script = $args[0];
|
||||
$RootPath = $args[1];
|
||||
$Version = $args[2];
|
||||
$IcingaShellArgs = $args[3];
|
||||
|
||||
# Load our Icinga Framework
|
||||
Use-Icinga;
|
||||
|
|
@ -361,7 +363,7 @@ function Invoke-IcingaCommand()
|
|||
return "> "
|
||||
}
|
||||
|
||||
} -Args $ScriptBlock, $PSScriptRoot, $IcingaFrameworkData.PrivateData.Version;
|
||||
} -Args $ScriptBlock, $PSScriptRoot, $IcingaFrameworkData.PrivateData.Version, $ArgumentList;
|
||||
}
|
||||
|
||||
function Start-IcingaShellAsUser()
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ function Get-IcingaDirectorSelfServiceConfig()
|
|||
|
||||
$EndpointUrl = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/powershell-parameters?key={0}', $ApiKey));
|
||||
|
||||
$response = Invoke-WebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST';
|
||||
$response = Invoke-IcingaWebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST';
|
||||
|
||||
if ($response.StatusCode -ne 200) {
|
||||
throw $response.Content;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ function Get-IcingaDirectorSelfServiceTicket()
|
|||
|
||||
[string]$url = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/ticket?key={0}', $ApiKey));
|
||||
|
||||
$response = Invoke-WebRequest -Uri $url -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST';
|
||||
$response = Invoke-IcingaWebRequest -Uri $url -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST';
|
||||
|
||||
if ($response.StatusCode -ne 200) {
|
||||
throw $response.Content;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ function Register-IcingaDirectorSelfServiceHost()
|
|||
|
||||
$EndpointUrl = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/register-host?name={0}&key={1}', $Hostname, $ApiKey));
|
||||
|
||||
$response = Invoke-WebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST' -Body $DirectorConfigJson;
|
||||
$response = Invoke-IcingaWebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST' -Body $DirectorConfigJson;
|
||||
|
||||
if ($response.StatusCode -ne 200) {
|
||||
throw $response.Content;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ function Get-IcingaFrameworkServiceBinary()
|
|||
|
||||
if ([string]::IsNullOrEmpty($FrameworkServiceUrl)) {
|
||||
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you provide a custom source of the service binary?' -Default 'n').result -eq 1) {
|
||||
$LatestRelease = (Invoke-WebRequest -Uri 'https://github.com/Icinga/icinga-powershell-service/releases/latest' -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
|
||||
$LatestRelease = (Invoke-IcingaWebRequest -Uri 'https://github.com/Icinga/icinga-powershell-service/releases/latest' -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
|
||||
$FrameworkServiceUrl = $LatestRelease.Replace('/tag/', '/download/');
|
||||
$Tag = $FrameworkServiceUrl.Split('/')[-1];
|
||||
$FrameworkServiceUrl = [string]::Format('{0}/icinga-service-{1}.zip', $FrameworkServiceUrl, $Tag);
|
||||
|
|
@ -64,9 +64,7 @@ function Get-IcingaFrameworkServiceBinary()
|
|||
$UpdateBin = Join-Path -Path $ServiceDirectory -ChildPath 'icinga-service.exe.update';
|
||||
$ServiceBin = Join-Path -Path $ServiceDirectory -ChildPath 'icinga-service.exe';
|
||||
|
||||
try {
|
||||
Invoke-WebRequest -Uri $FrameworkServiceUrl -UseBasicParsing -OutFile $ZipArchive;
|
||||
} catch {
|
||||
if ((Invoke-IcingaWebRequest -Uri $FrameworkServiceUrl -UseBasicParsing -OutFile $ZipArchive).HasErrors) {
|
||||
Write-IcingaConsoleError -Message 'Failed to download the Icinga Service Binary from "{0}". Please try again.' -Objects $FrameworkServiceUrl;
|
||||
return Get-IcingaFrameworkServiceBinary;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,11 +70,13 @@ function Get-IcingaPowerShellModuleArchive()
|
|||
if ($branch.ToLower() -eq 'snapshot') {
|
||||
$DownloadUrl = [string]::Format('https://github.com/{0}/{1}/archive/master.zip', $GitHubUser, $Repository);
|
||||
} else {
|
||||
try {
|
||||
$LatestRelease = (Invoke-WebRequest -Uri ([string]::Format('https://github.com/{0}/{1}/releases/latest', $GitHubUser, $Repository)) -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
|
||||
$WebResponse = Invoke-IcingaWebRequest -Uri 'https://github.com/{0}/{1}/releases/latest' -Objects $GitHubUser, $Repository -UseBasicParsing;
|
||||
|
||||
if ($null -eq $WebResponse.HasErrors -Or $WebResponse.HasErrors -eq $FALSE) {
|
||||
$LatestRelease = $WebResponse.BaseResponse.ResponseUri.AbsoluteUri;
|
||||
$DownloadUrl = $LatestRelease.Replace('/releases/tag/', '/archive/');
|
||||
$Tag = $DownloadUrl.Split('/')[-1];
|
||||
} catch {
|
||||
} else {
|
||||
Write-IcingaConsoleError -Message 'Failed to fetch latest release for "{0}" from GitHub. Either the module or the GitHub account do not exist' -Objects $ModuleName;
|
||||
}
|
||||
|
||||
|
|
@ -110,13 +112,11 @@ function Get-IcingaPowerShellModuleArchive()
|
|||
};
|
||||
}
|
||||
|
||||
try {
|
||||
$DownloadDirectory = New-IcingaTemporaryDirectory;
|
||||
$DownloadDestination = (Join-Path -Path $DownloadDirectory -ChildPath ([string]::Format('{0}.zip', $Repository)));
|
||||
Write-IcingaConsoleNotice ([string]::Format('Downloading "{0}" into "{1}"', $ModuleName, $DownloadDirectory));
|
||||
$DownloadDirectory = New-IcingaTemporaryDirectory;
|
||||
$DownloadDestination = (Join-Path -Path $DownloadDirectory -ChildPath ([string]::Format('{0}.zip', $Repository)));
|
||||
Write-IcingaConsoleNotice ([string]::Format('Downloading "{0}" into "{1}"', $ModuleName, $DownloadDirectory));
|
||||
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $DownloadUrl -OutFile $DownloadDestination;
|
||||
} catch {
|
||||
if ((Invoke-IcingaWebRequest -UseBasicParsing -Uri $DownloadUrl -OutFile $DownloadDestination).HasErrors) {
|
||||
Write-IcingaConsoleError ([string]::Format('Failed to download "{0}" into "{1}". Starting cleanup process', $ModuleName, $DownloadDirectory));
|
||||
Start-Sleep -Seconds 2;
|
||||
Remove-Item -Path $DownloadDirectory -Recurse -Force;
|
||||
|
|
|
|||
|
|
@ -92,7 +92,9 @@ function Install-IcingaFrameworkUpdate()
|
|||
Remove-ItemSecure -Path $Archive.Directory -Recurse -Force | Out-Null;
|
||||
|
||||
Write-IcingaConsoleNotice 'Updating Framework cache file';
|
||||
Write-IcingaFrameworkCodeCache;
|
||||
if (Test-IcingaFunction 'Write-IcingaFrameworkCodeCache') {
|
||||
Write-IcingaFrameworkCodeCache;
|
||||
}
|
||||
|
||||
Write-IcingaConsoleNotice 'Framework update has been completed. Please start a new PowerShell instance now to complete the update';
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ function Get-IcingaAgentMSIPackage()
|
|||
$LastUpdate = $null;
|
||||
|
||||
if ($Version -eq 'snapshot' -Or $Version -eq 'release') {
|
||||
$Content = (Invoke-WebRequest -Uri $Source -UseBasicParsing).RawContent.Split("`r`n");
|
||||
$Content = (Invoke-IcingaWebRequest -Uri $Source -UseBasicParsing).RawContent.Split("`r`n");
|
||||
$UsePackage = $null;
|
||||
|
||||
foreach ($line in $Content) {
|
||||
|
|
@ -62,7 +62,7 @@ function Get-IcingaAgentMSIPackage()
|
|||
if ($SkipDownload -eq $FALSE) {
|
||||
$DownloadPath = Join-Path $Env:TEMP -ChildPath $UsePackage;
|
||||
Write-IcingaConsoleNotice ([string]::Format('Downloading Icinga 2 Agent installer "{0}" into temp directory "{1}"', $UsePackage, $DownloadPath));
|
||||
Invoke-WebRequest -Uri (Join-WebPath -Path $Source -ChildPath $UsePackage) -OutFile $DownloadPath;
|
||||
Invoke-IcingaWebRequest -Uri (Join-WebPath -Path $Source -ChildPath $UsePackage) -OutFile $DownloadPath;
|
||||
}
|
||||
|
||||
return @{
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ function Copy-IcingaAgentCACertificate()
|
|||
Set-IcingaTLSVersion;
|
||||
# It could also be a web ressource
|
||||
try {
|
||||
$response = Invoke-WebRequest $CAPath -UseBasicParsing;
|
||||
$response = Invoke-IcingaWebRequest $CAPath -UseBasicParsing;
|
||||
[int]$Index = $response.RawContent.IndexOf("`r`n`r`n") + 4;
|
||||
|
||||
[string]$CAContent = $response.RawContent.SubString(
|
||||
|
|
|
|||
|
|
@ -140,6 +140,11 @@ function Get-IcingaCheckCommandConfig()
|
|||
|
||||
$IcingaCustomVariable = [string]::Format('${0}_{1}_{2}$', $PluginNameSpace, (Get-Culture).TextInfo.ToTitleCase($parameter.type.name), $parameter.Name);
|
||||
|
||||
if ($IcingaCustomVariable.Length -gt 66) {
|
||||
Write-IcingaConsoleError 'The argument "{0}" for the plugin "{1}" is too long. The maximum size of generated custom variables is 64 digits. Current argument size: "{2}", Name: "{3}"' -Objects $parameter.Name, $check, ($IcingaCustomVariable.Length - 2), $IcingaCustomVariable.Replace('$', '');
|
||||
return;
|
||||
}
|
||||
|
||||
# Todo: Should we improve this? Actually the handling would be identical, we just need to assign
|
||||
# the proper field for this
|
||||
if ($IcingaCustomVariable -like '*_Int32_Verbose$' -Or $IcingaCustomVariable -like '*_Int_Verbose$' -Or $IcingaCustomVariable -like '*_Object_Verbose$') {
|
||||
|
|
|
|||
17
lib/web/Disable-IcingaProgressPreference.psm1
Normal file
17
lib/web/Disable-IcingaProgressPreference.psm1
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Disables the progress bar during file downloads or while loading certain modules.
|
||||
This will increase the speed of certain tasks, for example file downloads
|
||||
.DESCRIPTION
|
||||
Disables the progress bar during file downloads or while loading certain modules.
|
||||
This will increase the speed of certain tasks, for example file downloads
|
||||
.FUNCTIONALITY
|
||||
Sets the $ProgressPreference to 'SilentlyContinue'
|
||||
.LINK
|
||||
https://github.com/Icinga/icinga-powershell-framework
|
||||
#>
|
||||
|
||||
function Disable-IcingaProgressPreference()
|
||||
{
|
||||
$global:ProgressPreference = "SilentlyContinue";
|
||||
}
|
||||
18
lib/web/Get-IcingaFrameworkProxyServer.psm1
Normal file
18
lib/web/Get-IcingaFrameworkProxyServer.psm1
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Fetches the configuration of the configured Proxy server for the Framework, in
|
||||
case it is set
|
||||
.DESCRIPTION
|
||||
etches the configuration of the configured Proxy server for the Framework, in
|
||||
case it is set
|
||||
.FUNCTIONALITY
|
||||
etches the configuration of the configured Proxy server for the Framework, in
|
||||
case it is set
|
||||
.LINK
|
||||
https://github.com/Icinga/icinga-powershell-framework
|
||||
#>
|
||||
|
||||
function Get-IcingaFrameworkProxyServer()
|
||||
{
|
||||
return (Get-IcingaPowerShellConfig -Path 'Framework.Proxy.Server');
|
||||
}
|
||||
144
lib/web/Invoke-IcingaWebRequest.psm1
Normal file
144
lib/web/Invoke-IcingaWebRequest.psm1
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
A wrapper function for Invoke-WebRequest to allow easier proxy support and
|
||||
to catch errors more directly.
|
||||
.DESCRIPTION
|
||||
A wrapper function for Invoke-WebRequest to allow easier proxy support and
|
||||
to catch errors more directly.
|
||||
.FUNCTIONALITY
|
||||
Uses Invoke-WebRequest to fetch information and returns the same output, but
|
||||
with direct error handling and global proxy support by configuration
|
||||
.EXAMPLE
|
||||
PS>Invoke-IcingaWebRequest -Uri 'https://icinga.com';
|
||||
.EXAMPLE
|
||||
PS>Invoke-IcingaWebRequest -Uri 'https://icinga.com' -UseBasicParsing;
|
||||
.EXAMPLE
|
||||
PS>Invoke-IcingaWebRequest -Uri 'https://{0}.com' -UseBasicParsing -Objects 'icinga';
|
||||
.EXAMPLE
|
||||
PS>Invoke-IcingaWebRequest -Uri 'https://{0}.com' -UseBasicParsing -Objects 'icinga' -Headers @{ 'accept' = 'application/json' };
|
||||
.PARAMETER Uri
|
||||
The Uri for the web request
|
||||
.PARAMETER Body
|
||||
Specifies the body of the request. The body is the content of the request that follows the headers. You can
|
||||
also pipe a body value to Invoke-WebRequest.
|
||||
|
||||
The Body parameter can be used to specify a list of query parameters or specify the content of the response.
|
||||
|
||||
When the input is a GET request and the body is an IDictionary (typically, a hash table), the body is added
|
||||
to the URI as query parameters. For other GET requests, the body is set as the value of the request body in
|
||||
the standard name=value format.
|
||||
|
||||
When the body is a form, or it is the output of an Invoke-WebRequest call, Windows PowerShell sets the
|
||||
request content to the form fields.
|
||||
.PARAMETER Headers
|
||||
Web headers send with the request as hashtable
|
||||
.PARAMETER Method
|
||||
The request method to send to the destination.
|
||||
Allowed values: 'Get', 'Post', 'Put', 'Trace', 'Patch', 'Options', 'Merge', 'Head', 'Default', 'Delete'
|
||||
.PARAMETER OutFile
|
||||
Specifies the output file for which this cmdlet saves the response body. Enter a path and file name. If you omit the path, the default is the current location.
|
||||
.PARAMETER UseBasicParsing
|
||||
Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM)
|
||||
parsing.
|
||||
|
||||
This parameter is required when Internet Explorer is not installed on the computers, such as on a Server
|
||||
Core installation of a Windows Server operating system.
|
||||
.PARAMETER Objects
|
||||
Use placeholders within the `-Uri` argument, like {0} and replace them with array elements of this argument.
|
||||
The index entry of {0} has to match the order of this argument.
|
||||
.INPUTS
|
||||
System.String
|
||||
.OUTPUTS
|
||||
System.Boolean
|
||||
.LINK
|
||||
https://github.com/Icinga/icinga-powershell-framework
|
||||
#>
|
||||
|
||||
function Invoke-IcingaWebRequest()
|
||||
{
|
||||
param (
|
||||
[string]$Uri = '',
|
||||
$Body,
|
||||
[hashtable]$Headers,
|
||||
[ValidateSet('Get', 'Post', 'Put', 'Trace', 'Patch', 'Options', 'Merge', 'Head', 'Default', 'Delete')]
|
||||
[string]$Method = 'Get',
|
||||
[string]$OutFile,
|
||||
[switch]$UseBasicParsing,
|
||||
[array]$Objects = @()
|
||||
);
|
||||
|
||||
[int]$Index = 0;
|
||||
foreach ($entry in $Objects) {
|
||||
|
||||
$Uri = $Uri.Replace(
|
||||
[string]::Format('{0}{1}{2}', '{', $Index, '}'),
|
||||
$entry
|
||||
);
|
||||
$Index++;
|
||||
}
|
||||
|
||||
$WebArguments = @{
|
||||
'Uri' = $Uri;
|
||||
'Method' = $Method;
|
||||
}
|
||||
|
||||
if ($Method -ne 'Get' -And $null -ne $Body -and [string]::IsNullOrEmpty($Body) -eq $FALSE) {
|
||||
$WebArguments.Add('Body', $Body);
|
||||
}
|
||||
|
||||
if ($Headers.Count -ne 0) {
|
||||
$WebArguments.Add('Headers', $Headers);
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrEmpty($OutFile) -eq $FALSE) {
|
||||
$WebArguments.Add('OutFile', $OutFile);
|
||||
}
|
||||
|
||||
$ProxyServer = Get-IcingaFrameworkProxyServer;
|
||||
|
||||
if ([string]::IsNullOrEmpty($ProxyServer) -eq $FALSE) {
|
||||
$WebArguments.Add('Proxy', $ProxyServer);
|
||||
}
|
||||
|
||||
Set-IcingaTLSVersion;
|
||||
Disable-IcingaProgressPreference;
|
||||
|
||||
try {
|
||||
$Response = Invoke-WebRequest -UseBasicParsing:$UseBasicParsing @WebArguments -ErrorAction Stop;
|
||||
} catch {
|
||||
[string]$ErrorId = ([string]$_.FullyQualifiedErrorId).Split(',')[0];
|
||||
[string]$Message = $_.Exception.Message;
|
||||
|
||||
switch ($ErrorId) {
|
||||
'System.UriFormatException' {
|
||||
Write-IcingaConsoleError 'The provided Url "{0}" is not a valid format' -Objects $Uri;
|
||||
break;
|
||||
};
|
||||
'WebCmdletWebResponseException' {
|
||||
Write-IcingaConsoleError 'The remote host for address "{0}" could not be resolved' -Objects $Uri;
|
||||
break;
|
||||
};
|
||||
'System.InvalidOperationException' {
|
||||
Write-IcingaConsoleError 'Failed to query host "{0}". Possible this is caused by an invalid Proxy Server configuration: "{1}".' -Objects $Uri, $ProxyServer;
|
||||
break;
|
||||
};
|
||||
Default {
|
||||
Write-IcingaConsoleError 'Unhandled exception for Url "{0}" with error id "{1}":{2}{2}{3}' -Objects $Uri, $ErrorId, (New-IcingaNewLine), $Message;
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
# Return some sort of objects which are often used to ensure we at least have some out-of-the-box compatibility
|
||||
return @{
|
||||
'HasErrors' = $TRUE;
|
||||
'BaseResponse' = @{
|
||||
'ResponseUri' = @{
|
||||
'AbsoluteUri' = $Uri;
|
||||
};
|
||||
};
|
||||
'StatusCode' = 900;
|
||||
};
|
||||
}
|
||||
|
||||
return $Response;
|
||||
}
|
||||
30
lib/web/Set-IcingaFrameworkProxyServer.psm1
Normal file
30
lib/web/Set-IcingaFrameworkProxyServer.psm1
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Sets the configuration for a proxy server which is used by all Invoke-WebRequests
|
||||
to ensure internet connections are working correctly.
|
||||
.DESCRIPTION
|
||||
Sets the configuration for a proxy server which is used by all Invoke-WebRequests
|
||||
to ensure internet connections are working correctly.
|
||||
.FUNCTIONALITY
|
||||
Sets the configuration for a proxy server which is used by all Invoke-WebRequests
|
||||
to ensure internet connections are working correctly.
|
||||
.EXAMPLE
|
||||
PS>Set-IcingaFrameworkProxyServer -Server 'http://example.com:8080';
|
||||
.PARAMETER Server
|
||||
The server with the port for the Proxy. Example: 'http://example.com:8080'
|
||||
.INPUTS
|
||||
System.String
|
||||
.LINK
|
||||
https://github.com/Icinga/icinga-powershell-framework
|
||||
#>
|
||||
|
||||
function Set-IcingaFrameworkProxyServer()
|
||||
{
|
||||
param (
|
||||
[string]$Server = ''
|
||||
);
|
||||
|
||||
Set-IcingaPowerShellConfig -Path 'Framework.Proxy.Server' -Value $Server;
|
||||
|
||||
Write-IcingaConsoleNotice 'The Proxy server for the PowerShell Framework has been set to "{0}"' -Objects $Server;
|
||||
}
|
||||
|
|
@ -1,3 +1,14 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Sets the allowed TLS version for communicating with endpoints to TLS 1.2 and 1.1
|
||||
.DESCRIPTION
|
||||
Sets the allowed TLS version for communicating with endpoints to TLS 1.2 and 1.1
|
||||
.FUNCTIONALITY
|
||||
Uses the [Net.ServicePointManager] to set the SecurityProtocol to TLS 1.2 and 1.1
|
||||
.LINK
|
||||
https://github.com/Icinga/icinga-powershell-framework
|
||||
#>
|
||||
|
||||
function Set-IcingaTLSVersion()
|
||||
{
|
||||
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11";
|
||||
|
|
|
|||
|
|
@ -55,7 +55,11 @@ function Get-IcingaWindowsInformation()
|
|||
|
||||
if ($ForceWMI -eq $FALSE -And (Get-Command 'Get-CimInstance' -ErrorAction SilentlyContinue)) {
|
||||
try {
|
||||
return (Get-CimInstance @Arguments -ErrorAction Stop);
|
||||
$CimData = (Get-CimInstance @Arguments -ErrorAction Stop);
|
||||
|
||||
Write-IcingaDebugMessage 'Debug output for "Get-IcingaWindowsInformation::Get-CimInstance"' -Objects $ClassName, $Filter, $Namespace, ($CimData | Out-String);
|
||||
|
||||
return $CimData;
|
||||
} catch {
|
||||
$ErrorName = $_.Exception.NativeErrorCode;
|
||||
$ErrorMessage = $_.Exception.Message;
|
||||
|
|
@ -84,7 +88,11 @@ function Get-IcingaWindowsInformation()
|
|||
|
||||
if ((Get-Command 'Get-WmiObject' -ErrorAction SilentlyContinue)) {
|
||||
try {
|
||||
return (Get-WmiObject @Arguments -ErrorAction Stop);
|
||||
$WmiData = (Get-WmiObject @Arguments -ErrorAction Stop);
|
||||
|
||||
Write-IcingaDebugMessage 'Debug output for "Get-IcingaWindowsInformation::Get-WmiObject"' -Objects $ClassName, $Filter, $Namespace, ($WmiData | Out-String);
|
||||
|
||||
return $WmiData;
|
||||
} catch {
|
||||
$ErrorName = $_.CategoryInfo.Category;
|
||||
$ErrorMessage = $_.Exception.Message;
|
||||
|
|
|
|||
Loading…
Reference in a new issue