|
||
---|---|---|
dist | ||
README.md | ||
build.sh | ||
go.mod | ||
go.sum | ||
host_check.go |
README.md
Purpose
This Go binary conducts network diagnostics on a set of hostnames, ideal for verifying connectivity to dependent services or containers.
Usage
-
Build: Execute the build script:
./build.sh
-
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'
).
- HOST_CHECK_HOSTNAMES: Comma-separated list of hostnames to check (e.g.,
-
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