-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathInvoke-IcingaForWindowsMigration.psm1
103 lines (78 loc) · 4.68 KB
/
Invoke-IcingaForWindowsMigration.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function Invoke-IcingaForWindowsMigration()
{
$IcingaForWindowsService = Get-IcingaForWindowsServiceData;
if (([string]::IsNullOrEmpty($IcingaForWindowsService.FullPath) -eq $FALSE -And (Test-Path $IcingaForWindowsService.FullPath))) {
$ServiceBinaryData = Read-IcingaServicePackage -File $IcingaForWindowsService.FullPath;
if ($ServiceBinaryData.FileVersion -lt (New-IcingaVersionObject -Version '1.2.0')) {
Write-IcingaConsoleWarning -Message 'You are running a Icinga for Windows Service binary older than v1.2.0. You need to upgrade to v1.2.0 or later before you can use Icinga for Windows properly. You can update it with "Update-Icinga -Name service"';
return;
}
}
# Upgrade to v1.8.0
if (Test-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.8.0')) {
$ServiceStatus = (Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Status;
Write-IcingaConsoleNotice 'Applying pending migrations required for Icinga for Windows v1.8.0';
if ($ServiceStatus -eq 'Running') {
Stop-IcingaWindowsService;
}
$ApiChecks = Get-IcingaPowerShellConfig -Path 'Framework.Experimental.UseApiChecks';
if ($null -ne $ApiChecks) {
Remove-IcingaPowerShellConfig -Path 'Framework.Experimental.UseApiChecks' | Out-Null;
Set-IcingaPowerShellConfig -Path 'Framework.ApiChecks' -Value $ApiChecks;
}
# Remove all prior EventLog handler
Unregister-IcingaEventLog;
# Add new Icinga for Windows EventLog
Register-IcingaEventLog;
Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.8.0');
# For upgrading to v1.8.0 it is required to restart the Icinga for Windows service
if ($ServiceStatus -eq 'Running') {
Restart-IcingaService -Service 'icingapowershell';
}
}
if (Test-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.10.0')) {
Write-IcingaConsoleNotice 'Applying pending migrations required for Icinga for Windows v1.10.0';
$ServiceStatus = (Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Status;
if ($ServiceStatus -eq 'Running') {
Stop-IcingaWindowsService;
}
# Convert the time intervals for the background daemon services from the previous index handling
# 1, 3, 5, 15 as example to 1m, 3m, 5m, 15m
$BackgroundServices = Get-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices';
# Only run this migration in case background services are defined
if ($null -ne $BackgroundServices) {
foreach ($service in $BackgroundServices.PSObject.Properties) {
[array]$ConvertedTimeIndex = @();
foreach ($interval in $service.Value.TimeIndexes) {
if (Test-Numeric $interval) {
$ConvertedTimeIndex += [string]::Format('{0}m', $interval);
} else {
$ConvertedTimeIndex = $interval;
}
}
$service.Value.TimeIndexes = $ConvertedTimeIndex;
}
Set-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices' -Value $BackgroundServices;
}
Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.10.0');
if ($ServiceStatus -eq 'Running') {
Restart-IcingaForWindows;
}
}
if (Test-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.10.1')) {
Write-IcingaConsoleNotice 'Applying pending migrations required for Icinga for Windows v1.10.1';
# Fix Icinga for Windows v1.10.0 broken background service registration
if ($null -eq (Get-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices')) {
Remove-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices';
}
Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.10.1');
}
if (Test-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.12.0')) {
Write-IcingaConsoleNotice 'Applying pending migrations required for Icinga for Windows v1.12.0';
# Add a new scheduled task to automatically renew the Icinga for Windows certificate
Register-IcingaWindowsScheduledTaskRenewCertificate -Force;
# Start the task to ensure the certificate is generated
Start-IcingaWindowsScheduledTaskRenewCertificate;
Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.12.0');
}
}