mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Add support to write into Windows Event Log (debug only for now)
This commit is contained in:
parent
edd8b4b6ed
commit
b947f71f3a
5 changed files with 38 additions and 2 deletions
|
|
@ -13,7 +13,8 @@ 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;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
lib/core/framework/Disable-IcingaFrameworkDebugMode.psm1
Normal file
4
lib/core/framework/Disable-IcingaFrameworkDebugMode.psm1
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
function Disable-IcingaFrameworkDebugMode()
|
||||||
|
{
|
||||||
|
$global:IcingaDaemonData.DebugMode = $FALSE;
|
||||||
|
}
|
||||||
4
lib/core/framework/Enable-IcingaFrameworkDebugMode.psm1
Normal file
4
lib/core/framework/Enable-IcingaFrameworkDebugMode.psm1
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
function Enable-IcingaFrameworkDebugMode()
|
||||||
|
{
|
||||||
|
$global:IcingaDaemonData.DebugMode = $TRUE;
|
||||||
|
}
|
||||||
12
lib/core/logging/Register-IcingaEventLog.psm1
Normal file
12
lib/core/logging/Register-IcingaEventLog.psm1
Normal 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';
|
||||||
|
}
|
||||||
12
lib/core/logging/Write-IcingaDebugMessage.psm1
Normal file
12
lib/core/logging/Write-IcingaDebugMessage.psm1
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue