Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_http.sh
1.0
2013-09-01
- Nagios 1.x
- Nagios 2.x
- Nagios 3.x
- Nagios 4.x
- Nagios XI
- Nagios Fusion
- Nagios Reactor
39538
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
It works on HTTP and HTTPS.
Requirement: curl
Usage ./check_http.sh
Example:
./check_http.sh 'http://oglobo.globo.com' oglobo 1
OK - Site oglobo.globo.com key oglobo time 0.019 |'time'=0.019s;1
#!/bin/bash
#Verificar um HTTPS
#Felipe Ferreira set 2013
URL=$1
KEY=$2
CRIT=$3
http_proxy=""
DEBUG=
if [ -z $CRIT ]; then
echo "Usage $0 "
exit 3
fi
TC=`echo ${URL} | awk -F. '{print $1}' |awk -F/ '{print $NF}'`
TMP="/tmp/check_http_sh_${TC}.tmp"
CMD_TIME="curl -k --location --no-buffer --silent --output ${TMP} -w %{time_connect}:%{time_starttransfer}:%{time_total} '${URL}'"
TIME=`eval $CMD_TIME`
if [ -f $TMP ]; then
RESULT=`grep -c $KEY $TMP`
else
echo "UNKOWN - Could not create tmp file $TMP"
# exit 3
fi
TIMETOT=`echo $TIME | gawk -F: '{ print $3 }'`
if [ ! -z $DEBUG ]; then
echo "CMD_TIME: $CMD_TIME"
echo "NUMBER OF $KEY FOUNDS: $RESULT"
echo "TIMES: $TIME"
echo "TIME TOTAL: $TIMETOT"
echo "TMP: $TMP"
ls $TMP
fi
rm -f $TMP
SURL=`echo $URL | cut -d "/" -f3-4`
MSGOK="Site $SURL key $KEY time $TIMETOT |'time'=${TIMETOT}s;${CRIT}"
MSGKO="Site $SURL has problems, time $TIMETOT |'time'=${TIMETOT}s;${CRIT}"
#PERFDATA HOWTO 'label'=value[UOM];[warn];[crit];[min];[max]
if [ "$RESULT" -ge "1" ] && [ $(echo "$TIMETOT < $CRIT"|bc) -eq 1 ]; then
echo "OK - $MSGOK"
exit 0
else
echo "CRITICAL - $MSGKO"
exit 2
fi
#Verificar um HTTPS
#Felipe Ferreira set 2013
URL=$1
KEY=$2
CRIT=$3
http_proxy=""
DEBUG=
if [ -z $CRIT ]; then
echo "Usage $0
exit 3
fi
TC=`echo ${URL} | awk -F. '{print $1}' |awk -F/ '{print $NF}'`
TMP="/tmp/check_http_sh_${TC}.tmp"
CMD_TIME="curl -k --location --no-buffer --silent --output ${TMP} -w %{time_connect}:%{time_starttransfer}:%{time_total} '${URL}'"
TIME=`eval $CMD_TIME`
if [ -f $TMP ]; then
RESULT=`grep -c $KEY $TMP`
else
echo "UNKOWN - Could not create tmp file $TMP"
# exit 3
fi
TIMETOT=`echo $TIME | gawk -F: '{ print $3 }'`
if [ ! -z $DEBUG ]; then
echo "CMD_TIME: $CMD_TIME"
echo "NUMBER OF $KEY FOUNDS: $RESULT"
echo "TIMES: $TIME"
echo "TIME TOTAL: $TIMETOT"
echo "TMP: $TMP"
ls $TMP
fi
rm -f $TMP
SURL=`echo $URL | cut -d "/" -f3-4`
MSGOK="Site $SURL key $KEY time $TIMETOT |'time'=${TIMETOT}s;${CRIT}"
MSGKO="Site $SURL has problems, time $TIMETOT |'time'=${TIMETOT}s;${CRIT}"
#PERFDATA HOWTO 'label'=value[UOM];[warn];[crit];[min];[max]
if [ "$RESULT" -ge "1" ] && [ $(echo "$TIMETOT < $CRIT"|bc) -eq 1 ]; then
echo "OK - $MSGOK"
exit 0
else
echo "CRITICAL - $MSGKO"
exit 2
fi
Reviews (1)
byMoore, January 15, 2019
I recommend making a modification to to enclose $KEY in quotes in the line containing
RESULT=`grep -c $KEY $TMP`
so that multiple word keys separated by spaces can be used.
RESULT=`grep -c $KEY $TMP`
so that multiple word keys separated by spaces can be used.