#!/bin/bash
#
# check_socks - Monitor a socks5 proxy
# Copyright (c) 2019 Ekhozie (ekhozie@users.noreply.github.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
HELP=false
IP='127.0.0.1'
PORT='1080'
TARGET='https://www.google.com'
MAX_TIME=10
OPTS=`getopt -o hi:p: --long max-time:,target:,help -n 'check_socks' -- "$@"`
if [[ $? != 0 ]] ; then
echo "UNKNOWN - Failed parsing options."
exit 3
fi
eval set -- "$OPTS"
while true; do
case "$1" in
-i ) IP="$2"; shift; shift ;;
-p ) PORT="$2"; shift; shift ;;
--target ) TARGET="$2"; shift; shift ;;
--max-time ) MAX_TIME="$2"; shift; shift ;;
-h | --help ) HELP=true; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done
if [[ $HELP == 'true' ]] ; then
cat </dev/null
ret=$?
tt=$((($(date +%s%N) - $ts)/1000000))
if [[ $ret -eq 0 ]] ; then
echo "OK - Latency ${tt}ms."
exit 0
else
echo "CRITICAL - Proxy is down, curl returns $ret after ${tt}ms"
exit 1
fi