amusarra
8/28/2014 - 5:26 PM

Check Informix (nagios-plugins 1.4)

Check Informix (nagios-plugins 1.4)

#!/bin/bash

##
# Set Required evironment variable for IDS Informix 10
# Add. 12/06/2008 Antonio Musarra <antonio.musarra@romcad.it>
##
INFORMIXDIR=/opt/IBM/informix
PATH=$PATH:$INFORMIXDIR/bin
ONCONFIG=onconfig.cormonet
INFORMIXSERVER=cormonet
INFORMIXSQLHOSTS=$INFORMIXDIR/etc/sqlhosts
LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql
CLIENT_LOCALE=en_US.819
DBDATE=DMY4
PDQPRIORITY=25
export INFORMIXDIR INFORMIXSQLHOSTS PATH ONCONFIG INFORMIXSERVER LD_LIBRARY_PATH DBDATE CLIENT_LOCALE PDQPRIORITY

# Definizione Stati di uscita
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
VERSION="v1.0"

# Definizione dei comandi
IFX_ONSTAT=`onstat - | tr -d '\n'`
IFX_STATUS=`onstat - | cut -d ' ' -f 12 | tr -d '\n'`
IFX_MEMORY=`onstat - | cut -d ' ' -f 19 | tr -d '\n'`

##
# Funzione print_revision()
##
print_revision() {
        echo "Check Informix (nagios-plugins 1.4) $VERSION"
        echo "------------------------------------------------------"
        echo ""
        echo "The nagios plugins come with ABSOLUTELY NO WARRANTY."
        echo "You may redistribute copies of the plugins under the "
        echo "terms of the GNU General Public License."
        echo "For more information about these matters,see the file "
        echo "named COPYING."
}

##
# Funzione print_usage()
##
print_usage() {
        echo "Check Informix by Antonio Musarra <antonio.musarra@romcad.it>"
        echo ""
        echo "See the follow examples:"
        echo -e "\t Check status of Informix server [Initialization,Fast Recovery,Archive Backup,Read-Only,Unknown,Abort,On-Line,Single-User,Quiescent]:\n check_informix --component status"
        echo -e "\t Check status SH Memory of Informix Server: check_informix -c 600000 -w 500000 --component shmemory"
        echo ""
        echo "Usage: check_informix -c <Critical Threshold> -w <Warning Threshold> --component <Component to check>"
        echo "Usage: check_informix [-h] [--help]"
        echo "Usage: check_informix [-V]"
}

##
# Funzione print_help()
##
print_help() {
        echo "Check Informix by Antonio Musarra <antonio.musarra@romcad.it>"
        echo ""
        echo "See the follow examples:"
        echo -e "\t Check status of Informix server [Initialization,Fast Recovery,Archive Backup,Read-Only,Unknown,Abort,On-Line,Single-User,Quiescent]:\n check_informix --component status"
        echo -e "\t Check status SH Memory of Informix Server: check_informix -c 600000 -w 500000 --component shmemory"
        echo ""
        echo "Usage: check_informix -c <Critical Threshold> -w <Warning Threshold> --component <Component to check>"
        echo "Usage: check_informix [-h] [--help]"
        echo "Usage: check_informix [-V]"
}

##
# CONTROLLO PARAMETRI
##
while test -n "$1"; do
        case "$1" in
                --help)
                        print_help
                        exit $STATE_OK
                        ;;
                -h)
                        print_help
                        exit $STATE_OK
                        ;;
                -V)
                        print_revision
                        exit $STATE_OK
                        ;;
                -c)
                        CRITICAL_LEVEL=$2
                        shift
                        ;;
                -w)
                        WARNING_LEVEL=$2
                        shift
                        ;;
                --component)
                        COMPONENT=$2
                        shift
                        ;;
                *)
                        echo "Unknown argument: $1"
                        print_usage
                        exit $STATE_UNKNOWN
                        ;;
                esac
shift
done

##
# Check Params
##
if [ -z $COMPONENT ]; then
        echo "STATUS CRITICAL: Component to check not specified"
        exit $STATE_CRITICAL
fi

if [[ "$COMPONENT" = "shmemory" ]] && [ -z $CRITICAL_LEVEL ]; then
        echo "STATUS CRITICAL: Critical Threshold not specified"
        exit $STATE_CRITICAL
fi

if [[ "$COMPONENT" = "shmemory" ]] && [ -z $WARNING_LEVEL ]; then
        echo "STATUS CRITICAL: Warning Threshold not specified"
        exit $STATE_CRITICAL
fi

##
# Check Status of Informix Server
##
if [[ "$COMPONENT" = "status" ]]; then
        if [[ "$IFX_STATUS" = "On-Line" ]]; then
                        echo "STATUS OK: $IFX_ONSTAT"
                        exit $STATE_OK
        fi
        if [[ "$IFX_STATUS" = "Quiescent" ]] || [[ "$IFX_STATUS" = "Fast Recovery" ]] || [[ "$IFX_STATUS" = "Read-Only" ]] || [[ "$IFX_STATUS" = "Single-User" ]];  then
                        echo "STATUS WARNING: $IFX_ONSTAT"
                        exit $STATE_WARNING
        fi
        if [[ "$IFX_STATUS" = "Initialization" ]] || [[ "$IFX_STATUS" = "Abort" ]] || [[ "$IFX_STATUS" = "Unknown" ]] || [[ "$IFX_STATUS" = "" ]]; then
                echo "STATUS CRITICAL: $IFX_ONSTAT"
                exit $STATE_CRITICAL
        fi
fi


##
# Check Shared Memory of Informix Server
##
if [[ "$COMPONENT" = "shmemory" ]]; then
        if [[ ${IFX_MEMORY} < $CRITICAL_LEVEL ]]; then
                if [[ ${IFX_MEMORY} < $WARNING_LEVEL ]]; then
                        echo "STATUS OK: $IFX_MEMORY"
                        exit $STATE_OK
                else
                        echo "STATUS WARNING: $IFX_MEMORY"
                        exit $STATE_WARNING
                fi
        else
                echo "STATUS CRITICAL: $IFX_MEMORY"
                exit $STATE_CRITICAL
        fi
fi

if [[ "$COMPONENT" != "status" ]] || [[ "$COMPONENT" != "shmemory" ]]; then
        echo "STATUS CRITICAL: Value for --component are: status or shmemory"
        exit $STATE_CRITICAL
fi