From 188421e870af0fc446f8541a54dc8844cd16f981 Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Tue, 14 Feb 2012 23:19:01 +0100 Subject: [PATCH] Rewrote most of the code, added help text, arguments, switches etc --- check_quake.sh | 178 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 169 insertions(+), 9 deletions(-) diff --git a/check_quake.sh b/check_quake.sh index 5155474..d6dbd0f 100755 --- a/check_quake.sh +++ b/check_quake.sh @@ -1,12 +1,172 @@ #!/bin/bash -HOST=$1 -PORT=$2 -STATE=`quakestat -u -default q2s ${HOST}:${PORT} | grep "${HOST}"` -if [[ $? == 0 ]]; then -printf "${PORT} - OK\n" -exit 0 -elif [[ $? == 1 ]]; then -printf "${PORT} - DOWN\n" -exit 2 + +################################################################################ +# # +# Copyright (C) 2012 Jack-Benny Persson # +# # +# 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. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +################################################################################ + +############################################################################### +# # +# Nagios plugin to monitor a Quake II server. # +# The plugin exit with a CRICITAL error code if the server is down. # +# This behavior can be changed with the --warning argument. # +# Written in Bash (and uses standard tools such as grep and awk). # +# # +############################################################################### + +VERSION="0.1" +AUTHOR="(c) 2012 Jack-Benny Persson (jack-benny@cyberinfo.se)" + +# Exit codes +STATE_OK=0 +STATE_WARNING=1 +STATE_CRITICAL=2 +STATE_UNKNOWN=3 + +# Some default values +PORT=27919 + +shopt -s extglob + +#### Functions #### + +# Print version information +print_version() +{ + printf "\n\n$0 - $VERSION\n" +} + +#Print help information +print_help() +{ + print_version + printf "$AUTHOR\n" + printf "Monitor a Quake II server\n" +/bin/cat <