Add support to write into Windows Event Log (debug only for now)

This commit is contained in:
Christian Stein 2020-03-24 14:04:41 +01:00
parent edd8b4b6ed
commit b947f71f3a
5 changed files with 38 additions and 2 deletions

View file

@ -12,8 +12,9 @@
function Use-Icinga() function Use-Icinga()
{ {
param( param(
[switch]$LibOnly = $FALSE, [switch]$LibOnly = $FALSE,
[switch]$Daemon = $FALSE [switch]$Daemon = $FALSE,
[switch]$DebugMode = $FALSE
); );
# Ensure we autoload the Icinga Plugin collection, provided by the external # Ensure we autoload the Icinga Plugin collection, provided by the external
@ -29,6 +30,8 @@ function Use-Icinga()
Import-IcingaLib '\' -Init; Import-IcingaLib '\' -Init;
if ($LibOnly -eq $FALSE) { if ($LibOnly -eq $FALSE) {
Register-IcingaEventLog;
$global:IcingaThreads = [hashtable]::Synchronized(@{}); $global:IcingaThreads = [hashtable]::Synchronized(@{});
$global:IcingaThreadContent = [hashtable]::Synchronized(@{}); $global:IcingaThreadContent = [hashtable]::Synchronized(@{});
$global:IcingaThreadPool = [hashtable]::Synchronized(@{}); $global:IcingaThreadPool = [hashtable]::Synchronized(@{});
@ -38,6 +41,7 @@ function Use-Icinga()
'IcingaThreadContent' = $global:IcingaThreadContent; 'IcingaThreadContent' = $global:IcingaThreadContent;
'IcingaThreadPool' = $global:IcingaThreadPool; 'IcingaThreadPool' = $global:IcingaThreadPool;
'FrameworkRunningAsDaemon' = $Daemon; 'FrameworkRunningAsDaemon' = $Daemon;
'DebugMode' = $DebugMode;
} }
); );
} }

View file

@ -0,0 +1,4 @@
function Disable-IcingaFrameworkDebugMode()
{
$global:IcingaDaemonData.DebugMode = $FALSE;
}

View file

@ -0,0 +1,4 @@
function Enable-IcingaFrameworkDebugMode()
{
$global:IcingaDaemonData.DebugMode = $TRUE;
}

View file

@ -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';
}

View file

@ -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;
}