#!/bin/bash
#
# Objective: Check all the IBM WebSphere MQSeries queue managers status 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 20071112 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="check queue manager status."
# 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
COUNT=`echo "DISPLAY CHSTATUS(SYSTEM.DEF.SVRCONN)" | ${RUNMQSC} ${QMANAGER} | grep "SYSTEM.DEF.SVRCONN" | grep -v DISPLAY | wc -l | sed -e 's/ //g'`
# 'label'=value[UOM],warn;crit;min;max
PERFDATA="'${QMANAGER}'=${COUNT};${WARN};${CRIT};0;${CRIT}"
if [[ "$COUNT" -ge "$CRIT" ]]; then
MSGTMP="${QMANAGER}:${QUEUE} tiene ${COUNT} o mas canales."
CRITICAL="1"
elif [[ "$COUNT" -ge "$WARN" ]]; then
MSGTMP="${QMANAGER}:${QUEUE} tiene ${COUNT} o mas canales."
WARNING="1"
fi
#concatenamos la informacion de performance con las anteriores
PERFDATATMP="${PERFDATA} ${PERFDATATMP}"
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