Kontrola voľného miesta na datastores

Vo fórach sa pomerne často stretávam s problémom zapĺneného datastore (dôvodom sú často “zabudnuté snapshots”). Ak nemáte Enterprise Plus licencie s funkcionalitou Storage DRS a nastavenie percentuálneho zaplnenia datastorov v alarmoch vám nevyhovuje, Ponúkam vám script na sledovanie voľnej kapacity.V podmienkach je zadané:

  • FreeSpace menej ako 20 GB
  • Nebrať do úvahy konkrétny adresár (v ktorom sú špeciálne datastores)
  • Nebrať do úvahy konkrétny Datacenter

ParentFolderID je možné zistiť:

Get-Datastore esx1:datastore1 | Select-Object ParentFolderID

Samotný script zasiela e-mailom tabuľku s informáciami:

  • Meno affectovaného datastore
  • Voľné miesto na danom datastore
  • Zapnuté VMs na danom datastore
  • Počet vypnutých VMs na danom datastore

Samotný script:

add-pssnapin VMware.VimAutomation.Core
connect-VIserver -server vc.yourcompany.com

$style = "<style>BODY{font-family:Arial;font-size:10pt;}"
$style = $style + "TABLE{border:1px solid black;border-collapse:collapse;}"
$style = $style + "TH{border:1px solid black;background:#dddddd;padding:5px;}"
$style = $style + "TD{border:1px solid black;padding:5px;}"
$style = $style + "</style>"

$mail = "name@yourcompany.com"

$DSFreeSpace = Get-Datastore | Where-Object { $_.FreeSpaceGB -lt "20" -and $_.ParentFolderID -ne "Folder-group-s000" -and $_.DatacenterID -ne "Datacenter-datacenter-00000" }
$PoweredOnVMs = @{N="Powered on VMs";E={Get-VM -Datastore $_.Name | Where-Object {$_.PowerState -eq "PoweredOn"}}}
$PoweredOffVMsCount = @{N="Powered off VMs(count)";E={(Get-VM -Datastore $_.Name | Where-Object {$_.PowerState -eq "PoweredOff"}).Count}}

if ($DSFreeSpace -ne $null){
$DSFreeSpaceReport = $DSFreeSpace | Select-Object Name,FreeSpaceGB,$PoweredOnVMs,$PoweredOffVMsCount


$DSFreeSpaceReportHTML = $DSFreeSpaceReport | ConvertTo-Html -Head $style
send-mailmessage -from "Name1 <name1@yourcompany.com>" -to $mail -subject "Criticky malo volneho miesta na datastore" `
-BodyAsHtml "$($DSFreeSpaceReportHTML) <br><br><b> <font color=red>POZOR!</b></font> <br><br>Dakujeme<br>Name1" -smtpServer smtpserver.yourcompany.com
}

Author: Martin

Infrastructure engineer | virtualization & cloud enthusiast | vSphere specialist | blogger | VMware vExpert 2017, 2018, 2019, 2020 | VMCE | Slovak VMUG Leader |  user group ambassador for kmug.sk | husband&father

Leave a Reply

Your email address will not be published. Required fields are marked *