Anthony Montibello wrote:
I always use a daily cron script/s to setup Downtime schedual to handle that issue. the flexable downtime, may be better if the hosts always recover within X min while Fixed is better if you know the host will go down at X and e back up at Y http://nagios.sourceforge.net/docs/3_0/downtime.html
Here is a script that I use that schedules downtime for a host/service
You could run it out of your backup pre-script
Modify it for your needs

#!/bin/bash
#
# This script is used to submit downtime to Nagios
# see the usage function for info on how to use it

. /opt/maj/standard

#================================ CONFIG =====================================
# location of nagios config file
nagios_cfg=/etc/nagios/nagios.cfg
echocmd="/bin/echo"

# get the current date/time in seconds since UNIX epoch
datetime=`date +%s`

author="$0"

#--------------------------------- AUTO CONFIG -------------------------------
# you should not need to change this
# get the name of the nagios command file
nagios_cmd=`awk -F= '/^command_file/ {print $2}' $nagios_cfg`
if [ ! -p "$nagios_cmd" ]; then
echo "Got Nagios CMD file as \"$nagios_cmd\" and it is not a valid command file"
  exit 1
fi

#================================ FUNCTIONS =====================================
#--------------------------------------------------------------------------------
usage ()
{
cat << EOT
Usage: $0 -h HOST -s SERVICENAME -c COMMENT -a "STARTTIME" -b "ENDTIME"

where
HOST        is the name of the host that this downtime is for
SERVICENAME is the name of the service that this downtime is for
           This is optional. If excluded we schedule downtime for the host
COMMENT     is the comment associated with the downtime
STARTTIME   format is the same as accepted by the date --date=STRING command
eg "now", "+30 minutes", "6 months 15 day", "2007-09-01 16:00:00"
ENDTIME     as for STARTTIME

EOT
exit 1
}
#--------------------------------------------------------------------------------
write_to_cmd_file () {
# create the command line to add to the command file
# sample format:
# SCHEDULE_SVC_DOWNTIME;mail.optusnet.com.au;SMTP;1188879530;1188880130;1;0;7200;Matthew Jurgens;COMMENT

# if $servicename is set it will supply its own ;
cmdline="\[$datetime\] $downtime_cmd;$host;$servicename$starttime_sec;$endtime_sec;1;0;$duration;$author;$comment"

# append the command to the end of the command file
`$echocmd $cmdline >> $nagios_cmd`
}
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
#================================ MAIN =====================================

# ---------- GET Options
[ $# -ge 1 ] || usage

# Check for options
while getopts h:s:c:a:b: OPT
do
  case $OPT in
  h)
     host=$OPTARG
     ;;
  s)
     servicename=$OPTARG
     ;;
  c)
     comment=$OPTARG
     ;;
  a)
     starttime=$OPTARG
     ;;
  b)
     endtime=$OPTARG
     ;;
  *)
     usage
     ;;
  esac
done
shift `expr $OPTIND - 1`

if [ -z "$host" -o -z "$comment" -o -z "$starttime" -o -z "$endtime" ]; then
  usage
fi

if [ -z "$servicename" ]; then
  # we schedule downtime for the host
  downtime_cmd="SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME"
else
  # we schedule downtime for the service
  downtime_cmd="SCHEDULE_SVC_DOWNTIME"
# add a ; to the end of the servicename so that it fits the correct syntax
  servicename="$servicename;"
fi


# convert starttime and endtime to seconds
starttime_sec=`date --date="$starttime" +'%s'`
endtime_sec=`date --date="$endtime" +'%s'`

if [ "$starttime_sec" -a "$endtime_sec" ]; then

  # work out the duration
  let duration=endtime_sec-starttime_sec

  write_to_cmd_file
else
  echo "ERROR:Starttime or Endtime date format not correct"
fi


--
Smartmon System Monitoring <http://www.smartmon.com.au>
www.smartmon.com.au
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
Nagios-users mailing list
Nagios-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting 
any issue. 
::: Messages without supporting info will risk being sent to /dev/null

Reply via email to