VMware Cloud Community
halr9000
Commander
Commander
Jump to solution

Get-Log suggestions

I personally don't find Get-Log very useful as-is. I think it would be much better for the vi-tk to make these logs available as discrete objects, rather than an array of strings. It should work more like the builtin $error object. I'd like to do things like this:

Get-Log -type error | ? { $_.timestamp -ge $_.timestamp.adddays(-1) }

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

We agree with you and will try to address this issue for our Beta release.

Carter

View solution in original post

Reply
0 Kudos
3 Replies
admin
Immortal
Immortal
Jump to solution

We agree with you and will try to address this issue for our Beta release.

Carter

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

In the meantime you can play around with these functions.

Sorry about the formatting, this forum software is, well, special. The regex line below is supposed to read:

$hostdRegex = "\[(?<Date>[^ ]+) (?<Time>[^ ]+) (?<Object>'[^']+') (?<ID>[^ ]+) (?<Level>[^ ]+)\] (?<Message>.+)"

function Get-LogObject ($logLine)

{

$hostdRegex = "*** SEE LINE ABOVE ***"

$otherRegex = ""

if ($logLine -match $regex) {

$logObj = New-Object System.Management.Automation.PsObject

foreach ($property in "Date","Time","Object","ID","Level","Message") {

$logObj | Add-Member NoteProperty $property $matches.$property

}

$logObj

}

}

function Get-LogObjects

{

$logObjects = @()

while ($input.movenext()) {

$objects = $input.Current.Entries

foreach ($o in $objects) {

$logObject = Get-LogObject $o

if ($logObject) {

$logObjects += $logObject

}

}

}

$logObjects

}

The functions are not parsing out the dates, but that shouldn't be too hard. Unfortunately this stuff only supports hostd ATM. Other log facilities use different formats for some reason. Anyway, there's a number of ways to improve this so feel free to run with it.

To use it, do something like get-log -key hostd | get-logobjects

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

  1. I know a couple of guys at Jive, let me know if you need a back door.

  2. cool script, I'll try that.

  3. I'm a little concerned at your (I mean that in the plural "y'all" sense, not you personally) tendency to have singular and plural cmdlet/function names. That's gonna trip people up at the command line during tab completion.

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos