#!/bin/bash # evt_apache2 # # Copyright (C) 2000 Christian Veith # # 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 (or with Nagios); if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA #################################### # Recheckparameter servicename="Service - HTTP" # SSH Connection & Checkparameter sshservicecheckname="Service - SSH" sshport=22 remote_command=/usr/bin/restart_apache.sh # Conditions checkstate=CRITICAL checktype=SOFT minretry=1 # Parameter from Nagios hostname=$1 state=$2 type=$3 retry=$(echo $4 | sed 's/\$//') retcode=0 debug=0 if [ $debug -eq 1 ]; then echo "--------------------------" echo $servicename >> /tmp/$1 echo $sshservicecheckname >> /tmp/$1 echo $sshport >> /tmp/$1 echo $hostname >> /tmp/$1 echo $state >> /tmp/$1 echo $type >> /tmp/$1 echo $retry >> /tmp/$1 fi if [[ "$state" == "$checkstate" && "$type" == "$checktype" ]] then if [[ "$retry" -gt "$minretry" ]] then #Check for running SSH Client on other side /usr/local/nagios/libexec/check_ssh -p $sshport $hostname if [ $? -eq 0 ] then /usr/bin/ssh $hostname "$remote_command" retcode=$? echo "[`date +%s`] ADD_SVC_COMMENT;$hostname;$servicename;1;nagios;Tried Restart of $servicename after $retry check(s)." >> /usr/local/nagios/var/rw/nagios.cmd echo "[`date +%s`] SEND_CUSTOM_SVC_NOTIFICATION;$hostname;$servicename;1;nagios;Tried restart of $servicename after $retry check(s).\n" >> /usr/local/nagios/var/rw/nagios.cmd else # Force SSH check echo "[`date +%s`] SCHEDULE_FORCED_SVC_CHECK;$hostname;$sshservicecheckname;`date +%s`" >> /usr/local/nagios/var/rw/nagios.cmd # Send Comment to SSH Service for the BOFH echo "[`date +%s`] ADD_SVC_COMMENT;$hostname;$servicename;1;nagios;Tried Restart of $servicename, but SSH was not working" >> /usr/local/nagios/var/rw/nagios.cmd retcode=1 fi if [ $retcode -eq 0 ]; then echo "[`date +%s`] SCHEDULE_FORCED_SVC_CHECK;$hostname;$servicename;`date +%s`" >> /usr/local/nagios/var/rw/nagios.cmd echo "[`date +%s`] ADD_SVC_COMMENT;$hostname;$servicename;1;nagios;Restart of $servicename successful." >> /usr/local/nagios/var/rw/nagios.cmd else echo "[`date +%s`] PROCESS_SERVICE_CHECK_RESULT;$hostname;$servicename;2;Eventhandler not successful - Error $retcode" >> /usr/local/nagios/var/rw/nagios.cmd echo "[`date +%s`] ADD_SVC_COMMENT;$hostname;$servicename;1;nagios;Restart of $servicename not successful." >> /usr/local/nagios/var/rw/nagios.cmd exit $retcode fi else echo "less or equal $minretry" exit 0 fi else echo "State not $checkstate or Type not $checktype" exit 0 fi