#!/bin/bash
#
# Objective: Checks all IBM WebSphere MQSeries queue depth in a host
# Author: Federico Ariel Castagnini federico.castagnini@gmail.com
# Note: You can run this with root or with any user in the mqm group
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# ------------------------------------------
# ######## Script Modifications ##########
# ------------------------------------------
# Who When What
# --- ---- ----
# facastagnini 20071120 Version inicial.
#
DSPMQ="/usr/bin/dspmq"
RUNMQSC="/usr/bin/runmqsc"
# NAGIOS EXIT STATES
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
USAGE="Ejecutar `basename $0` ."
NOTE="Este script obtiene la profundidad de las colas."
# Print usage
if [[ $# -ne 2 ]]; then
echo -e "Uso: $USAGE\n\n"
echo -e "Nota: $NOTE\n\n"
exit $STATE_UNKNOWN
else
WARN=$1
CRIT=$2
fi
# si el binario es ejecutable obtenemos la lista de QM
if [[ -x $DSPMQ ]]; then
QMANAGERS=`${DSPMQ} | awk '{print $1}' | sed -e 's/QMNAME(//' -e 's/)//'`
else
echo "ERROR: No se puede ejecutar $DSPMQ"
exit $STATE_UNKNOWN
fi
#si el comando existe y es ejecutable
if [[ -x $RUNMQSC ]]; then
for QMANAGER in $QMANAGERS
do
#echo $QMANAGER:
QUEUES=`echo "dis q(Q.*)" | ${RUNMQSC} ${QMANAGER} | awk '/QUEUE/ {print $1}' | awk -F"(" '{print $2}' | sed -e 's/)/ /'`
for QUEUE in $QUEUES
do
MSGAGE=`echo "dis qstatus(${QUEUE}) curdepth" | ${RUNMQSC} ${QMANAGER} | grep CURDEPTH | awk -F "(" '{print $2}' | awk -F ")" '{print $1}'`
#echo $QUEUE: $MSGAGE
# Preparamos la informacion de performance
# 'label'=value[UOM],warn;crit;min;max
PERFDATA="'${QMANAGER}_${QUEUE}'=${MSGAGE};${WARN};${CRIT};0;${CRIT}"
if [[ "$MSGAGE" -ge "$CRIT" ]]; then
MSGTMP="${MSGTMP}${QMANAGER}:${QUEUE} tiene ${CRIT} o mas mensajes encolados,"
CRITICAL="1"
elif [[ "$MSGAGE" -ge "$WARN" ]]; then
MSGTMP="${MSGTMP}${QMANAGER}:${QUEUE} tiene ${WARN} o mas mensajes encolados,"
WARNING="1"
fi
PERFDATATMP="${PERFDATA} ${PERFDATATMP}"
done
done
else
echo "ERROR: No se puede ejecutar $RUNMQSC"
exit $STATE_UNKNOWN
fi
# ultima etapa, imprimimos la linea del nagios en pantalla, mensaje de estado y perfdata
if [[ "$CRITICAL" == "1" ]]; then
echo "CRITICAL - $MSGTMP|$PERFDATATMP"
exit $STATE_CRITICAL
elif [[ "$WARNING" == "1" ]]; then
echo "WARNING - $MSGTMP|$PERFDATATMP"
exit $STATE_WARNING
else
echo "OK|$PERFDATATMP"
exit $STATE_OK
fi