# synology-disk-health.ps1 — DSM 7 disk health summary via HTTP API. # Run from any Windows box that can reach the NAS on its DSM port (default 5001 HTTPS). $Url = "YOUR_URL/synology" $NasUrl = "https://nas.local:5001" $User = "monitor" $Pass = "your-readonly-password" $SessionName = "alerts_monitor" # --- DSM session login ------------------------------------------------------ $Auth = Invoke-RestMethod -Method Get -SkipCertificateCheck ` -Uri "$NasUrl/webapi/auth.cgi?api=SYNO.API.Auth&version=6&method=login&account=$User&passwd=$Pass&session=$SessionName&format=cookie" if (-not $Auth.success) { $Body = (@{ nas_host = $NasUrl; error = "login failed (code $($Auth.error.code))" }) | ConvertTo-Json -Compress Invoke-RestMethod -Uri $Url -Method Post -Body $Body -ContentType "application/json" -TimeoutSec 15 | Out-Null exit 1 } $Sid = $Auth.data.sid try { # --- Read storage info ------------------------------------------------- $StorageResp = Invoke-RestMethod -Method Get -SkipCertificateCheck ` -Uri "$NasUrl/webapi/entry.cgi?api=SYNO.Storage.CGI.Storage&version=1&method=load_info&_sid=$Sid" if (-not $StorageResp.success) { throw "load_info failed (code $($StorageResp.error.code))" } $Disks = @{} $AnyUnhealthy = $false $MaxTemp = 0 foreach ($d in $StorageResp.data.disks) { $temp = if ($null -ne $d.temp) { [int]$d.temp } else { 0 } if ($temp -gt $MaxTemp) { $MaxTemp = $temp } $Disks[$d.id] = @{ name = "$($d.name)" model = "$($d.model)" status = "$($d.status)" temp_c = $temp } if ($d.status -ne 'normal') { $AnyUnhealthy = $true } } $Body = (@{ nas_host = $NasUrl disk_count = $Disks.Count disks = $Disks any_unhealthy = $AnyUnhealthy max_temp_c = $MaxTemp }) | ConvertTo-Json -Compress -Depth 5 Invoke-RestMethod -Uri $Url -Method Post -Body $Body ` -ContentType "application/json" -TimeoutSec 15 | Out-Null } finally { # Always log out so DSM doesn't accumulate sessions. Invoke-RestMethod -Method Get -SkipCertificateCheck ` -Uri "$NasUrl/webapi/auth.cgi?api=SYNO.API.Auth&version=6&method=logout&session=$SessionName&_sid=$Sid" | Out-Null }