mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Extends eventlog write function for pre-defined messages and object dump
This commit is contained in:
parent
abb2ab1e35
commit
935c497a7d
1 changed files with 40 additions and 5 deletions
|
|
@ -2,15 +2,50 @@ function Write-IcingaEventMessage()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[int]$EventId = 0,
|
[int]$EventId = 0,
|
||||||
[string]$Namespace = $null
|
[string]$Namespace = $null,
|
||||||
|
[array]$Objects = @()
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($EventId -eq 0 -Or $null -eq $Namespace) {
|
if ($EventId -eq 0 -Or [string]::IsNullOrEmpty($Namespace)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$EntryType = $IcingaEventLogEnums[$Namespace][$EventId].EntryType;
|
[string]$EntryType = $IcingaEventLogEnums[$Namespace][$EventId].EntryType;
|
||||||
$Message = $IcingaEventLogEnums[$Namespace][$EventId].Message;
|
[string]$Message = $IcingaEventLogEnums[$Namespace][$EventId].Message;
|
||||||
|
[string]$Details = $IcingaEventLogEnums[$Namespace][$EventId].Details;
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($Details)) {
|
||||||
|
$Details = '';
|
||||||
|
}
|
||||||
|
if ([string]::IsNullOrEmpty($Message)) {
|
||||||
|
$Message = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
[string]$ObjectDump = '';
|
||||||
|
|
||||||
|
if ($Objects.Count -eq 0) {
|
||||||
|
$ObjectDump = [string]::Format(
|
||||||
|
'{0}{0}No additional object details provided.',
|
||||||
|
(New-IcingaNewLine)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($entry in $Objects) {
|
||||||
|
$ObjectDump = [string]::Format(
|
||||||
|
'{0}{1}',
|
||||||
|
$ObjectDump,
|
||||||
|
($entry | Out-String)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[string]$EventLogMessage = [string]::Format(
|
||||||
|
'{0}{1}{1}{2}{1}{1}Object dumps if available:{1}{3}',
|
||||||
|
$Message,
|
||||||
|
(New-IcingaNewLine),
|
||||||
|
$Details,
|
||||||
|
$ObjectDump
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
if ($null -eq $EntryType -Or $null -eq $Message) {
|
if ($null -eq $EntryType -Or $null -eq $Message) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -20,5 +55,5 @@ function Write-IcingaEventMessage()
|
||||||
-Source 'Icinga for Windows' `
|
-Source 'Icinga for Windows' `
|
||||||
-EntryType $EntryType `
|
-EntryType $EntryType `
|
||||||
-EventId $EventId `
|
-EventId $EventId `
|
||||||
-Message $Message;
|
-Message $EventLogMessage;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue