D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
lib64
/
nagios
/
plugins
/
Filename :
check_icinga_hosts.sh
back
Copy
#!/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