VMware Cloud Community
Rick360
Contributor
Contributor
Jump to solution

Script to pull latest hostd timestamp from all hosts in a cluster?

Hi all,

Lately I've seen an issue where my 5.1 host logging abruptly stops and other than remoting to each host I have no way of knowing this has occurred.

Is there a way to report the last, e.g. hostd.log  timestamp for each host in a cluster?

Thanks,

Tony

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

foreach($esx in Get-Cluster -Name MyCluster | Get-VMHost){
 
$log = Get-Log -Key hostd -VMHost $esx
 
$esx | Select Name,@{N="Last entry";E={[datetime]($log.entries[-1].Split(' ')[0])}}
}

But be warned that fetching a log from an ESXi this way might take a bit of time.

The script needs to fetch the complete log, to be able to extract the last line


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

foreach($esx in Get-Cluster -Name MyCluster | Get-VMHost){
 
$log = Get-Log -Key hostd -VMHost $esx
 
$esx | Select Name,@{N="Last entry";E={[datetime]($log.entries[-1].Split(' ')[0])}}
}

But be warned that fetching a log from an ESXi this way might take a bit of time.

The script needs to fetch the complete log, to be able to extract the last line


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Rick360
Contributor
Contributor
Jump to solution

This worked perfectly, took ~ 5 minutes in my 16 blade chassis.

Just curious though, what does this part do - [-1].Split(' ')[0])}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The property $log.Entries is an array, with each line of the log being an element in that array.

By using the [-1], you select the last entry of the entry. In this case the most recent entry in the log.

Each log entry follows a fixed layout: "datetimeindication message"

By splitting that line on the blanks in there, we get an array with a number of elements.

Since we want the first one, the timestamp, we index with [0].

Looks complicated, but once you get the hang of it, it comes naturally .


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos