# 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:
   ```bash
   ./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:
   ```bash
   ./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:

```bash
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
```
