From 1f0246a8ea0f4263d90d0ffce30950dd52af790f Mon Sep 17 00:00:00 2001 From: Stephen Gran Date: Sun, 19 Jan 2014 12:18:09 +0000 Subject: [PATCH] make the check actually work Signed-off-by: Stephen Gran --- .../checks/dsa-check-mq-connection | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/dsa-nagios-checks/checks/dsa-check-mq-connection b/dsa-nagios-checks/checks/dsa-check-mq-connection index a245762..96fe26a 100755 --- a/dsa-nagios-checks/checks/dsa-check-mq-connection +++ b/dsa-nagios-checks/checks/dsa-check-mq-connection @@ -61,19 +61,25 @@ 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_conn () { + 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}" + return 3 fi - fi -done -echo "${host} connected to ${prefix}-${host}.debian.org in ${vhost}" -exit 0 + if [ "${messages}" -gt 0 ] ; then + if [ "${consumers}" -eq 0 ]; then + echo "${host} not connected to MQ" + return 2 + fi + fi + done +} +check_conn +ret=$? +if [ $ret -eq 0 ]; then + echo "${host} connected to ${prefix}-${host}.debian.org in ${vhost}" +fi +exit $ret -- 2.20.1