Add Nagios mode
Benjamin Renard

Benjamin Renard commited on 2014-12-31 09:08:39
Showing 1 changed files, with 22 additions and 2 deletions.

... ...
@@ -16,24 +16,29 @@ OWNER=root
16 16
 GROUP=www-data
17 17
 
18 18
 DEBUG=0
19
+NAGIOS=0
19 20
 UPGRADE=0
20 21
 EXTRACT=0
21 22
 JUST_DISP=0
22 23
 
23 24
 function usage() {
24
-	echo "Usage : $0 [-v] [-d] [-u]"
25
+	echo "Usage : $0 [-v] [-n] [-d] [-u]"
25 26
 	echo "  -v   Verbose mode"
27
+	echo "  -n   Nagios mode"
26 28
 	echo "  -d   Download new release"
27 29
 	echo "  -u   Upgrade installation"
28 30
 	echo "  -j   Just display current stable version"
29 31
 	echo "  -h   Display this help"
30 32
 }
31 33
 
32
-while getopts ":dvhuj" opt; do
34
+while getopts ":dvnhuj" opt; do
33 35
 	case $opt in
34 36
 		v)
35 37
 			DEBUG=1
36 38
 		;;
39
+		n)
40
+			NAGIOS=1
41
+		;;
37 42
 		d)
38 43
 			DOWNLOAD=1
39 44
 		;;
... ...
@@ -86,6 +91,7 @@ do
86 91
 		break;
87 92
 	elif [ $i -eq $MAX_CHECK ]
88 93
 	then
94
+		[ $NAGIOS -eq 1 ] && echo "WARNING : Fail to retrieve current stable version" && exit 1
89 95
 		error="Site du projet injoignable (ou structure du site modifie !!) => Impossible de recuperer le numero de la version stable actuel."
90 96
 		[ $DEBUG -eq 1 ] && echo $error
91 97
 		if [ -f $CACHE_FAILED ]
... ...
@@ -118,8 +124,21 @@ current="`echo $current|sed 's/-rc$//'`"
118 124
 current="`echo $current|sed 's/-beta$//'`"
119 125
 
120 126
 [ $DEBUG -eq 1 ] && echo "Current : $current"
127
+
128
+if [ -z "$current" ]
129
+then
130
+	[ $NAGIOS -eq 1 ] && echo "UNKNOWN : Fail to retrieve current installed version" && exit 3
131
+	echo "ERROR : Fail to retrieve current version !"
132
+	exit 3
133
+fi
134
+
121 135
 if [ "$newest" != "$current" ]
122 136
 then
137
+	if [ $NAGIOS -eq 1 ]
138
+	then
139
+		echo "CRITICAL : A newest version of Roundcube Webmail is available (newest : $newest / current : $current)"
140
+		exit 2
141
+	fi
123 142
 
124 143
 	if [ $DOWNLOAD -eq 1 ]
125 144
 	then
... ...
@@ -292,4 +311,5 @@ then
292 311
 	fi
293 312
 else
294 313
 	[ $DEBUG -eq 1 ] && echo "Pas de changement de version"
314
+	[ $NAGIOS -eq 1 ] && echo "OK : Lastest version installed" && exit 1
295 315
 fi
296 316