#!/bin/bash source /usr/lib/nagios/plugins/utils.sh PROGNAME=`basename $0` status_query_default="/status" print_usage() { echo "Usage: $PROGNAME -H fe.host.ru [-Q /status] [-F]" echo "Options:" echo "-H - Hostname where nginx server is running" echo "-Q - Query string, like /status [Default: $status_query_default]" echo "-F - show performance data" } print_help() { echo $PROGNAME $REVISION echo "" print_usage echo "" echo "Will show connections info" echo "" exit $UNKNOWN } ### Parse Arguments while getopts ":hV:H:Q:F" Option; do case $Option in h) print_help exit 0 ;; V) print_revision $PROGNAME $REVISION exit 0 ;; H) status_host=${OPTARG} ;; Q) status_query=${OPTARG} ;; F) show_perfdata="yes" ;; *) print_help exit 0 ;; esac done shift $(($OPTIND - 1)) if [[ "x$status_host" == "x" ]] then echo "No hostname specified, hostname should be like host.ru" exit $STATE_UNKNOWN fi if [[ "x$status_query" == "x" ]] then #echo "No query specified, query should be like /status" #exit $STATE_UNKNOWN status_query=$status_query_default fi status_url="${status_host}$status_query" #URL=$1 reslt=$(lynx --dump $status_url|head -n 3|tail -n 1) reslt_code=$? #echo "return $reslt_code" if [[ "x$reslt_code" != "x0" ]] then echo "lynx returned $reslt_code as return code, message is:$reslt" exit $STATE_UNKNOWN fi if [[ "x$reslt" != "x" ]] then EXITTEXT="not actual check: $reslt" if [[ "x$show_perfdata" == "xyes" ]] then DATA_TMP=`mktemp /tmp/nagios_check.XXXXXXXX` echo $reslt > $DATA_TMP #echo "result is:$reslt" >> /tmp/nagios.frontendtest.log read fe_accepts fe_handled fe_requests fe_rest < $DATA_TMP rm -rf $DATA_TMP #echo "fe_accepts:$fe_accepts" >> /tmp/nagios.frontendtest.log #echo "fe_handled:$fe_handled" >> /tmp/nagios.frontendtest.log #echo "fe_requests:$fe_requests" >> /tmp/nagios.frontendtest.log k=0 for i in $fe_accepts $fe_handled $fe_requests do let k+=1 c=0 #echo "i is $i" valuecheck=$(let "c+=$i") if [[ ($? != 0 ) || (($c < 0)) ]] then #echo "fuck! $c" exit_unknown="yes" fe_connections[$k]=0 else fe_connections[$k]=$i fi done EXITTEXT="${EXITTEXT}|'fe_accepts'=${fe_connections[1]}c;;;0; 'fe_handled'=${fe_connections[2]}c;;;0; 'fe_requests'=${fe_connections[3]}c;;;0;" #echo "exit text: $EXITTEXT" >> /tmp/nagios.frontendtest.log fi echo $EXITTEXT if [[ "x$exit_unknown" == "xyes" ]] then exit $STATE_UNKNOWN fi else echo "status is empty, whattafuck?" exit $STATE_UNKNOWN fi