retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-mq-connection
index a245762..2ed45ca 100755 (executable)
@@ -61,19 +61,41 @@ if [ "${prefix/[^a-z0-9-]/}" != "$prefix" ]; then
        exit 3
 fi
 
-sudo -u rabbitmq rabbitmqctl list_queues -p ${vhost} name messages consumers \
-       | grep "${prefix}-${host}.debian.org" \
-       | while read name messages consumers; do
-       if [ "${name}" != "${prefix}-${host}.debian.org" ]; then
-               echo "Unexpected output: ${name} ${messages} ${consumers}"
-               exit 3
-       fi
-       if [ "${messages}" -gt 0 ] ; then
-               if [ "${consumers}" -eq 0 ]; then
-                       echo "${host} not connected to MQ"
-                       exit 2
+check_output() {
+       found=0
+       while read name messages consumers; do
+               found=1
+               if [ "${name}" != "${prefix}-${host}.debian.org" ]; then
+                       echo "Unexpected output: ${name} ${messages} ${consumers}"
+                       return 3
+               fi
+               if [ "${messages}" -gt 0 ] ; then
+                       if [ "${consumers}" -eq 0 ]; then
+                               echo "${host} not connected to MQ"
+                               return 2
+                       fi
                fi
+               return 0
+       done
+       if [ $found = 0 ]; then
+               return 2
        fi
-done
-echo "${host} connected to ${prefix}-${host}.debian.org in ${vhost}"
-exit 0
+}
+
+check_conn () {
+       sudo -u rabbitmq rabbitmqctl list_queues -p ${vhost} name messages consumers \
+               | grep "${prefix}-${host}.debian.org" \
+               | check_output
+       ret=$?
+       if [ $ret != 0 ]; then
+               echo "${host} not connected to MQ"
+               return 2
+       fi
+       return 0
+}
+check_conn
+ret=$?
+if [ $ret -eq 0 ]; then
+       echo "${host} connected to ${prefix}-${host}.debian.org in ${vhost}"
+fi
+exit $ret