Merge pull request #426 from Icinga:feature/add_detailed_exception_report_feature

Feature: Adds exception report

Adds a new feature to EventLog writer, allowing to parse an exception report to identity the exact root cause and location, on where the error occurred in first place.
This commit is contained in:
Lord Hepipud 2022-01-13 00:04:14 +01:00 committed by GitHub
commit 7c019e7cd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 7 deletions

View file

@ -27,6 +27,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#388](https://github.com/Icinga/icinga-powershell-framework/issues/388) Improves performance for testing if `Add-Type` functions have been added, by adding an internal test for newly introduced environment variables within a PowerShell session * [#388](https://github.com/Icinga/icinga-powershell-framework/issues/388) Improves performance for testing if `Add-Type` functions have been added, by adding an internal test for newly introduced environment variables within a PowerShell session
* [#417](https://github.com/Icinga/icinga-powershell-framework/issues/417) Adds support to allow the force creation of Icinga Agent certificates, even when they are already present on the system over Icinga Management Console installation * [#417](https://github.com/Icinga/icinga-powershell-framework/issues/417) Adds support to allow the force creation of Icinga Agent certificates, even when they are already present on the system over Icinga Management Console installation
* [#426](https://github.com/Icinga/icinga-powershell-framework/pull/426) Adds a new feature to EventLog writer, allowing to parse an exception report to identity the exact root cause and location, on where the error occurred in first place.
## 1.7.1 (2021-11-11) ## 1.7.1 (2021-11-11)

View file

@ -0,0 +1,60 @@
function Get-IcingaExceptionString()
{
param (
$ExceptionObject = $null
);
if ($null -eq $ExceptionObject) {
return '';
}
$ExceptionStack = New-Object -TypeName 'System.Text.StringBuilder';
$ExceptionStack.AppendLine('') | Out-Null;
$ExceptionStack.AppendLine('') | Out-Null;
$ExceptionStack.AppendLine('Icinga for Windows exception report:') | Out-Null;
if ([string]::IsNullOrEmpty($ExceptionObject.Exception.Message) -eq $FALSE) {
$ExceptionStack.AppendLine('') | Out-Null;
$ExceptionStack.AppendLine('Exception Message:') | Out-Null;
$ExceptionStack.AppendLine($ExceptionObject.Exception.Message) | Out-Null;
}
if ([string]::IsNullOrEmpty($ExceptionObject.InvocationInfo.InvocationName) -eq $FALSE) {
$ExceptionStack.AppendLine('') | Out-Null;
$ExceptionStack.AppendLine('Invocation Name:') | Out-Null;
$ExceptionStack.AppendLine($ExceptionObject.InvocationInfo.InvocationName) | Out-Null;
}
if ([string]::IsNullOrEmpty($ExceptionObject.InvocationInfo.CommandOrigin) -eq $FALSE) {
$ExceptionStack.AppendLine('') | Out-Null;
$ExceptionStack.AppendLine('Command Origin:') | Out-Null;
$ExceptionStack.AppendLine($ExceptionObject.InvocationInfo.CommandOrigin) | Out-Null;
}
if ([string]::IsNullOrEmpty($ExceptionObject.InvocationInfo.ScriptLineNumber) -eq $FALSE) {
$ExceptionStack.AppendLine('') | Out-Null;
$ExceptionStack.AppendLine('Script Line Number:') | Out-Null;
$ExceptionStack.AppendLine($ExceptionObject.InvocationInfo.ScriptLineNumber) | Out-Null;
}
if ([string]::IsNullOrEmpty($ExceptionObject.InvocationInfo.PositionMessage) -eq $FALSE) {
$ExceptionStack.AppendLine('') | Out-Null;
$ExceptionStack.AppendLine('Exact Position:') | Out-Null;
$ExceptionStack.AppendLine($ExceptionObject.InvocationInfo.PositionMessage) | Out-Null;
}
if ([string]::IsNullOrEmpty($ExceptionObject.Exception.StackTrace) -eq $FALSE) {
$ExceptionStack.AppendLine('') | Out-Null;
$ExceptionStack.AppendLine('StackTrace:') | Out-Null;
$ExceptionStack.AppendLine($ExceptionObject.Exception.StackTrace) | Out-Null;
}
$CallStack = Get-PSCallStack;
$ExceptionStack.AppendLine('') | Out-Null;
$ExceptionStack.AppendLine('Call Stack:') | Out-Null;
if ($CallStack.Count -gt 11) {
$ExceptionStack.AppendLine(($CallStack[0..10] | Out-String)) | Out-Null;
} else {
$ExceptionStack.AppendLine(($CallStack | Out-String)) | Out-Null;
}
$ExceptionStack.Remove($ExceptionStack.Length - 8, 8) | Out-Null;
return $ExceptionStack.ToString();
}

View file

@ -1,8 +1,9 @@
function Write-IcingaDebugMessage() function Write-IcingaDebugMessage()
{ {
param( param (
[string]$Message, [string]$Message,
[array]$Objects = @() [array]$Objects = @(),
$ExceptionObject = $null
); );
if ([string]::IsNullOrEmpty($Message)) { if ([string]::IsNullOrEmpty($Message)) {
@ -16,5 +17,5 @@ function Write-IcingaDebugMessage()
[array]$DebugContent = @($Message); [array]$DebugContent = @($Message);
$DebugContent += $Objects; $DebugContent += $Objects;
Write-IcingaEventMessage -EventId 1000 -Namespace 'Framework' -Objects $DebugContent; Write-IcingaEventMessage -EventId 1000 -Namespace 'Framework' -ExceptionObject $ExceptionObject -Objects $DebugContent;
} }

View file

@ -3,7 +3,8 @@ function Write-IcingaEventMessage()
param ( param (
[int]$EventId = 0, [int]$EventId = 0,
[string]$Namespace = $null, [string]$Namespace = $null,
[array]$Objects = @() [array]$Objects = @(),
$ExceptionObject = $null
); );
if ($EventId -eq 0 -Or [string]::IsNullOrEmpty($Namespace)) { if ($EventId -eq 0 -Or [string]::IsNullOrEmpty($Namespace)) {
@ -25,7 +26,7 @@ function Write-IcingaEventMessage()
if ($Objects.Count -eq 0) { if ($Objects.Count -eq 0) {
$ObjectDump = [string]::Format( $ObjectDump = [string]::Format(
'{0}{0}No additional object details provided.', '{0}No additional object details provided.',
(New-IcingaNewLine) (New-IcingaNewLine)
); );
} }
@ -39,12 +40,12 @@ function Write-IcingaEventMessage()
} }
[string]$EventLogMessage = [string]::Format( [string]$EventLogMessage = [string]::Format(
'{0}{1}{1}{2}{1}{1}Object dumps if available:{1}{3}', '{0}{1}{1}{2}{3}{1}{1}Object details:{1}{4}',
$Message, $Message,
(New-IcingaNewLine), (New-IcingaNewLine),
$Details, $Details,
(Get-IcingaExceptionString -ExceptionObject $ExceptionObject),
$ObjectDump $ObjectDump
); );
if ($null -eq $EntryType -Or $null -eq $Message) { if ($null -eq $EntryType -Or $null -eq $Message) {