mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-22 23:59:46 -05:00
Merge pull request #211 from Icinga:feature/add_support_to_uninstall_components
Feature: Adds support to uninstall Icinga for Windows Adds feature to uninstall single components for Icinga for Windows or to uninstall everything and start entirely from new.
This commit is contained in:
commit
7d3ac7ef08
3 changed files with 121 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
||||||
* [#205](https://github.com/Icinga/icinga-powershell-framework/pull/205) Ensure Icinga for Windows configuration file is opened as read-only for every single task besides actually modifying configuration content
|
* [#205](https://github.com/Icinga/icinga-powershell-framework/pull/205) Ensure Icinga for Windows configuration file is opened as read-only for every single task besides actually modifying configuration content
|
||||||
* [#207](https://github.com/Icinga/icinga-powershell-framework/pull/207) Adds new Argument `-LabelName` to `New-IcingaCheck`, allowing the developer to provide custom label names for checks and override the default based on the check name.
|
* [#207](https://github.com/Icinga/icinga-powershell-framework/pull/207) Adds new Argument `-LabelName` to `New-IcingaCheck`, allowing the developer to provide custom label names for checks and override the default based on the check name.
|
||||||
* [#210](https://github.com/Icinga/icinga-powershell-framework/pull/210) Updates the Icinga DSL for building PowerShell arrays to ensure all string values are properly escaped with `'`. In case the user already wrapped commands with `'` by himself, this will not have an effect as we only add single quotes for escaping if they are not present already
|
* [#210](https://github.com/Icinga/icinga-powershell-framework/pull/210) Updates the Icinga DSL for building PowerShell arrays to ensure all string values are properly escaped with `'`. In case the user already wrapped commands with `'` by himself, this will not have an effect as we only add single quotes for escaping if they are not present already
|
||||||
|
* [#211](https://github.com/Icinga/icinga-powershell-framework/pull/211) Adds feature to uninstall single components for Icinga for Windows or to uninstall everything and start entirely from new
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
||||||
72
lib/core/framework/Uninstall-IcingaForWindows.psm1
Normal file
72
lib/core/framework/Uninstall-IcingaForWindows.psm1
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Uninstalls every PowerShell module within the icinga-powershell-* namespace
|
||||||
|
including the Icinga Agent with all components (like certificates) as well as
|
||||||
|
the Icinga for Windows service and the Icinga PowerShell Framework.
|
||||||
|
.DESCRIPTION
|
||||||
|
Uninstalls every PowerShell module within the icinga-powershell-* namespace
|
||||||
|
including the Icinga Agent with all components (like certificates) as well as
|
||||||
|
the Icinga for Windows service and the Icinga PowerShell Framework.
|
||||||
|
.FUNCTIONALITY
|
||||||
|
Uninstalls every PowerShell module within the icinga-powershell-* namespace
|
||||||
|
including the Icinga Agent with all components (like certificates) as well as
|
||||||
|
the Icinga for Windows service and the Icinga PowerShell Framework.
|
||||||
|
.PARAMETER Force
|
||||||
|
Suppress the question if you are sure to uninstall everything
|
||||||
|
.INPUTS
|
||||||
|
System.String
|
||||||
|
.OUTPUTS
|
||||||
|
Null
|
||||||
|
.LINK
|
||||||
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
|
#>
|
||||||
|
|
||||||
|
function Uninstall-IcingaForWindows()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[switch]$Force = $FALSE
|
||||||
|
);
|
||||||
|
|
||||||
|
$ModuleList = Get-Module 'icinga-powershell-*' -ListAvailable;
|
||||||
|
[string]$Modules = [string]::Join(', ', $ModuleList.Name);
|
||||||
|
|
||||||
|
if ($Force -eq $FALSE) {
|
||||||
|
Write-IcingaConsoleWarning -Message 'You are about to uninstall the Icinga Agent with all components (including certificates) and all Icinga for Windows Components: {0}{1}Are you sure you want to proceed? (y/N)' -Objects $Modules, (New-IcingaNewLine);
|
||||||
|
$Input = Read-Host 'Confirm uninstall';
|
||||||
|
if ($input -ne 'y') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$CurrentLocation = Get-Location;
|
||||||
|
|
||||||
|
if ($CurrentLocation -eq (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'icinga-powershell-framework')) {
|
||||||
|
Set-Location -Path (Get-IcingaFrameworkRootPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-IcingaConsoleNotice 'Uninstalling Icinga for Windows from this host';
|
||||||
|
Write-IcingaConsoleNotice 'Uninstalling Icinga Agent';
|
||||||
|
Uninstall-IcingaAgent -RemoveDataFolder | Out-Null;
|
||||||
|
Write-IcingaConsoleNotice 'Uninstalling Icinga for Windows service';
|
||||||
|
Uninstall-IcingaFrameworkService | Out-Null;
|
||||||
|
|
||||||
|
$HasErrors = $FALSE;
|
||||||
|
|
||||||
|
foreach ($module in $ModuleList.Name) {
|
||||||
|
[string]$ModuleName = $module.Replace('icinga-powershell-', '');
|
||||||
|
|
||||||
|
if ((Uninstall-IcingaFrameworkComponent -Component $ModuleName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$HasErrors = $TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Remove-Module 'icinga-powershell-framework' -Force -ErrorAction SilentlyContinue;
|
||||||
|
|
||||||
|
if ($HasErrors) {
|
||||||
|
Write-IcingaConsoleWarning 'Not all components could be removed. Please ensure no other PowerShell/Application is currently open and accessing Icinga for Windows files';
|
||||||
|
} else {
|
||||||
|
Write-IcingaConsoleNotice 'Icinga for Windows was removed from this host.';
|
||||||
|
}
|
||||||
|
}
|
||||||
48
lib/core/framework/Uninstall-IcingaFrameworkComponent.psm1
Normal file
48
lib/core/framework/Uninstall-IcingaFrameworkComponent.psm1
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Uninstalls a specific module within the icinga-powershell-* namespace
|
||||||
|
inside your PowerShell module folder
|
||||||
|
.DESCRIPTION
|
||||||
|
Uninstalls a specific module within the icinga-powershell-* namespace
|
||||||
|
inside your PowerShell module folder
|
||||||
|
.FUNCTIONALITY
|
||||||
|
Uninstalls a specific module within the icinga-powershell-* namespace
|
||||||
|
inside your PowerShell module folder
|
||||||
|
.PARAMETER Component
|
||||||
|
The component you want to uninstall, like 'plugins' or 'mssql'
|
||||||
|
.INPUTS
|
||||||
|
System.String
|
||||||
|
.OUTPUTS
|
||||||
|
Null
|
||||||
|
.LINK
|
||||||
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
|
#>
|
||||||
|
|
||||||
|
function Uninstall-IcingaFrameworkComponent()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$Component
|
||||||
|
);
|
||||||
|
|
||||||
|
$ModuleBase = Get-IcingaFrameworkRootPath;
|
||||||
|
$UninstallComponent = [string]::Format('icinga-powershell-{0}', $Component);
|
||||||
|
$UninstallPath = Join-Path -Path $ModuleBase -ChildPath $UninstallComponent;
|
||||||
|
|
||||||
|
if ((Test-Path $UninstallPath) -eq $FALSE) {
|
||||||
|
Write-IcingaConsoleNotice -Message 'The Icinga for Windows component "{0}" at "{1}" could not ne found.' -Objects $UninstallComponent, $UninstallPath;
|
||||||
|
return $FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-IcingaConsoleNotice -Message 'Uninstalling Icinga for Windows component "{0}" from "{1}"' -Objects $UninstallComponent, $UninstallPath;
|
||||||
|
if (Remove-ItemSecure -Path $UninstallPath -Recurse -Force) {
|
||||||
|
Write-IcingaConsoleNotice -Message 'Successfully removed Icinga for Windows component "{0}" from "{1}"' -Objects $UninstallComponent, $UninstallPath;
|
||||||
|
if ($UninstallComponent -ne 'icinga-powershell-framework') {
|
||||||
|
Remove-Module $UninstallComponent -Force -ErrorAction SilentlyContinue;
|
||||||
|
}
|
||||||
|
return $TRUE;
|
||||||
|
} else {
|
||||||
|
Write-IcingaConsoleError -Message 'Unable to uninstall Icinga for Windows component "{0}" from "{1}"' -Objects $UninstallComponent, $UninstallPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $FALSE;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue