diff --git a/icinga-powershell-framework.psm1 b/icinga-powershell-framework.psm1 index e0e52e7..1e15d88 100644 --- a/icinga-powershell-framework.psm1 +++ b/icinga-powershell-framework.psm1 @@ -29,15 +29,6 @@ function Use-Icinga() Import-IcingaLib '\' -Init -Custom; Import-IcingaLib '\' -Init; - $EventLogMessages = Invoke-IcingaNamespaceCmdlets -Command 'Register-IcingaEventLogMessages*'; - foreach ($entry in $EventLogMessages.Values) { - foreach ($event in $entry.Keys) { - Add-IcingaHashtableItem -Hashtable $global:IcingaEventLogEnums ` - -Key $event ` - -Value $entry[$event] | Out-Null; - } - } - if ($LibOnly -eq $FALSE) { Register-IcingaEventLog; @@ -66,6 +57,21 @@ function Use-Icinga() $global:IcingaDaemonData.FrameworkRunningAsDaemon = $Daemon; } } + + # Enable DebugMode in case it is enabled in our config + if (Get-IcingaFrameworkDebugMode) { + Enable-IcingaFrameworkDebugMode; + $DebugMode = $TRUE; + } + + $EventLogMessages = Invoke-IcingaNamespaceCmdlets -Command 'Register-IcingaEventLogMessages*'; + foreach ($entry in $EventLogMessages.Values) { + foreach ($event in $entry.Keys) { + Add-IcingaHashtableItem -Hashtable $global:IcingaEventLogEnums ` + -Key $event ` + -Value $entry[$event] | Out-Null; + } + } } function Import-IcingaLib() diff --git a/lib/core/framework/Disable-IcingaFrameworkDebugMode.psm1 b/lib/core/framework/Disable-IcingaFrameworkDebugMode.psm1 index ebd30f5..f32633e 100644 --- a/lib/core/framework/Disable-IcingaFrameworkDebugMode.psm1 +++ b/lib/core/framework/Disable-IcingaFrameworkDebugMode.psm1 @@ -1,4 +1,5 @@ function Disable-IcingaFrameworkDebugMode() { $global:IcingaDaemonData.DebugMode = $FALSE; + Set-IcingaPowerShellConfig -Path 'Framework.DebugMode' -Value $FALSE; } diff --git a/lib/core/framework/Enable-IcingaFrameworkDebugMode.psm1 b/lib/core/framework/Enable-IcingaFrameworkDebugMode.psm1 index 9ee7d15..4b3af05 100644 --- a/lib/core/framework/Enable-IcingaFrameworkDebugMode.psm1 +++ b/lib/core/framework/Enable-IcingaFrameworkDebugMode.psm1 @@ -1,4 +1,5 @@ function Enable-IcingaFrameworkDebugMode() { $global:IcingaDaemonData.DebugMode = $TRUE; + Set-IcingaPowerShellConfig -Path 'Framework.DebugMode' -Value $TRUE; } diff --git a/lib/core/framework/Get-IcingaFrameworkDebugMode.psm1 b/lib/core/framework/Get-IcingaFrameworkDebugMode.psm1 new file mode 100644 index 0000000..fcc5b88 --- /dev/null +++ b/lib/core/framework/Get-IcingaFrameworkDebugMode.psm1 @@ -0,0 +1,10 @@ +function Get-IcingaFrameworkDebugMode() +{ + $DebugMode = Get-IcingaPowerShellConfig -Path 'Framework.DebugMode'; + + if ($null -eq $DebugMode) { + return $FALSE; + } + + return $DebugMode; +}