HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //lib64/nagios/plugins/check_icinga_hosts.sh
#!/bin/bash

usage() {
    echo " check_icinga_hosts - Icinga check for number of services"
    echo ""
    echo " Usage: check_icinga_hosts -w <warning threshold> -c <critical threshold> [ -h ]"
    echo ""
    echo "       -w  Service count at which a warning is triggered"
    echo "       -c  Service count at which a critical is triggered"
    echo "       -h  Show this page"
    echo ""
}

cmdopts() {
    if ( `test 0 -lt $#` )
    then
        while getopts w:c:h myarg "$@"
        do
            case $myarg in
                h|\?)
                    usage
                    exit;;
                w)
                    WARNING=$OPTARG;;
                c)
                    CRITICAL=$OPTARG;;
                *)
                    usage
                    exit;;
            esac
        done
    else
        usage
        exit
    fi
}

cmdopts $@

# Get the host count from Icinga2
HOST_COUNT=$(icinga2 daemon -C | grep "information/ConfigItem: Instantiated" | grep "Services" | awk '{print $6}')

# Check if we got a valid number
if [[ "$HOST_COUNT" =~ ^[0-9]+$ ]]; then
    if [ "$HOST_COUNT" -ge "$CRITICAL" ]
    then
        echo "CRITICAL: Icinga Services count is at $HOST_COUNT (threshold: $CRITICAL)";
        exit 2;
    elif [ "$HOST_COUNT" -ge "$WARNING" ]
    then
        echo "WARNING: Icinga Services count is at $HOST_COUNT (threshold: $WARNING)";
        exit 1;
    else
        echo "OK: Icinga Services count is at $HOST_COUNT";
        exit 0;
    fi
else
    echo "UNKNOWN: Could not determine services count"
    exit 3
fi