Skip to content

Commit 45c4a2b

Browse files
authored
Merge pull request #710 from Icinga:fix/errors_for_non_admin_shells
Fix: Errors for non-admin shells introduced with v1.12.0 Fixes various console errors while running Icinga for Windows outside of an administrative shell
2 parents 98f3f60 + 1667485 commit 45c4a2b

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

doc/100-General/10-Changelog.md

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

1818
* [#707](https://github.com/Icinga/icinga-powershell-framework/pull/707) Fixes size of the `Icinga for Windows` eventlog by setting it to `20MiB`, allowing to store more events before they are overwritten
19+
* [#710](https://github.com/Icinga/icinga-powershell-framework/pull/710) Fixes various console errors while running Icinga for Windows outside of an administrative shell
1920

2021
## 1.12.0 (2024-03-26)
2122

lib/core/icingaagent/setters/Set-IcingaServiceEnvironment.psm1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ function Set-IcingaServiceEnvironment()
88
return;
99
}
1010

11+
# Don't do anything if we are not inside an administrative shell
12+
if ((Test-AdministrativeShell) -eq $FALSE) {
13+
return;
14+
}
15+
1116
# Use scheduled tasks to fetch our current service configuration for faster load times afterwards
1217
$IcingaService = Invoke-IcingaWindowsScheduledTask -JobType GetWindowsService -ObjectName 'icinga2';
1318
$PowerShellService = Invoke-IcingaWindowsScheduledTask -JobType GetWindowsService -ObjectName 'icingapowershell';

lib/core/logging/Register-IcingaEventLog.psm1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ function Register-IcingaEventLog()
44
[string]$LogName = $null
55
);
66

7+
if ((Test-AdministrativeShell) -eq $FALSE) {
8+
return;
9+
}
10+
711
if ([string]::IsNullOrEmpty($LogName)) {
812
New-EventLog -LogName 'Icinga for Windows' -Source 'IfW::Framework' -ErrorAction SilentlyContinue;
913
New-EventLog -LogName 'Icinga for Windows' -Source 'IfW::Service' -ErrorAction SilentlyContinue;
@@ -15,6 +19,12 @@ function Register-IcingaEventLog()
1519
}
1620

1721
$IfWEventLog = Get-WinEvent -ListLog 'Icinga for Windows';
22+
23+
# In case the value is already set, nothing to do
24+
if ($IfWEventLog.MaximumSizeInBytes -ge 20971520) {
25+
return;
26+
}
27+
1828
# Set the size to 20MiB
1929
$IfWEventLog.MaximumSizeInBytes = 20971520;
2030
$IfWEventLog.SaveChanges();

0 commit comments

Comments
 (0)