5 Replies Latest reply on Aug 13, 2014 12:01 PM by LucD

    vSphere events with PowerCLI

    sbartle Novice

      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

        • 1. Re: vSphere events with PowerCLI
          LucD Guru
          Community WarriorsvExpertUser Moderators

          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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: vSphere events with PowerCLI
            sbartle Novice

            Thank you very much LucD, worked like a charm.

            • 3. Re: vSphere events with PowerCLI
              sbartle Novice

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

              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

              • 4. Re: vSphere events with PowerCLI
                vmk2014 Expert

                Hi,

                I ran the script but the output is blank.

                 

                PowerCLI C:\temp> .\vSphere_Events.ps1

                 

                 

                 

                 

                esxhost     :

                datastore   :

                cluster     :

                createdtime :

                message     :

                 

                Thanks

                vmk2014

                • 5. Re: vSphere events with PowerCLI
                  LucD Guru
                  vExpertCommunity WarriorsUser Moderators

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

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz