Adds support to store debugmode state in config and make it globally available

This commit is contained in:
Christian Stein 2020-03-27 16:39:47 +01:00
parent e8f2152010
commit dff16d8f0d
4 changed files with 27 additions and 9 deletions

View file

@ -29,15 +29,6 @@ function Use-Icinga()
Import-IcingaLib '\' -Init -Custom; Import-IcingaLib '\' -Init -Custom;
Import-IcingaLib '\' -Init; 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) { if ($LibOnly -eq $FALSE) {
Register-IcingaEventLog; Register-IcingaEventLog;
@ -66,6 +57,21 @@ function Use-Icinga()
$global:IcingaDaemonData.FrameworkRunningAsDaemon = $Daemon; $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() function Import-IcingaLib()

View file

@ -1,4 +1,5 @@
function Disable-IcingaFrameworkDebugMode() function Disable-IcingaFrameworkDebugMode()
{ {
$global:IcingaDaemonData.DebugMode = $FALSE; $global:IcingaDaemonData.DebugMode = $FALSE;
Set-IcingaPowerShellConfig -Path 'Framework.DebugMode' -Value $FALSE;
} }

View file

@ -1,4 +1,5 @@
function Enable-IcingaFrameworkDebugMode() function Enable-IcingaFrameworkDebugMode()
{ {
$global:IcingaDaemonData.DebugMode = $TRUE; $global:IcingaDaemonData.DebugMode = $TRUE;
Set-IcingaPowerShellConfig -Path 'Framework.DebugMode' -Value $TRUE;
} }

View file

@ -0,0 +1,10 @@
function Get-IcingaFrameworkDebugMode()
{
$DebugMode = Get-IcingaPowerShellConfig -Path 'Framework.DebugMode';
if ($null -eq $DebugMode) {
return $FALSE;
}
return $DebugMode;
}