Add check-ping.ps1

This commit is contained in:
Markus Fleschutz
2021-03-30 09:06:30 +02:00
parent 3a0daeb85a
commit 67f114831d
6 changed files with 35 additions and 2 deletions

View File

@ -22,7 +22,7 @@ try {
write-warning "Drive $Drive has only $Free GB left to use! ($Used GB out of $Total GB in use, minimum is $MinLevel GB)"
exit 1
}
write-host -foregroundColor green "OK - drive $Drive has $Free GB left ($Used GB of $Total GB used)"
write-host -foregroundColor green "OK - $Free GB left on drive $Drive ($Used GB of $Total GB used)"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -32,6 +32,9 @@ if (-not($IsLinux)) {
& check-dns-resolution.ps1
if ($lastExitCode -ne "0") { $Healthy = 0 }
& check-ping.ps1
if ($lastExitCode -ne "0") { $Healthy = 0 }
if ($Healthy) {
write-host -foregroundColor green "OK - $Hostname is healthy"
exit 0

28
Scripts/check-ping.ps1 Executable file
View File

@ -0,0 +1,28 @@
#!/bin/powershell
<#
.SYNTAX ./check-ping.ps1
.DESCRIPTION checks the ping latency to the internet
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
try {
write-verbose "Sending pings to the internet ..."
$Pings = test-connection -count 1 -computerName heise.de,cnn.com,github.com,www.microsoft.com,dropbox.com,amazon.com,google.com,bing.com,youtube.com
[int]$Min = 9999999
[int]$Max = 0
[int]$Avg = 0
foreach($Ping in $Pings) {
if ($Ping.latency -lt $Min) { $Min = $Ping.latency }
if ($Ping.latency -gt $Max) { $Max = $Ping.latency }
$Avg += $Ping.latency
}
$Avg = $Avg / $Pings.count
write-host -foregroundColor green "OK - $Avg ms average ping latency ($Min ms min, $Max ms max)"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -31,7 +31,7 @@ try {
write-warning "Swap space has only $Free GB left to use! ($Used GB out of $Total GB in use, minimum is $MinLevel GB)"
exit 1
}
write-host -foregroundColor green "OK - swap space has $Free GB left ($Used GB of $Total GB used)"
write-host -foregroundColor green "OK - $Free GB left on swap space ($Used GB of $Total GB used)"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"