fbocolowski / sssm

Stupid Simple Server Monitor - UN*X Server monitoring app
MIT License
78 stars 10 forks source link

Add "ping-to-domain" support #7

Closed fbocolowski closed 5 years ago

fbocolowski commented 5 years ago

Allow option to make the server ping to multiple domains and return the result (OK or NOT OK).

benyanke commented 5 years ago

Would also love this.

fbocolowski commented 5 years ago

Here's a code snippet for a bash doing this:

SERVERS=("https://google.com", "https://github.com")
    for SERVER in ${SERVERS[@]}; do
      CURL_RESULT=`curl -s -o /dev/null -w "%{http_code} %{time_total}" $SERVER`
      CURL_CODE=`echo "$CURL_RESULT"| awk {'print $1'}`
      CURL_TIME=`echo "$CURL_RESULT"| awk {'print $2'}`
      echo "  $SERVER $CURL_CODE $CURL_TIME"
      if [ $CURL_CODE != "200" -a $CURL_CODE != "302" -a $CURL_CODE != "301" ]; then
        echo "  SERVER ERROR!"
        slack "Error connecting to $SERVER!\nResult was $CURL_CODE"
      else
        echo "  SERVER OK!"
      fi
    done