Scheduled Check on Octopus

Hi ,

With the amazing Octopus architecture i have the ability to connect to all my servers , run scripts etc. It has been really helpful for our deployments. I want to use Octopus tentacle architecture to schedule some check on the servers using PS script like check logs for error everyday , SSL Certificate expiration check etc. I know Octopus is not built for this but is it something which is achievable by making some workaround. if we can achieve it it will fix few big issues which we are facing right now. Please help .

HI,

Thanks for reaching out. Like you said, Octopus wasn’t exactly built for this, but there’s a feature in it that you could use to achieve this called Machine Policies: https://octopus.com/docs/key-concepts/environments/machine-policies

With this feature you can customize what happens when you run health checks on your machines. So you could technically add scripts to check SSL, Logs, etc.

Hope that helps,
Dalmiro

Awesome Thanks Dalmiro. Let me check on this.

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

That should be fine. Still, I’d recommend you to test this thoroughly before setting it as the default policy for your prod machines.

Sure would do. Thanks Grañas and I have to say Octopus support is the best support team I have worked with. You guys are just awesome!!

Thanks for the kind words! They’ve been passed to the rest of the team in Slack :slight_smile: