From a9c967550cf5ea2cf124d4301a818a0bdb8fded5 Mon Sep 17 00:00:00 2001 From: Pressacco <5507864+Pressacco@users.noreply.github.com> Date: Wed, 28 Aug 2024 22:21:52 +0000 Subject: [PATCH 1/2] New : Added new PowerShell cmdlet called `Get-Records` #155 --- .../BlueDotBrigade.Weevil.PowerShell.csproj | 38 ++++++++++++++ .../GetRecordsCmdlet.cs | 50 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 Src/BlueDotBrigade.Weevil.PowerShell/BlueDotBrigade.Weevil.PowerShell.csproj create mode 100644 Src/BlueDotBrigade.Weevil.PowerShell/GetRecordsCmdlet.cs diff --git a/Src/BlueDotBrigade.Weevil.PowerShell/BlueDotBrigade.Weevil.PowerShell.csproj b/Src/BlueDotBrigade.Weevil.PowerShell/BlueDotBrigade.Weevil.PowerShell.csproj new file mode 100644 index 00000000..23033e90 --- /dev/null +++ b/Src/BlueDotBrigade.Weevil.PowerShell/BlueDotBrigade.Weevil.PowerShell.csproj @@ -0,0 +1,38 @@ + + + + net8.0 + BlueDotBrigade.Weevil.PowerShell + BlueDotBrigade.Weevil.PowerShell + Library + false + 2.11.0 + BlueDotBrigade; + © 2022 Blue Dot Brigade. All rights reserved. + Blue Dot Brigade + Blue Dot Brigade + PowerShell Cmdlets for the Weevil log viewer application. + BlueDotBrigade.Weevil.PowerShell + BlueDotBrigade;Weevil;Log Viewer; + git + https://github.com/BlueDotBrigade/weevil + https://github.com/BlueDotBrigade/weevil.git + 1.0.0 + true + Apache-2.0 + 2.11.0.0 + 2.11.0.0 + enable + true + + + + + + + + + + + + diff --git a/Src/BlueDotBrigade.Weevil.PowerShell/GetRecordsCmdlet.cs b/Src/BlueDotBrigade.Weevil.PowerShell/GetRecordsCmdlet.cs new file mode 100644 index 00000000..bff475f1 --- /dev/null +++ b/Src/BlueDotBrigade.Weevil.PowerShell/GetRecordsCmdlet.cs @@ -0,0 +1,50 @@ +using System; +using System.Management.Automation; +using BlueDotBrigade.Weevil.Core; +using BlueDotBrigade.Weevil.Core.Filtering; + +namespace BlueDotBrigade.Weevil.PowerShell +{ + /* + # Assuming you have already loaded the BlueDotBrigade.Weevil.PowerShell module + $logFilePath = "C:\Temp\Application.log" + $records = Get-Records -FilePath $logFilePath -Include "Id=2" -Exclude "Error" + $records | ForEach-Object { Write-Host $_ } + */ + [Cmdlet(VerbsCommon.Get, "Records")] + public class GetRecordsCmdlet : Cmdlet + { + [Parameter(Position = 0, Mandatory = true)] + public string FilePath { get; set; } + + [Parameter(Position = 1, Mandatory = false)] + public FilterType FilterType { get; set; } = FilterType.RegularExpression; + + [Parameter(Position = 2, Mandatory = false)] + public string Include { get; set; } = string.Empty; + + [Parameter(Position = 3, Mandatory = false)] + public string Exclude { get; set; } = string.Empty; + + protected override void ProcessRecord() + { + try + { + IEngine engine = Engine + .UsingPath(this.FilePath) + .Open(); + + var filterCriteria = new FilterCriteria(this.Include, this.Exclude); + + var filteredEntries = engine.Filter.Apply(this.FilterType, filterCriteria); + + this.WriteObject(filteredEntries, enumerateCollection: true); + } + catch (Exception ex) + { + // Handle any errors that occur during processing + this.WriteError(new ErrorRecord(ex, "FilterError", ErrorCategory.InvalidOperation, this)); + } + } + } +} From 9ab5cc372be9580b3b9c70fc3e9129e1c7088575 Mon Sep 17 00:00:00 2001 From: Pressacco <5507864+Pressacco@users.noreply.github.com> Date: Wed, 28 Aug 2024 22:26:47 +0000 Subject: [PATCH 2/2] New : Added `Get-Insight` cmdlet #294 --- .../GetInsightCmdlet.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Src/BlueDotBrigade.Weevil.PowerShell/GetInsightCmdlet.cs diff --git a/Src/BlueDotBrigade.Weevil.PowerShell/GetInsightCmdlet.cs b/Src/BlueDotBrigade.Weevil.PowerShell/GetInsightCmdlet.cs new file mode 100644 index 00000000..880b54fe --- /dev/null +++ b/Src/BlueDotBrigade.Weevil.PowerShell/GetInsightCmdlet.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Management.Automation; +using BlueDotBrigade.Weevil.Core; +using BlueDotBrigade.Weevil.Core.Analysis; +using BlueDotBrigade.Weevil.Core.Filtering; + +namespace BlueDotBrigade.Weevil.PowerShell +{ + + /* + # Assuming you have already loaded the BlueDotBrigade.Weevil.PowerShell module + $logFilePath = "C:\Temp\Application.log" + + $insights = Get-Insight -FilePath $logFilePath + + $insights | ForEach-Object { + Write-Host "Title: $_.Title" + Write-Host "Metric: $_.MetricValue $_.MetricUnit" + Write-Host "Details: $_.Details" + Write-Host "Attention Required: $_.IsAttentionRequired" + Write-Host "-------------------------------------" + } + */ + [Cmdlet(VerbsCommon.Get, "Insight")] + public class GetInsightCmdlet : Cmdlet + { + [Parameter(Position = 0, Mandatory = true)] + public string FilePath { get; set; } + + protected override void ProcessRecord() + { + try + { + IEngine engine = Engine + .UsingPath(this.FilePath) + .Open(); + + IEnumerable insights = engine.Analyzer.GetInsights(); + + foreach (var insight in insights) + { + this.WriteObject(insight); + } + } + catch (Exception ex) + { + // Handle any errors that occur during processing + this.WriteError(new ErrorRecord(ex, "InsightError", ErrorCategory.InvalidOperation, this)); + } + } + } +}