Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI ISSUE] Ping checks output nonsensical #2061

Open
P6g9YHK6 opened this issue Nov 4, 2024 · 2 comments
Open

[UI ISSUE] Ping checks output nonsensical #2061

P6g9YHK6 opened this issue Nov 4, 2024 · 2 comments

Comments

@P6g9YHK6
Copy link

P6g9YHK6 commented Nov 4, 2024

Is your feature request related to a problem? Please describe.
The outputs of ping checks are unusable at best.
There is no Y axis explanation, the output does not explain why it failed
image

Describe the solution you'd like
just like cpu and ram the output should be on a chart with the answer time as the X value
output should be readable
and it should do only 1 ping not the default 3 or set the amount and average

Describe alternatives you've considered
back to scripting this one :/

@P6g9YHK6
Copy link
Author

P6g9YHK6 commented Nov 8, 2024

Here something i wiped up to patchwork this

<#
.SYNOPSIS
    A PowerShell script to check the reachability and response time of specified hosts or IP addresses.

.DESCRIPTION
    This script checks if a list of hosts or IP addresses (specified in the PING_TARGETS environment variable) is reachable by sending a single ping request.
    It outputs "OK" with the latency in milliseconds if the host is reachable, or "KO" if it is not.

.PARAMETER PING_TARGETS
    Environment variable that holds a comma-separated list of IP addresses or hostnames to ping.

.PARAMETER WarnThreshold
    The threshold in milliseconds for a warning. If the ping response time exceeds this threshold, the script will output a warning and exit with code 1.

.PARAMETER ErrorThreshold
    The threshold in milliseconds for an error. If the ping response time exceeds this threshold, the script will output an error and exit with code 2.

.NOTES
    Author: SAN
    Created: 08.11.24

.CHANGELOG
    
#>

# Set default threshold values (in ms)
$DefaultWarnThreshold = 100     # Default warning threshold in milliseconds
$DefaultErrorThreshold = 200   # Default error threshold in milliseconds

# Check for environment variables to override the default thresholds
$WarnThreshold = if ($env:PING_WARN_THRESHOLD) { [int]$env:PING_WARN_THRESHOLD } else { $DefaultWarnThreshold }
$ErrorThreshold = if ($env:PING_ERROR_THRESHOLD) { [int]$env:PING_ERROR_THRESHOLD } else { $DefaultErrorThreshold }

# Get the list of targets from the environment variable
$Targets = $env:PING_TARGETS -split ","   # Split comma-separated values into an array
$IsSingleTarget = ($Targets.Count -eq 1)  # Check if only one target is specified

if (-not $Targets) {
    Write-Output "No targets specified in the environment variable 'PING_TARGETS'. Exiting."
    exit 3
}

$ExitCode = 0   # Default exit code is 0 (success)

foreach ($Target in $Targets) {
    $Target = $Target.Trim()  # Remove any leading/trailing whitespace
    try {
        $PingResult = Test-Connection -ComputerName $Target -Count 1 -Quiet
        if ($PingResult) {
            # Calculate latency by measuring ping time manually
            $PingTime = (Measure-Command {Test-Connection -ComputerName $Target -Count 1 -Quiet}).TotalMilliseconds
            if ($IsSingleTarget) {
                Write-Output "$PingTime ms."
            } else {
                Write-Output "OK $Target $PingTime ms."
            }

            # Check for warnings and errors based on latency
            if ($PingTime -gt $ErrorThreshold) {
                Write-Output "Error: Ping time exceeded $ErrorThreshold ms."
                $ExitCode = 2  # Set exit code for error
            } elseif ($PingTime -gt $WarnThreshold) {
                Write-Output "Warning: Ping time exceeded $WarnThreshold ms."
                $ExitCode = 1  # Set exit code for warning (if error code not set)
            }
        } else {
            if ($IsSingleTarget) {
                Write-Output "KO"
            } else {
                Write-Output "KO $Target"
            }
            $ExitCode = 3  # Set exit code for failure
        }
    }
    catch {
        if ($IsSingleTarget) {
            Write-Output "KO (Error: $_)"
        } else {
            Write-Output "KO $Target (Error: $_)"
        }
        $ExitCode = 3  # Set exit code for failure
    }
}

# Exit with the determined exit code (warn = 1, error = 2, fail = 3)
$host.SetShouldExit($ExitCode)
exit $ExitCode

@P6g9YHK6
Copy link
Author

also noticed there is no alternative to ping to the python lib's
ping3 or equivalent should be added to the standard list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant