VMware Cloud Community
sbartle
Contributor
Contributor
Jump to solution

vSphere events with PowerCLI

Hi all,

I need a little help writing a script to view storage events and extract the relevant data I’m after. More specifically I want to run a report that looks at anytime a esxi 5.5 server has lost access to a volume.

So far I have this.

Get-VIEvent

Then added a few filters.

Get-VIEvent | select EventTypeId, objectname, FullFormattedMessage | ft -wrap

  1. esx.clear.scsi.device.io.latency.improved            esxXXX.ad.murdoch.edu.au                              Device naa.60030d90b0791d05fa6fe90fc655f11b

                                                                                                               performance has improved. I/O latency reduced from 

                                                                                                               22060 microseconds to 10269 microseconds.          

  1. esx.clear.scsi.device.io.latency.improved            esxXXC.ad.murdoch.edu.au                              Device naa.60030d90b0791d05fa6fe90fc655f11b

                                                                                                               performance has improved. I/O latency reduced from 

                                                                                                               112376 microseconds to 22060 microseconds.         

  1. esx.problem.scsi.device.io.latency.high              esxXXB.ad.murdoch.edu.au                              Device naa.60030d90b0791d05fa6fe90fc655f11b

                                                                                                               performance has deteriorated. I/O latency increased

                                                                                                               from average value of 5258 microseconds to 112376  

                                                                                                               microseconds.                                      

What I noticed was some of the events are missing, specifically “Lost access to volume 00000000-00000000-0000-000000000000 (Local-Disk-0) due to connectivity issues. Recovery attempt is in progress and outcome will be reported shortly.” I can see them in the Web GUI but can’t locate them via powerCLI.

Can anyone point me to the right direction on where this object event could be queried by powerCLI?


Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

It could be that these are shown as EventEx objects.

When you do

$start = (Get-Date).AddDays(-1)

Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) |

where {$_.FullFormattedMessage -match "lost access"} |

Select FullFormattedMessage,@{N="Type";E={$_.GetType().Name}}

Do you get any results back ?


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

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

It could be that these are shown as EventEx objects.

When you do

$start = (Get-Date).AddDays(-1)

Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) |

where {$_.FullFormattedMessage -match "lost access"} |

Select FullFormattedMessage,@{N="Type";E={$_.GetType().Name}}

Do you get any results back ?


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

Reply
0 Kudos
sbartle
Contributor
Contributor
Jump to solution

Thank you very much LucD, worked like a charm.

Reply
0 Kudos
sbartle
Contributor
Contributor
Jump to solution

I hope this final code will save some future hair loss.:smileymischief:

It will find the event and link the Host,Datastore,Cluster,timecreated and message into something readable.

$start = (get-date).adddays(-1)

$events = Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) | where {$_.FullFormattedMessage -match "lost access"}

$objects = @()

foreach ($event in $events)

{

    $esxhost = $event | select -ExpandProperty host

    $datastore = $event | select -ExpandProperty ds

    $cluster = $event | select -ExpandProperty computeresource

    $object = new-object -TypeName psobject

    $object | add-member -MemberType NoteProperty -Name 'esxhost' -Value $esxhost.name

    $object | Add-Member -MemberType NoteProperty -Name 'datastore' -Value $datastore.name

    $object | Add-Member -MemberType NoteProperty -Name 'cluster' -Value $cluster.name

    $object | add-member -MemberType NoteProperty -Name 'createdtime' -Value $event.CreatedTime

    $object | Add-Member -MemberType NoteProperty -Name 'message' -Value $event.FullFormattedMessage

    $objects += $object

}

$objects

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Hi,

I ran the script but the output is blank.

PowerCLI C:\temp> .\vSphere_Events.ps1

esxhost     :

datastore   :

cluster     :

createdtime :

message     :

Thanks

vmk2014

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That could mean that there was no event with the "lost connection" message during the last day.


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

Reply
0 Kudos