X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;ds=sidebyside;f=dsa-nagios-checks%2Fchecks%2Fdsa-check-mq-connection;h=2ed45ca4ac7a7c621c60e5a002cbecd92f044ab4;hb=b3923761df2779305961f11dc4e953dc31624f00;hp=a2457627751b1c84d3db82c63b04c951f8a99f2e;hpb=bf2d7840143c5f885d32af37af662e4f58553ced;p=mirror%2Fdsa-nagios.git diff --git a/dsa-nagios-checks/checks/dsa-check-mq-connection b/dsa-nagios-checks/checks/dsa-check-mq-connection index a245762..2ed45ca 100755 --- a/dsa-nagios-checks/checks/dsa-check-mq-connection +++ b/dsa-nagios-checks/checks/dsa-check-mq-connection @@ -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