6601dd9c2f91d17d144031c38f74f9ba9f173f13
Benjamin Renard Initial commit

Benjamin Renard authored 8 years ago

check-apt-cacher-ng   1) #!/bin/bash
Benjamin Renard Add plugin description at t...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng   2) #
check_apt_cacher_ng   3) # Nagios plugin to check Apt-cacher-ng status
check_apt_cacher_ng   4) #
check_apt_cacher_ng   5) # This plugin check apt-cacher-ng status by asking report page.
check_apt_cacher_ng   6) # It's able to parse result to retreive performance data.
check_apt_cacher_ng   7) #
check_apt_cacher_ng   8) # Copyright (c) 2015 Benjamin Renard <brenard@zionetrix.net>
check_apt_cacher_ng   9) #
check_apt_cacher_ng  10) # This program is free software; you can redistribute it and/or
check_apt_cacher_ng  11) # modify it under the terms of the GNU General Public License version 2
check_apt_cacher_ng  12) # as published by the Free Software Foundation.
check_apt_cacher_ng  13) #
check_apt_cacher_ng  14) # This program is distributed in the hope that it will be useful,
check_apt_cacher_ng  15) # but WITHOUT ANY WARRANTY; without even the implied warranty of
check_apt_cacher_ng  16) # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
check_apt_cacher_ng  17) # GNU General Public License for more details.
check_apt_cacher_ng  18) #
check_apt_cacher_ng  19) # You should have received a copy of the GNU General Public License
check_apt_cacher_ng  20) # along with this program; if not, write to the Free Software
check_apt_cacher_ng  21) # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
check_apt_cacher_ng  22) #
Benjamin Renard Initial commit

Benjamin Renard authored 8 years ago

check-apt-cacher-ng  23) 
check-apt-cacher-ng  24) HOST=127.0.0.1
check-apt-cacher-ng  25) PORT=3142
Benjamin Renard Permit to specify ReportPag...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng  26) REPORTPAGE=acng-report.html
Benjamin Renard Permit to specify auth info...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng  27) AUTHINFO=""
check_apt_cacher_ng  28) USER=""
check_apt_cacher_ng  29) PASS=""
Benjamin Renard Initial commit

Benjamin Renard authored 8 years ago

check-apt-cacher-ng  30) DO_PERFDATA=0
check-apt-cacher-ng  31) DEBUG=0
check-apt-cacher-ng  32) 
check-apt-cacher-ng  33) function usage() {
check-apt-cacher-ng  34) cat << EOF
Benjamin Renard Permit to specify auth info...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng  35) Usage : check_apt_cacher_ng [-H hostaddress] [-p port] [-r reportpage] [-a user:pass] [-Pdh]
Benjamin Renard Initial commit

Benjamin Renard authored 8 years ago

check-apt-cacher-ng  36) 
check-apt-cacher-ng  37)   -H hostaddress	Specify apt-cacher-ng host address (default=127.0.0.1)
check-apt-cacher-ng  38)   -p post		Specify apt-cacher-ng TCP port (default=3142)
Benjamin Renard Permit to specify ReportPag...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng  39)   -r reportpage		Specify apt-cacher-ng ReportPage parameter value (default=acng-report.html)
Benjamin Renard Permit to specify auth info...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng  40)   -a user:pass		Specify authentication informations with format 'user:pass'
Benjamin Renard Initial commit

Benjamin Renard authored 8 years ago

check-apt-cacher-ng  41)   -P			Include performance data
check-apt-cacher-ng  42)   -d			Enable debug mode
check-apt-cacher-ng  43)   -h			Show this help message
check-apt-cacher-ng  44) EOF
check-apt-cacher-ng  45) }
check-apt-cacher-ng  46) 
Benjamin Renard Permit to specify auth info...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng  47) while getopts "H:p:r:a:Pdh" OPTION
Benjamin Renard Initial commit

Benjamin Renard authored 8 years ago

check-apt-cacher-ng  48) do
check-apt-cacher-ng  49) 	case $OPTION in
check-apt-cacher-ng  50) 		H)
check-apt-cacher-ng  51) 			HOST=$OPTARG
check-apt-cacher-ng  52) 		;;
check-apt-cacher-ng  53) 		p)
check-apt-cacher-ng  54) 			PORT=$OPTARG
check-apt-cacher-ng  55) 		;;
Benjamin Renard Permit to specify ReportPag...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng  56) 		r)
check_apt_cacher_ng  57) 			REPORTPAGE=$OPTARG
check_apt_cacher_ng  58) 		;;
Benjamin Renard Permit to specify auth info...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng  59) 		a)
check_apt_cacher_ng  60) 			AUTHINFO=$OPTARG
check_apt_cacher_ng  61) 			USER=$( echo "$AUTHINFO"|cut -d':' -f 1 )
check_apt_cacher_ng  62) 			PASS=$( echo "$AUTHINFO"|cut -d':' -f 2 )
check_apt_cacher_ng  63) 			if [ -z "$USER" -o -z "$PASS" -o $( echo "$AUTHINFO"|grep -c ':' ) -ne 1 ]
check_apt_cacher_ng  64) 			then
check_apt_cacher_ng  65) 				echo "Authentification informations invalid. You must specify it using format : 'user:password'"
check_apt_cacher_ng  66) 				usage
check_apt_cacher_ng  67) 				exit 1
check_apt_cacher_ng  68) 			fi
check_apt_cacher_ng  69) 		;;
Benjamin Renard Initial commit

Benjamin Renard authored 8 years ago

check-apt-cacher-ng  70) 		P)
check-apt-cacher-ng  71) 			DO_PERFDATA=1
check-apt-cacher-ng  72) 		;;
check-apt-cacher-ng  73) 		d)
check-apt-cacher-ng  74) 			DEBUG=1
check-apt-cacher-ng  75) 		;;
check-apt-cacher-ng  76) 		h)
check-apt-cacher-ng  77) 			usage
check-apt-cacher-ng  78) 			exit 0
check-apt-cacher-ng  79) 		;;
check-apt-cacher-ng  80) 		\?)
check-apt-cacher-ng  81) 			echo "Invalid option: -$OPTARG" >&2
check-apt-cacher-ng  82) 			usage
check-apt-cacher-ng  83) 			exit 1
check-apt-cacher-ng  84) 		;;
check-apt-cacher-ng  85) 		:)
check-apt-cacher-ng  86) 			echo "Option -$OPTARG requires an argument." >&2
check-apt-cacher-ng  87) 			usage
check-apt-cacher-ng  88) 			exit 1
check-apt-cacher-ng  89) 		;;
check-apt-cacher-ng  90) 	esac
check-apt-cacher-ng  91) done
check-apt-cacher-ng  92) 
check-apt-cacher-ng  93) function debug() {
check-apt-cacher-ng  94) 	[ $DEBUG -eq 1 ] && echo "[DEBUG] $1"
check-apt-cacher-ng  95) }
check-apt-cacher-ng  96) 
check-apt-cacher-ng  97) html2text -version > /dev/null 2>&1
check-apt-cacher-ng  98) if [ $? -ne 0 ]
check-apt-cacher-ng  99) then
check-apt-cacher-ng 100) 	echo "UNKNOWN : html2text command not found"
check-apt-cacher-ng 101) 	exit 3
check-apt-cacher-ng 102) fi
check-apt-cacher-ng 103) 
Benjamin Renard Permit to specify ReportPag...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng 104) stats_url="http://$HOST:$PORT/$REPORTPAGE?doCount=Count+Data#top"
check_apt_cacher_ng 105) debug "Get apt-cacher-ng stats from $HOST:$PORT (URL : $stats_url)"
Benjamin Renard Permit to specify auth info...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng 106) wget_cmd="wget -O - $stats_url"
Benjamin Renard Initial commit

Benjamin Renard authored 8 years ago

check-apt-cacher-ng 107) 
Benjamin Renard Permit to specify auth info...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng 108) if [ -n "$AUTHINFO" ]
check_apt_cacher_ng 109) then
check_apt_cacher_ng 110) 	debug "Using auth info $USER:*****"
check_apt_cacher_ng 111) 	wget_cmd="$wget_cmd --user=$USER --password=$PASS"
check_apt_cacher_ng 112) fi
check_apt_cacher_ng 113) 
check_apt_cacher_ng 114) [ $DEBUG -ne 1 ] && wget_cmd="$wget_cmd -q"
check_apt_cacher_ng 115) 
check_apt_cacher_ng 116) stats=$( $wget_cmd )
check_apt_cacher_ng 117) res=$?
check_apt_cacher_ng 118) debug "Wget return code : $res"
check_apt_cacher_ng 119) 
check_apt_cacher_ng 120) if [ $res -ne 0 ]
Benjamin Renard Initial commit

Benjamin Renard authored 8 years ago

check-apt-cacher-ng 121) then
Benjamin Renard Permit to specify auth info...

Benjamin Renard authored 8 years ago

check_apt_cacher_ng 122) 	case $res in
check_apt_cacher_ng 123) 		4)
check_apt_cacher_ng 124) 			comment="(Network failure)"
check_apt_cacher_ng 125) 		;;
check_apt_cacher_ng 126) 		5)
check_apt_cacher_ng 127) 			comment="(SSL verification failure)"
check_apt_cacher_ng 128) 		;;
check_apt_cacher_ng 129) 		6)
check_apt_cacher_ng 130) 			comment="(Auth required)"
check_apt_cacher_ng 131) 		;;
check_apt_cacher_ng 132) 		7)
check_apt_cacher_ng 133) 			comment="(Protocol errors)"
check_apt_cacher_ng 134) 		;;
check_apt_cacher_ng 135) 		8)
check_apt_cacher_ng 136) 			comment="(Server issued an error response)"
check_apt_cacher_ng 137) 		;;
check_apt_cacher_ng 138) 		*)
check_apt_cacher_ng 139) 			comment=""
check_apt_cacher_ng 140) 		;;
check_apt_cacher_ng 141) 	esac
check_apt_cacher_ng 142) 
check_apt_cacher_ng 143) 	echo "CRITICAL : Fail to connect to apt-cacher-ng $comment"