PowerShell/Scripts/check-health.ps1

41 lines
1.1 KiB
PowerShell
Raw Normal View History

2021-03-20 15:51:03 +01:00
#!/bin/powershell
<#
.SYNTAX ./check-health.ps1
.DESCRIPTION checks the system health
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
try {
$Hostname = $(hostname)
"Checking health of $Hostname ..."
& check-swap-space.ps1
if ($lastExitCode -ne "0") { throw "check-swap-space.ps1 failed" }
if ($IsLinux) {
& check-drive-space.ps1 /
2021-03-20 16:13:54 +01:00
if ($lastExitCode -ne "0") { throw "check-drive-space.ps1 failed" }
2021-03-20 15:51:03 +01:00
} else {
& check-drive-space.ps1 C
2021-03-20 16:13:54 +01:00
if ($lastExitCode -ne "0") { throw "check-drive-space.ps1 failed" }
2021-03-20 15:51:03 +01:00
}
2021-03-20 16:13:54 +01:00
& check-cpu-temp.ps1
if ($lastExitCode -ne "0") { throw "check-cpu-temp.ps1 failed" }
2021-03-20 15:51:03 +01:00
if (-not($IsLinux)) {
& check-windows-system-files.ps1
if ($lastExitCode -ne "0") { throw "check-windows-system-files.ps1 failed" }
}
& check-dns-resolution.ps1
if ($lastExitCode -ne "0") { throw "check-dns-resolution.ps1 failed" }
write-host -foregroundColor green "OK - $Hostname is healthy"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}