mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-09 13:04:59 +02:00
Add check-health.ps1
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#!/bin/powershell
|
||||
<#
|
||||
.SYNTAX ./train-dns-cache.ps1
|
||||
.DESCRIPTION trains the DNS cache with frequently used domain names
|
||||
.SYNTAX ./check-dns-resolution.ps1
|
||||
.DESCRIPTION checks the DNS resolution with frequently used domain names
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
@ -18,14 +18,14 @@ try {
|
||||
|
||||
foreach($Row in $Table) {
|
||||
$Domain = $Row.Domain
|
||||
write-progress "Training DNS cache with $Domain..."
|
||||
write-progress "Resolving $Domain..."
|
||||
$Ignore = nslookup $Domain
|
||||
}
|
||||
|
||||
$Count = $Table.Length
|
||||
$StopTime = Get-Date
|
||||
$TimeInterval = New-Timespan -start $StartTime -end $StopTime
|
||||
write-host -foregroundColor green "Done - DNS cache trained with $Count domain names in $TimeInterval seconds"
|
||||
write-host -foregroundColor green "OK - resolved $Count domain names in $TimeInterval seconds"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
@ -14,15 +14,15 @@ if ($Drive -eq "" ) {
|
||||
|
||||
try {
|
||||
$DriveDetails = (get-psdrive $Drive)
|
||||
[int]$FreeSpace = (($DriveDetails.Free / 1024) / 1024) / 1024
|
||||
[int]$InUse = (($DriveDetails.Used / 1024) / 1024) / 1024
|
||||
[int]$Total = ($InUse + $FreeSpace)
|
||||
[int]$Free = (($DriveDetails.Free / 1024) / 1024) / 1024
|
||||
[int]$Used = (($DriveDetails.Used / 1024) / 1024) / 1024
|
||||
[int]$Total = ($Used + $Free)
|
||||
|
||||
if ($FreeSpace -lt $MinLevel) {
|
||||
write-warning "Drive $Drive has only $FreeSpace GB left to use! ($InUse GB out of $Total GB in use, minimum is $MinLevel GB)"
|
||||
if ($Free -lt $MinLevel) {
|
||||
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 $FreeSpace GB left to use ($InUse GB out of $Total GB in use, minimum is $MinLevel GB)"
|
||||
write-host -foregroundColor green "OK - $Free GB free at drive $Drive ($Used GB used out of $Total GB, $MinLevel GB is minimum)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
36
Scripts/check-health.ps1
Executable file
36
Scripts/check-health.ps1
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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 /
|
||||
} else {
|
||||
& check-drive-space.ps1 C
|
||||
}
|
||||
if ($lastExitCode -ne "0") { throw "check-drive-space.ps1 failed" }
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user