Happy new year
[pazpar2-moved-to-github.git] / etc / check-pazpar2.sh
1 #!/bin/sh
2
3 usage()
4 {
5 cat <<EOF    
6 usage: $0 options
7
8 This script run the test1 or test2 over a machine.
9
10 OPTIONS:
11    -h      Show this message
12    -H      host name or IP
13    -w      Warning level
14    -c      Critical level
15    -p      port name
16 EOF
17 }
18
19
20 MSG="OK";
21 HOST=localhost
22 PORT=8004
23
24 while getopts "hH:w:c:p:" OPTION
25 do 
26     case $OPTION in
27      h)  usage; exit 3;;
28      H)  
29             HOST=$OPTARG
30             ;;
31      p)  
32             PORT=$OPTARG
33             ;;
34      w)  
35             WARN_LEVEL=$OPTARG
36             ;;
37      c)  
38             CRIT_LEVEL=$OPTARG
39             ;;
40   esac
41 done
42
43 #echo $HOST $PORT $WARN_LEVEL $CRIT_LEVEL
44
45 `wget -q "http://$HOST:$PORT/search.pz2?command=server-status" -O- | xsltproc /etc/pazpar2/server-status-nagios.xsl - 2> /dev/null` 
46
47 if [ $? -ne 0 ] ; then
48     MSG="FATAL failed to communicate with pazpar2"
49     exit 128
50 fi
51
52 if [ "$WARN_LEVEL" != "" ] ; then 
53     if [ $SESSIONS -gt $WARN_LEVEL ];  then
54         MSG="WARNING "
55         rc=1; 
56     fi
57 fi 
58
59 if [ "$CRIT_LEVEL" != "" ] ; then 
60     if [ $SESSIONS -gt $CRIT_LEVEL ];  then
61         MSG="CRITICAL " 
62         rc=2;
63     fi
64 fi 
65
66 echo "SESSIONS $MSG $SESSIONS ($CLIENTS) [$VIRT,$VIRTUSE,$AREA,$ORDBLKS,$UORDBLKS,$FORDBLKS,$KEEPCOST,$HBLKS,$HBLKHD]   | $SESSIONS;$WARN_LEVEL;$CRIT_LEVEL "
67 exit $rc
68