Commit ca64d42b authored by mape2k's avatar mape2k
Browse files

check_cgiirc - monitor active users



git-svn-id: https://subversion.fem.tu-ilmenau.de/repository/nagios@20 0c029375-f9a5-47ba-aa0c-8883c34e326a
parent 40f33f1f
#!/bin/bash
#
# check_cgiirc
#
# Check currently connected CGI:IRC-Users for Nagios.
#
# Copyright (c) 2012 Marcel Pennewiss (opensource@pennewiss.de)
# Forschungsgemeinschaft elektronische Medien e.V. (FeM e.V.)
#
# Current Version: 0.1
# Last Modified: 2012-09-07
#
# USAGE:
# Start check_cgiirc with the "-h" option to show usage/help.
#
# REQUIREMENTS:
# bash-3.2 (regex operator)
#
# INSTALLATION:
# Copy the shell script to a suitable location
#
# CHANGELOG:
# v0.1 - Initial Release
#
# LICENSE: GPL-2
#
# 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 2 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.
#
##########################################################################
# default values
WARNING=10
CRITICAL=20
CGIIRC_TEMPDIR=/tmp
CGIIRC_PREFIX=cgiirc-
NAGIOS_OK=0
NAGIOS_WARNING=1
NAGIOS_CRITICAL=2
NAGIOS_UNKNOWN=3
# show usage information
print_usage() {
SCRIPT_NAME=$(basename ${0})
echo "CHECK_CGIIRC (v0.1)"
echo "Check currently connected CGI:IRC-Users for Nagios."
echo ""
echo "Usage ${SCRIPT_NAME} -w <warn> -c <crit>"
echo ""
echo " -w <warn> Warning threshold"
echo " -c <crit> Critical threshold"
echo " -h Show this help"
echo ""
}
# print performance data
echoperfdata () {
echo " | 'users'=${1};${WARNING};${CRITICAL}"
}
# print output
echooutput() {
if [ ${1} -lt ${WARNING} ]; then
# Usercounter below warning treshold
echo -n "USERS OK - ${1} CGI:IRC-Users"
echoperfdata ${1}
exit ${NAGIOS_OK}
elif [ ${1} -lt ${CRITICAL} ]; then
# Usercounter below critical treshold
echo -n "USERS WARNING - ${1} CGI:IRC-Users"
echoperfdata ${1}
exit ${NAGIOS_WARNING}
else
# Usercounter above/equal critical treshold
echo -n "USERS CRITICAL - ${1} CGI:IRC-Users"
echoperfdata ${1}
exit ${NAGIOS_CRITICAL}
fi
}
# get number of users
getusers() {
local USERCOUNT=0
for DIRECTORY in $(ls -d ${CGIIRC_TEMPDIR}/${CGIIRC_PREFIX}* 2>/dev/null); do
if [ -f ${DIRECTORY}/ip ] && [ -f ${DIRECTORY}/server ] && [ -S ${DIRECTORY}/sock ]; then
USERCOUNT=$(( $USERCOUNT + 1 ))
fi
done
echooutput ${USERCOUNT}
}
while getopts "w:c:h" Option; do
case ${Option} in
w ) # check valid warning threshold
if ! [[ ${OPTARG} =~ ^[0-9]*$ ]]; then
echo "WARNING THRESHOLD UNKNOWN - Threshold have to be a number"
exit ${NAGIOS_UNKNOWN}
fi
WARNING=${OPTARG} ;;
c ) # check valid critical threshold
if ! [[ ${OPTARG} =~ ^[0-9]*$ ]]; then
echo "CRITICAL THRESHOLD UNKNOWN - Threshold have to be a number"
exit ${NAGIOS_UNKNOWN}
fi
CRITICAL=${OPTARG} ;;
h ) print_usage && exit 0 ;;
* ) echo "UNKNOWN - Unknown parameter"
exit ${NAGIOS_UNKNOWN} ;;
esac
done
shift $(($OPTIND - 1))
getusers
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment