Atlantis ILIO – Storage Usage Monitoring with Powershell

Here is simple Powershell script and plink.exe, I used to monitor Atlantis ILIO disk usage:

Atlantis-ILIO-Persistent-VDI-4.0

#Function to process single server
Function Get-AtlantisStat($server)
{
      #connect to host once to get rsa2 key
      echo Y | .\plink -l poweruser -pw poweruser $server "pwd" | Out-Null
 
      #No connect for real
      $res = (echo Y | .\plink -l username -pw password $server "df -h | grep export") -split "\s+"
 
      #Create object
      $obj = New-Object System.Object
      $obj | Add-Member -Type NoteProperty -Name Server -Value $server
      $obj | Add-Member -Type NoteProperty -Name ReportDate -Value $(Get-Date -Format d)
      $obj | Add-Member -Type NoteProperty -Name Filesystem -Value $res[0]
      $obj | Add-Member -Type NoteProperty -Name Size -Value $res[1]
      $obj | Add-Member -Type NoteProperty -Name Used -Value $res[2]
      $obj | Add-Member -Type NoteProperty -Name Available -Value $res[3]   
      $obj | Add-Member -Type NoteProperty -Name UsedPercent -Value $res[4]
      $obj | Add-Member -Type NoteProperty -Name MountedOn -Value $res[5]
 
      #return object
      return $obj
}
 
#Define servers
$servers_list = "172.21.104.101",
                        "172.21.104.102",
                        "172.21.104.103",
                        "172.21.104.104",
                        "172.21.104.105",
                        "172.21.104.106",
                        "172.21.104.107",
                        "172.21.104.108",
                        "172.21.104.109",
                        "172.21.104.110",
			"172.21.104.100",
                        "172.21.104.111",
			"172.21.104.122",
                        "172.21.104.112",
                        "172.21.104.113",
			"172.21.104.123",
                        "172.21.104.114",
			"172.21.104.124",
                        "172.21.104.115",
			"172.21.104.117",
                        "172.21.104.119",
			"172.21.104.121"

$Atlantis = $servers_list | %{get-AtlantisStat $_}

$recipients = "vojin@test.local"
$fromEmail = "atlantis@test.local"
$server = "smtp.test.local"

$a = "<style>"
$a = $a + "BODY{background-color:White;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:White}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:White}"
$a = $a + "</style>"

$EmailBody = @()

ForEach ($Atlanti in $Atlantis) {
 IF ([INT]($Atlanti.UsedPercent -replace '%') -gt 80) {
    $EmailBody += $Atlanti
    }
  }

$EmailBody | Select Server, ReportDate, Filesystem, Size, Used, Available, UsedPercent, MountedOn | ConvertTo-HTML -head $a -body "<H2>XEN Atlantis Storage Usage VMs</H2>"
 
if($EmailBody)
{
send-mailmessage -from $fromEmail -to $recipients -subject " Atlantis Storage Usage VMs" -Bodyashtml ($EmailBody | Out-String) -priority High -smtpServer $server
}