diff --git a/icinga-powershell-framework.psm1 b/icinga-powershell-framework.psm1 index 2818aa0..640926c 100644 --- a/icinga-powershell-framework.psm1 +++ b/icinga-powershell-framework.psm1 @@ -12,8 +12,9 @@ function Use-Icinga() { param( - [switch]$LibOnly = $FALSE, - [switch]$Daemon = $FALSE + [switch]$LibOnly = $FALSE, + [switch]$Daemon = $FALSE, + [switch]$DebugMode = $FALSE ); # Ensure we autoload the Icinga Plugin collection, provided by the external @@ -29,6 +30,8 @@ function Use-Icinga() Import-IcingaLib '\' -Init; if ($LibOnly -eq $FALSE) { + Register-IcingaEventLog; + $global:IcingaThreads = [hashtable]::Synchronized(@{}); $global:IcingaThreadContent = [hashtable]::Synchronized(@{}); $global:IcingaThreadPool = [hashtable]::Synchronized(@{}); @@ -38,6 +41,7 @@ function Use-Icinga() 'IcingaThreadContent' = $global:IcingaThreadContent; 'IcingaThreadPool' = $global:IcingaThreadPool; 'FrameworkRunningAsDaemon' = $Daemon; + 'DebugMode' = $DebugMode; } ); } diff --git a/lib/core/framework/Disable-IcingaFrameworkDebugMode.psm1 b/lib/core/framework/Disable-IcingaFrameworkDebugMode.psm1 new file mode 100644 index 0000000..ebd30f5 --- /dev/null +++ b/lib/core/framework/Disable-IcingaFrameworkDebugMode.psm1 @@ -0,0 +1,4 @@ +function Disable-IcingaFrameworkDebugMode() +{ + $global:IcingaDaemonData.DebugMode = $FALSE; +} diff --git a/lib/core/framework/Enable-IcingaFrameworkDebugMode.psm1 b/lib/core/framework/Enable-IcingaFrameworkDebugMode.psm1 new file mode 100644 index 0000000..9ee7d15 --- /dev/null +++ b/lib/core/framework/Enable-IcingaFrameworkDebugMode.psm1 @@ -0,0 +1,4 @@ +function Enable-IcingaFrameworkDebugMode() +{ + $global:IcingaDaemonData.DebugMode = $TRUE; +} diff --git a/lib/core/logging/Register-IcingaEventLog.psm1 b/lib/core/logging/Register-IcingaEventLog.psm1 new file mode 100644 index 0000000..0ed2167 --- /dev/null +++ b/lib/core/logging/Register-IcingaEventLog.psm1 @@ -0,0 +1,12 @@ +function Register-IcingaEventLog() +{ + $Registered = [System.Diagnostics.EventLog]::SourceExists( + 'Icinga for Windows' + ); + + if ($Registered) { + return; + } + + New-EventLog -LogName Application -Source 'Icinga for Windows'; +} diff --git a/lib/core/logging/Write-IcingaDebugMessage.psm1 b/lib/core/logging/Write-IcingaDebugMessage.psm1 new file mode 100644 index 0000000..473d129 --- /dev/null +++ b/lib/core/logging/Write-IcingaDebugMessage.psm1 @@ -0,0 +1,12 @@ +function Write-IcingaDebugMessage() +{ + param( + [string]$Message + ); + + if ($global:IcingaDaemonData.DebugMode -eq $FALSE) { + return; + } + + Write-EventLog -LogName Application -Source 'Icinga for Windows' -EntryType Information -EventId 1000 -Message $Message; +}