Hi Dalmiro,
I created a new machine policy and tried to keep the default tentacle health check script and added my script after that as below. Is that fine ? I dont want to change what octopus is doing by default for tentacle health check.
$freeDiskSpaceThreshold = 5GB
Try {
Get-WmiObject win32_LogicalDisk -ErrorAction Stop | ? { ($.DriveType -eq 3) -and ($.FreeSpace -ne $null)} | % { CheckDriveCapacity @{Name =$.DeviceId; FreeSpace=$.FreeSpace} }
} Catch [System.Runtime.InteropServices.COMException] {
Get-WmiObject win32_Volume | ? { ($.DriveType -eq 3) -and ($.FreeSpace -ne $null) -and ($.DriveLetter -ne $null)} | % { CheckDriveCapacity @{Name =$.DriveLetter; FreeSpace=$.FreeSpace} }
Get-WmiObject Win32_MappedLogicalDisk | ? { ($.FreeSpace -ne $null) -and ($.DeviceId -ne $null)} | % { CheckDriveCapacity @{Name =$.DeviceId; FreeSpace=$_.FreeSpace} }
}
This script performs the following actions:
1) Read available disks in current system
2) get disk drive information - drive letter, drive size, free space, percent free
3) Email the status
function Send-Email
{
param( [string]$EmailTo, [string]$Body,[string]$computerName)
$Username =“xyz”
$Password = ConvertTo-SecureString “xyz” -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $Username, $Password
$SMTPServer = “smtp.sendgrid.net”
$EmailFrom = "MonitorDiskSpace@honeywell.com"
$Subject = “Disk space warning on $computerName”
Send-MailMessage -smtpServer $SMTPServer -Credential $credential -Usessl -Port 587 -from $EmailFrom -to $EmailTo -subject $Subject -Body $Body -BodyAsHtml
}
$users = "xyz@xyz.com"
$computerName = $env:computername
#change this value if you want to change percentage of space remaining which will trigger mail
$diskspaceFlag= 15;
$drives = Get-WmiObject -ComputerName $computerName Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}
foreach($drive in $drives)
{
$id = $drive.DeviceID
$size = [math]::round($drive.Size / 1073741824, 2)
$free = [math]::round($drive.FreeSpace / 1073741824, 2)
$pct = [math]::round($free / $size, 2) * 100
if ($pct -lt $diskspaceFlag) { $pct = $pct.ToString()
Send-Email -EmailTo $users -Body "
Disk space in $computerName $id drive is $pct" -computerName $computerName
}
$pct = 0
}
End of Script