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

@ -7,6 +7,7 @@ check-health.ps1, checks the system health
check-ipv4-address.ps1, checks the given IPv4 address for validity
check-ipv6-address.ps1, checks the given IPv6 address for validity
check-mac-address.ps1, checks the given MAC address for validity
check-ping.ps1, checks the ping latency to the internet
check-swap-space.ps1, checks the swap space for free space left
check-symlinks.ps1, checks every symlink in the given directory tree
check-windows-system-files.ps1, checks the validity of the Windows system files

1 Script Description
7 check-ipv4-address.ps1 checks the given IPv4 address for validity
8 check-ipv6-address.ps1 checks the given IPv6 address for validity
9 check-mac-address.ps1 checks the given MAC address for validity
10 check-ping.ps1 checks the ping latency to the internet
11 check-swap-space.ps1 checks the swap space for free space left
12 check-symlinks.ps1 checks every symlink in the given directory tree
13 check-windows-system-files.ps1 checks the validity of the Windows system files

View File

@ -34,6 +34,7 @@ Mega Collection of PowerShell Scripts
* [check-dns-resolution.ps1](Scripts/check-dns-resolution.ps1) - checks the DNS resolution with frequently used domain names
* [check-drive-space.ps1](Scripts/check-drive-space.ps1) - checks the given drive for free space left
* [check-health.ps1](Scripts/check-health.ps1) - checks the system health
* [check-ping.ps1](Scripts/check-ping.ps1) - checks the ping latency to the internet
* [check-swap-space.ps1](Scripts/check-swap-space.ps1) - checks the swap space for free space left
* [check-windows-system-files.ps1](Scripts/check-windows-system-files.ps1) - checks the validity of the Windows system files (requires admin rights)
* [enable-crash-dumps.ps1](Scripts/enable-crash-dumps.ps1) - enables the writing of crash dumps

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])"