Go to file
Colin 30701d8910 Fixup 2024-04-18 11:55:01 -04:00
dist Fixup 2024-04-18 11:55:01 -04:00
README.md Fixup 2024-04-18 11:55:01 -04:00
build.sh Fixup 2024-04-18 11:55:01 -04:00
go.mod Fixup 2024-04-18 11:55:01 -04:00
go.sum Fixup 2024-04-18 11:55:01 -04:00
host_check.go Fixup 2024-04-18 11:55:01 -04:00

README.md

Purpose

This Go binary conducts network diagnostics on a set of hostnames, ideal for verifying connectivity to dependent services or containers.

Usage

  1. Build: Execute the build script:

    ./build.sh
    
  2. Set Environment Variables:

    • HOST_CHECK_HOSTNAMES: Comma-separated list of hostnames to check (e.g., database,redis-server,api.example.com).
    • HOST_CHECK_FAIL_ON_ERROR (optional): Set to "true" to halt execution immediately if a ping to any hostname fails.
    • HOST_CHECK_COMMAND (optional): Command to execute if all hosts are successfully pinged (e.g., entrypoint.sh to run a script on each host).
    • HOST_CHECK_ERROR_COMMAND (optional): Command to execute if a ping fails, useful for automated error handling (e.g., go-glitch report-error <hostname> 'Ping failed').
  3. Run: Start the host check:

    ./host_check
    

Output

For each hostname, the output includes:

  • DNS Resolution: Indicates success or failure, displaying resolved IPs if successful.
  • Ping: Indicates success or failure, including ping statistics if successful.
  • Custom Script: Displays the output of the HOST_CHECK_COMMAND script, if executed.
  • Error Reporting: Displays the output of the HOST_CHECK_ERROR_COMMAND, if a ping failure occurs.

Example

To verify connectivity to "db-container" and "webserver", execute the entrypoint.sh script, and handle errors via go-glitch:

export HOST_CHECK_HOSTNAMES="db-container,webserver"
export HOST_CHECK_COMMAND="entrypoint.sh"
export HOST_CHECK_ERROR_COMMAND="go-glitch report-error <hostname> 'Ping failed'"
./host_check