-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathInstall-Icinga.psm1
182 lines (158 loc) · 8.04 KB
/
Install-Icinga.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
function Install-Icinga()
{
param (
[string]$InstallCommand = $null,
[string]$InstallFile = ''
);
if ($null -eq $global:Icinga) {
$global:Icinga = @{ };
}
if ($global:Icinga.ContainsKey('InstallWizard') -eq $FALSE) {
$global:Icinga.Add(
'InstallWizard', @{
'AdminShell' = (Test-AdministrativeShell);
'BlockClearHost' = $FALSE;
'LastInput' = '';
'LastNotice' = '';
'LastError' = '';
'DirectorError' = '';
'HeaderPreview' = '';
'DirectorSelfService' = $FALSE;
'DirectorRegisteredHost' = $FALSE;
'DirectorInstallError' = $FALSE;
'LastParent' = [System.Collections.ArrayList]@();
'LastValues' = @();
'DisabledEntries' = @{ };
'Config' = @{ };
'ConfigSwap' = @{ };
'ParentConfig' = $null;
'Menu' = 'Install-Icinga';
'NextCommand' = '';
'NextArguments' = $null;
'HeaderSelection' = $null;
'DisplayAdvanced' = $FALSE;
'ShowAdvanced' = $FALSE;
'ShowHelp' = $FALSE;
'ShowCommand' = $FALSE;
'DeleteValues' = $FALSE;
'HeaderPrint' = $FALSE;
'JumpToSummary' = $FALSE;
'Closing' = $FALSE;
}
);
}
if ([string]::IsNullOrEmpty($InstallFile) -eq $FALSE) {
$InstallCommand = Read-IcingaFileSecure -File $InstallFile -ExitOnReadError;
}
# Use our install command to configure everything
if ([string]::IsNullOrEmpty($InstallCommand) -eq $FALSE) {
try {
$JsonInstallCmd = ConvertFrom-Json -InputObject $InstallCommand -ErrorAction Stop;
} catch {
Write-IcingaConsoleError 'Failed to deserialize the provided JSON from file or command: {0}' -Objects $_.Exception.Message;
return;
}
# Add our "old" swap internally
$OldConfigSwap = Get-IcingaPowerShellConfig -Path 'Framework.Config.Swap';
Disable-IcingaFrameworkConsoleOutput;
[hashtable]$IcingaConfiguration = Convert-IcingaForwindowsManagementConsoleJSONConfig -Config $JsonInstallCmd;
# First run our configuration values
$Success = Invoke-IcingaForWindowsManagementConsoleCustomConfig -IcingaConfiguration $IcingaConfiguration;
if ($Success -eq $FALSE) {
return;
}
# In case we use the director, we require to first fetch all basic values from the Self-Service API then
# require to register the host to fet the remaining content
if ($IcingaConfiguration.ContainsKey('IfW-DirectorSelfServiceKey') -And $IcingaConfiguration.ContainsKey('IfW-DirectorUrl')) {
Enable-IcingaFrameworkConsoleOutput;
Resolve-IcingaForWindowsManagementConsoleInstallationDirectorTemplate;
Resolve-IcingaForWindowsManagementConsoleInstallationDirectorTemplate -Register;
Disable-IcingaFrameworkConsoleOutput;
} else {
# Now load all remaining values we haven't set and define the defaults
Add-IcingaForWindowsInstallationAdvancedEntries;
}
# Now apply our configuration again to ensure the defaults are overwritten again
# Suite a mess, but we can improve this later
$Success = Invoke-IcingaForWindowsManagementConsoleCustomConfig -IcingaConfiguration $IcingaConfiguration;
if ($Success -eq $FALSE) {
return;
}
Enable-IcingaFrameworkConsoleOutput;
Start-IcingaForWindowsInstallation -Automated;
# Set our "old" swap live again. By doing so, we can still continue our old
# configuration
Set-IcingaPowerShellConfig -Path 'Framework.Config.Swap' -Value $OldConfigSwap;
return;
}
while ($TRUE) {
# Do nothing else anymore in case we are closing the management console
if ($global:Icinga.InstallWizard.Closing) {
break;
}
$FrameworkInstalled = Get-IcingaPowerShellConfig -Path 'Framework.Installed';
if ($null -eq $FrameworkInstalled) {
$FrameworkInstalled = $FALSE;
}
if ([string]::IsNullOrEmpty($global:Icinga.InstallWizard.NextCommand) -Or $global:Icinga.InstallWizard.NextCommand -eq 'Install-Icinga') {
Show-IcingaForWindowsInstallerMenu `
-Header 'What do you want to do?' `
-Entries @(
@{
'Caption' = 'Installation';
'Command' = 'Show-IcingaForWindowsInstallerMenuInstallWindows';
'Help' = 'Allows you to install Icinga for Windows with all required components and options.'
},
@{
'Caption' = 'Install components';
'Command' = 'Show-IcingaForWindowsMenuInstallComponents';
'Help' = 'Allows you to install new components for Icinga for Windows from your repositories.';
'Disabled' = (-Not ($global:Icinga.InstallWizard.AdminShell));
},
@{
'Caption' = 'Update components';
'Command' = 'Show-IcingaForWindowsMenuUpdateComponents';
'Help' = 'Allows you to modify your current Icinga for Windows installation.';
'Disabled' = (-Not ($global:Icinga.InstallWizard.AdminShell));
},
@{
'Caption' = 'Remove components';
'Command' = 'Show-IcingaForWindowsMenuRemoveComponents';
'Help' = 'Allows you to modify your current Icinga for Windows installation.';
'Disabled' = (-Not ($global:Icinga.InstallWizard.AdminShell));
},
@{
'Caption' = 'Manage environment';
'Command' = 'Show-IcingaForWindowsMenuManage';
'Help' = 'Allows you to modify your current Icinga for Windows installation.';
},
@{
'Caption' = 'List environment';
'Command' = 'Show-IcingaForWindowsMenuListEnvironment';
'Help' = 'Shows you an overview of your current Icinga for Windows installation, including installed components and system informations.';
}
) `
-DefaultIndex 0;
} else {
$NextArguments = $global:Icinga.InstallWizard.NextArguments;
if ($global:Icinga.InstallWizard.NextCommand.Contains(':')) {
$NextArguments = @{
'Value' = ($global:Icinga.InstallWizard.NextCommand.Split(':')[1]);
};
$global:Icinga.InstallWizard.NextCommand = $global:Icinga.InstallWizard.NextCommand.Split(':')[0];
}
try {
if ($null -ne $NextArguments -And $NextArguments.Count -ne 0) {
& $global:Icinga.InstallWizard.NextCommand @NextArguments;
} else {
& $global:Icinga.InstallWizard.NextCommand;
}
} catch {
$ErrMsg = $_.Exception.Message;
$global:Icinga.InstallWizard.LastError = [string]::Format('Failed to enter menu "{0}". Error "{1}', $global:Icinga.InstallWizard.NextCommand, $ErrMsg);
$global:Icinga.InstallWizard.NextCommand = 'Install-Icinga';
$global:Icinga.InstallWizard.NextArguments = @{ };
}
}
}
}