The greatest challenge to any thinker is stating the problem in a way that will allow a solution

Bertrand Russell

By

On 27 Jul 2011

PowerCLI, VMware

Tags: , , , , ,


A while back I came across an intermittent storage problem, whereby paths were occasionally going down and coming back up for a period of time.  In order to be able to tally the timings of the events up with other goings on (eg when looking at SAN logs etc) I needed to create a an export of when the events were occurring.

Note that Get-VIEvent is limited to 1000 results, which will typically get 1 – 2 days worth depending on your infrastructure. To get a longer history would require multiple calls to Get-VIEvent using the -Start and -Finish parameters

$OutputFile = "ESX-EventsStorage.csv"
 
$Results = @()
$events = Get-VIEvent -MaxSamples 1000 | Where {$_.EventTypeID -like "esx.*.storage.*"}
foreach ($event in $events) {
    $row = "" | Select Date, Host, EventID, Device, Datastore, Path
    $row.Date = $event.CreatedTime
    $row.Host = $event.Host.Name.Split(".")[0]
    $row.EventID = $event.EventTypeID
    # Allow for Argument Keys being mixed up between "problem" aka fault start and "clear" aka fault end events
    $row.Device = $event.Arguments[0].Value
    if ($row.EventID -like "esx.problem.*") {
        $row.Datastore = $event.Arguments[2].Value
        $row.Path = $event.Arguments[1].Value
    } elseif ($row.EventID -like "esx.clear.*") {
        $row.Datastore = $event.Arguments[1].Value
        $row.Path = $event.Arguments[2].Value
    } else {
        Write-Host "ERROR: Unexpected EventTypeID - " $row.EventID
    }
    $Results = $Results + $row
}
$Results | Format-Table *
$Results | Export-Csv -path $OutputFile -NoTypeInformation

Leave a Reply

XHTML: You can use these tags if you know what they are: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.