Initial commit
Benjamin Renard

Benjamin Renard commited on 2015-06-30 14:43:45
Showing 2 changed files, with 151 additions and 0 deletions.

... ...
@@ -0,0 +1,43 @@
1
+Nagios plugin to check Apt-cacher-NG status
2
+===========================================
3
+
4
+Usage
5
+-----
6
+
7
+  Usage : check_apt_cacher_ng [-H hostaddress] [-p port] [-Pdh]
8
+  
9
+    -H hostaddress	Specify apt-cacher-ng host address (default=127.0.0.1)
10
+    -p post		Specify apt-cacher-ng TCP port (default=3142)
11
+    -P			Include performance data
12
+    -d			Enable debug mode
13
+    -h			Show this help message
14
+
15
+Requirements
16
+------------
17
+
18
+ - html2text
19
+ - sed
20
+ - egrep
21
+ - tail
22
+ - awk
23
+
24
+Copyright
25
+---------
26
+
27
+Copyright (c) 2015 Benjamin Renard
28
+
29
+License
30
+-------
31
+
32
+This program is free software; you can redistribute it and/or
33
+modify it under the terms of the GNU General Public License version 2
34
+as published by the Free Software Foundation.
35
+
36
+This program is distributed in the hope that it will be useful,
37
+but WITHOUT ANY WARRANTY; without even the implied warranty of
38
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
+GNU General Public License for more details.
40
+
41
+You should have received a copy of the GNU General Public License
42
+along with this program; if not, write to the Free Software
43
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
... ...
@@ -0,0 +1,108 @@
1
+#!/bin/bash
2
+
3
+HOST=127.0.0.1
4
+PORT=3142
5
+DO_PERFDATA=0
6
+DEBUG=0
7
+
8
+function usage() {
9
+cat << EOF
10
+Usage : check_apt_cacher_ng [-H hostaddress] [-p port] [-Pdh]
11
+
12
+  -H hostaddress	Specify apt-cacher-ng host address (default=127.0.0.1)
13
+  -p post		Specify apt-cacher-ng TCP port (default=3142)
14
+  -P			Include performance data
15
+  -d			Enable debug mode
16
+  -h			Show this help message
17
+EOF
18
+}
19
+
20
+while getopts "H:p:Pdh" OPTION
21
+do
22
+	case $OPTION in
23
+		H)
24
+			HOST=$OPTARG
25
+		;;
26
+		p)
27
+			PORT=$OPTARG
28
+		;;
29
+		P)
30
+			DO_PERFDATA=1
31
+		;;
32
+		d)
33
+			DEBUG=1
34
+		;;
35
+		h)
36
+			usage
37
+			exit 0
38
+		;;
39
+		\?)
40
+			echo "Invalid option: -$OPTARG" >&2
41
+			usage
42
+			exit 1
43
+		;;
44
+		:)
45
+			echo "Option -$OPTARG requires an argument." >&2
46
+			usage
47
+			exit 1
48
+		;;
49
+	esac
50
+done
51
+
52
+function debug() {
53
+	[ $DEBUG -eq 1 ] && echo "[DEBUG] $1"
54
+}
55
+
56
+html2text -version > /dev/null 2>&1
57
+if [ $? -ne 0 ]
58
+then
59
+	echo "UNKNOWN : html2text command not found"
60
+	exit 3
61
+fi
62
+
63
+debug "Get apt-cacher-ng stats from $HOST:$PORT"
64
+stats=$( wget -q -O - http://$HOST:$PORT/acng-report.html?doCount=Count+Data#top )
65
+
66
+if [ $? -ne 0 ]
67
+then
68
+	echo "CRITICAL : Fail to connect to apt-cacher-ng"
69
+	exit 2
70
+fi
71
+
72
+stats_line=$( echo -e "$stats"|html2text -width 300|grep '^ *Period' -A 2|tail -n 1 )
73
+if [ -z "$stats_line" ]
74
+then
75
+	echo "WARNING : Fail to parse apt-cacher-ng stats page"
76
+	exit 1
77
+fi
78
+
79
+if [ $DO_PERFDATA -eq 1 ]
80
+then
81
+	cache_req_hits_count=$( echo -e "$stats_line"|awk '{print $6}'|sed 's/^[^0-9]*//' )
82
+	cache_req_hits_per=$( echo -e "$stats_line"|cut -d '(' -f 2|cut -d')' -f 1|sed 's/^[^0-9]*//' )
83
+	cache_req_misses_count=$( echo -e "$stats_line"|awk '{print $8}'|sed 's/^[^0-9]*//' )
84
+	cache_req_misses_per=$( echo -e "$stats_line"|cut -d '(' -f 3|cut -d')' -f 1|sed 's/^[^0-9]*//' )
85
+	cache_req_total_count=$( echo -e "$stats_line"|awk '{print $10}'|sed 's/^[^0-9]*//' )
86
+
87
+	cache_data_hits_count=$( echo -e "$stats_line"|awk '{print $11$12}'|sed 's/^[^0-9]*//' )
88
+	cache_data_hits_per=$( echo -e "$stats_line"|cut -d '(' -f 4|cut -d')' -f 1|sed 's/^[^0-9]*//' )
89
+	cache_data_misses_count=$( echo -e "$stats_line"|awk '{print $14$15}'|sed 's/^[^0-9]*//' )
90
+	cache_data_misses_per=$( echo -e "$stats_line"|cut -d '(' -f 4|cut -d')' -f 1|sed 's/^[^0-9]*//' )
91
+	cache_data_total_count=$( echo -e "$stats_line"|awk '{print $17$18}'|sed 's/^[^0-9]*//' )
92
+
93
+	PERF_DATA="|cache_req_hits_count=$cache_req_hits_count"
94
+	PERF_DATA="$PERF_DATA,cache_req_hits_per=$cache_req_hits_per"
95
+	PERF_DATA="$PERF_DATA,cache_req_misses_count=$cache_req_misses_count"
96
+	PERF_DATA="$PERF_DATA,cache_req_misses_per=$cache_req_misses_per"
97
+	PERF_DATA="$PERF_DATA,cache_req_total_count=$cache_req_total_count"
98
+	PERF_DATA="$PERF_DATA,cache_data_hits_count=$cache_data_hits_count"
99
+	PERF_DATA="$PERF_DATA,cache_data_hits_per=$cache_data_hits_per"
100
+	PERF_DATA="$PERF_DATA,cache_data_misses_count=$cache_data_misses_count"
101
+	PERF_DATA="$PERF_DATA,cache_data_misses_per=$cache_data_misses_per"
102
+	PERF_DATA="$PERF_DATA,cache_data_total_count=$cache_data_total_count"
103
+else
104
+	PERF_DATA=""
105
+fi
106
+
107
+echo "OK - Apt-cacher-ng is running$PERF_DATA"
108
+exit 0
0 109