Compare commits
2 Commits
bdb9ee05e7
...
41082ce029
Author | SHA1 | Date | |
---|---|---|---|
41082ce029 | |||
17ce488ac3 |
@ -80,7 +80,6 @@ crit=0.9
|
||||
disk='/'
|
||||
script_name=$(basename "${0}")
|
||||
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
possibleavarages=("1" "5" "15")
|
||||
GetOptions "$@"
|
||||
|
||||
totalfull=$(df --output=size -B 1024 "${disk}" | tail -n 1 | xargs)
|
||||
|
@ -70,7 +70,6 @@ warn=0.7
|
||||
crit=0.9
|
||||
script_name=$(basename "${0}")
|
||||
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
possibleavarages=("1" "5" "15")
|
||||
GetOptions "$@"
|
||||
|
||||
totalfull=$(cat /proc/meminfo | grep MemTotal | awk '{ print $2; }')
|
||||
|
106
check-url.sh
Normal file
106
check-url.sh
Normal file
@ -0,0 +1,106 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
#/
|
||||
#/ Usage:
|
||||
#/ check-url.sh --proxy=<proxy-url> --warning=<level> --critical=<level> <URL>
|
||||
#/
|
||||
#/ Checks the disk usage
|
||||
#/
|
||||
#/ Options:
|
||||
#/ -p, --proxy=<proxy-url> The proxy server to use
|
||||
#/ -w, --warning=<sec> The amount of response time to trigger a warning (in sec)
|
||||
#/ -c, --critical=<sec> The amount of response time to trigger a critcal warning (in sec)
|
||||
#/
|
||||
#/ Exit Codes:
|
||||
#/ 0 Everything OK
|
||||
#/ 1 Warning level exceeded
|
||||
#/ 2 Critical level exceeded
|
||||
#/ 3 Unknown status
|
||||
#/
|
||||
|
||||
|
||||
Usage() {
|
||||
grep '^#/' "${script_dir}/${script_name}" | sed 's/^#\/\w*//'
|
||||
}
|
||||
|
||||
GetOptions() {
|
||||
# https://stackoverflow.com/a/29754866
|
||||
OPTIONS=p:w:c:
|
||||
LONGOPTS=proxy:,warning:,critical:
|
||||
|
||||
# -use ! and PIPESTATUS to get exit code with errexit set
|
||||
# -temporarily store output to be able to check for errors
|
||||
# -activate quoting/enhanced mode (e.g. by writing out “--options”)
|
||||
# -pass arguments only via -- "$@" to separate them correctly
|
||||
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
|
||||
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
|
||||
# e.g. return value is 1
|
||||
# then getopt has complained about wrong arguments to stdout
|
||||
Usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# read getopt's output this way to handle the quoting right:
|
||||
eval set -- "$PARSED"
|
||||
|
||||
# now enjoy the options in order and nicely split until we see --
|
||||
while true; do
|
||||
case "$1" in
|
||||
-p|--proxy)
|
||||
proxy="$2"
|
||||
shift 2
|
||||
;;
|
||||
-w|--warning)
|
||||
warn="$2"
|
||||
shift 2
|
||||
;;
|
||||
-c|--critital)
|
||||
crit="$2"
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "URL UNKNOWN - ${1} is not a valid parameter"
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z ${1+x} ]; then
|
||||
echo "URL UNKNOWN - url not given"
|
||||
exit 3
|
||||
else
|
||||
url=${1}
|
||||
fi
|
||||
}
|
||||
LC_NUMERIC="C"
|
||||
warn=1
|
||||
crit=2
|
||||
script_name=$(basename "${0}")
|
||||
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
url=''
|
||||
GetOptions "$@"
|
||||
|
||||
eval $(curl -L -o /dev/null -s -w 'RESPONSE_CODE=%{response_code}\nRESPONSE_TIME=%{time_total}\nDNS_TIME=%{time_namelookup}\nCONNECT_TIME=%{time_connect}' ${proxy:+"--proxy" "$proxy"} $url)
|
||||
rdetail=""
|
||||
if (( $(echo "$RESPONSE_CODE != 200" | bc -l) )); then
|
||||
rval=2
|
||||
rmsg="CRITICAL"
|
||||
rdetail="$url was not available"
|
||||
elif (( $(echo "$RESPONSE_TIME < ${warn}" | bc -l) )); then
|
||||
rval=0
|
||||
rmsg="OK"
|
||||
elif (( $(echo "$RESPONSE_TIME < ${crit}" | bc -l) )); then
|
||||
rval=1
|
||||
rmsg="WARNING"
|
||||
else
|
||||
rval=2
|
||||
rmsg="CRITICAL"
|
||||
fi
|
||||
unit='s'
|
||||
echo "URL ${rmsg} - ${rdetail:+"$rdetail - "}Response code: ${RESPONSE_CODE} Response Time: ${RESPONSE_TIME} DNS Lookup time: ${DNS_TIME} Connect time: ${CONNECT_TIME}|response=${RESPONSE_TIME}${unit} dns-query=${DNS_TIME}${unit} connect=${CONNECT_TIME}${unit}"
|
||||
exit $rval
|
Loading…
Reference in New Issue
Block a user