vfast.example.nagios.sh
#!/bin/bash2 # The script to check url.status
3 # MAKE u(yangpenghao)
4 #exit status
5 ST_OK=0
6 ST_WR=1
7 ST_CR=2
8 ST_UK=3
9
10 while test -n "$1";do
11 case "$1" in
12 --url|-u)
13 URL=$2
14 shift
15 ;;
16 --host|-H)
17 HOST=$2
18 shift
19 ;;
20 *)
21 echo "fail"
22 exit $ST_UK
23 ;;
24 esac
25 shift
26 done
27
28 if [-n "$HOSTNAME" ] ;then
29 HTTP_STATUS=`curl -s -I"$URL" |head -n1|awk '{print $2}'`
30 else
31 HTTP_STATUS=`curl -s -I host:$HOSTNAME "$URL"|head -n1|awk '{print $2}'`
32 fi
33 if [ ! -n "$HTTP_STATUS" ] ;then
34 HTTP_STATUS="CONNET_ERROR"
35 fi
36
37 case $HTTP_STATUS in
38 200)
39 echo "OK HTTP $HTTP_STATUS ";
40 exit $ST_OK;
41 ;;
42 500|502|504|CONNET_ERROR)
43 echo "CRITICAL $HTTP_STATUS $URL";
44 exit $ST_CR;
45 ;;
46 *)
47 echo "WARNING $HTTP_STATUS";
48 exit $ST_WR
49 ;;
50 esac
页:
[1]