Skip to content

Commit

Permalink
Fixes permission error on EventLog registration by printing proper er…
Browse files Browse the repository at this point in the history
…ror message

Fixes #81
  • Loading branch information
LordHepipud committed Aug 6, 2020
1 parent 22f341b commit 47272bd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doc/31-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Check Command configuration generated by Icinga for Windows 1.2.0 require Icinga

* [#78](https://github.com/Icinga/icinga-powershell-framework/issues/78) Fix Icinga Agent package fetching for x86 architecture
* [#79](https://github.com/Icinga/icinga-powershell-framework/issues/79) Fix ConvertTo-Seconds to output valid numeric data with multiple digits
* [#81](https://github.com/Icinga/icinga-powershell-framework/issues/81), [#82](https://github.com/Icinga/icinga-powershell-framework/issues/82) Fix error on EventLog initialising in case `Icinga for Windows` application is not registered on new machines
* [#81](https://github.com/Icinga/icinga-powershell-framework/issues/81), [#82](https://github.com/Icinga/icinga-powershell-framework/issues/82) Fix error on EventLog initialising in case `Icinga for Windows` application is not registered on new machines and throws proper error message on plugin execution on how to resolve it
* [#84](https://github.com/Icinga/icinga-powershell-framework/issues/84), Fix conversion of `ConvertTo-Seconds` and `ConvertTo-SecondsFromIcingaThresholds` while the input value is `$null`
* [#85](https://github.com/Icinga/icinga-powershell-framework/issues/85), Fix incorrect handling to empty service user password which was configured as empty `String` instead of `$null` `SecureString` object
* [#89](https://github.com/Icinga/icinga-powershell-framework/issues/89), Fix file type question during `Get-IcingaCheckCommandConfig` generation in Windows 2012 R2 and older
Expand Down
6 changes: 4 additions & 2 deletions icinga-powershell-framework.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ function Use-Icinga()
Import-IcingaLib '\' -Init;

if ($LibOnly -eq $FALSE) {
Register-IcingaEventLog;

$global:IcingaThreads = [hashtable]::Synchronized(@{});
$global:IcingaThreadContent = [hashtable]::Synchronized(@{});
$global:IcingaThreadPool = [hashtable]::Synchronized(@{});
Expand Down Expand Up @@ -73,6 +71,10 @@ function Use-Icinga()
-Value $entry[$event] | Out-Null;
}
}

if ($LibOnly -eq $FALSE) {
Register-IcingaEventLog;
}
}

function Import-IcingaLib()
Expand Down
8 changes: 3 additions & 5 deletions lib/core/logging/Register-IcingaEventLog.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ function Register-IcingaEventLog()
if ($Registered) {
return;
}

New-EventLog -LogName Application -Source 'Icinga for Windows';
} catch {
# Nothing to handle here. We should simply register our application
# whtin the Application Event-Log. We will only run into this catch
# block if the app was not registered.
Exit-IcingaThrowException -ExceptionType 'Configuration' -ExceptionThrown $IcingaExceptions.Configuration.EventLogNotInstalled -Force;
}

New-EventLog -LogName Application -Source 'Icinga for Windows';
}
1 change: 1 addition & 0 deletions lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
PluginArgumentMissing = 'Your plugin argument configuration is missing mandatory arguments. This is error is caused when mandatory or required arguments are missing from a plugin call and the operation is unable to process without them.';
PluginNotInstalled = 'The plugin assigned to this service check seems not to be installed on this machine. Please review your service check configuration for spelling errors and check if the plugin is installed and executable on this machine by PowerShell.';
PluginNotAssigned = 'Your check for this service could not be processed because it seems like no valid Cmdlet was assigned to the check command. Please review your check command to ensure that a valid Cmdlet is assigned and executed by a PowerShell call.';
EventLogNotInstalled = 'Your Icinga PowerShell Framework has been executed by an unprivileged user before it was properly installed. The Windows EventLog application could not be registered because the current user has insufficient permissions. Please log into the machine and run "Use-Icinga" once from an administrative shell to complete the setup process. Once done this error should vanish.';
}

<#
Expand Down

0 comments on commit 47272bd

Please sign in to comment.