Skip to content

Instantly share code, notes, and snippets.

@ZappaBoy
Created November 14, 2022 11:16
Show Gist options
  • Save ZappaBoy/7fa719316b9deaef0de1069dab7f7a90 to your computer and use it in GitHub Desktop.
Save ZappaBoy/7fa719316b9deaef0de1069dab7f7a90 to your computer and use it in GitHub Desktop.
This simple script call the check-host.net API to check host status through ping, http, tcp and dns checks.
#!/usr/bin/env bash
# Created by: ZappaBoy
# Usage: ./check-host "your.domain"
# This simple script call the check-host.net API to check host status through ping, http, tcp and dns checks.
base_url='https://check-host.net'
headers="Accept: application/json"
sleep_time=10
declare -a check_types=("ping" "http" "tcp" "dns")
check_host(){
curl -s -H "$headers" "$base_url/check-$1?host=$2" | jq '.request_id'
}
check_result(){
request_id=$(echo "$request_id" | tr -d '"')
curl -s -H "$headers" "$base_url/check-result/$request_id"
}
check(){
local check_type="$1"
local host="$2"
request_id=$(check_host "$check_type" "$host")
echo "$check_type request id: $request_id"
sleep "$sleep_time"
check_result "$request_id"
}
check_ping(){
check 'ping' "$1"
}
check_http(){
check 'http' "$1"
}
check_tcp(){
check 'tcp' "$1"
}
check_dns(){
check 'dns' "$1"
}
check_all_sequentially(){
check_ping "$1" | jq
check_http "$1" | jq
check_tcp "$1" | jq
check_dns "$1" | jq
}
check_all(){
declare -a requests_ids=()
for check_type in "${check_types[@]}"; do
echo "Checking: $check_type"
request_id=$(check_host "$check_type" "$1")
requests_ids+=("$request_id")
done
sleep "$sleep_time"
for request_id in "${requests_ids[@]}"; do
echo "Getting result: $request_id"
check_result "$request_id" | jq
done
}
check_all "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment