Schedule downtime command

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
ariarlet
Posts: 61
Joined: Wed Apr 22, 2015 11:04 am

Schedule downtime command

Post by ariarlet »

Hello

Can i make shedule downtime by command?
this is yes, how i make?


I found this page:
https://exchange.nagios.org/directory/A ... ty/details
but i sure this run

thanks
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Schedule downtime command

Post by Box293 »

We can use curl to do this.

This is for the host object:

Command:

Code: Select all

curl -d "cmd_typ=55&cmd_mod=2&host=centos03&com_data=TestingDowntime&trigger=0&start_time=03-13-2015 11:30:00&end_time=03-13-2015 11:40:00&fixed=1&childoptions=0&btnSubmit=Commit" "http://xitest/nagios/cgi-bin/cmd.cgi" -u "troylea:password"
This is for the host's services:

Command:

Code: Select all

curl -d "cmd_typ=86&cmd_mod=2&host=centos03&com_data=TestingDowntime&trigger=0&start_time=03-13-2015 11:30:00&end_time=03-13-2015 11:40:00&fixed=1&childoptions=0&btnSubmit=Commit" "http://xitest/nagios/cgi-bin/cmd.cgi" -u "troylea:password"

The output you receive for the commands is a http page, but most importantly you are after this message:

Output:

Code: Select all

<P><DIV CLASS='infoMessage'>Your command request was successfully submitted to Nagios for processing.<BR><BR>
Note: It may take a while before the command is actually processed.<BR><BR>

I have some other examples here:
http://sites.box293.com/nagios/guides/t ... e-and-cgis
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
ariarlet
Posts: 61
Joined: Wed Apr 22, 2015 11:04 am

Re: Schedule downtime command

Post by ariarlet »

Thank but i have got problems with permisions and i use this script:

Code: Select all

#!/bin/sh
 
#
# Write a command to the Nagios command file to cause
# it to schedule service downtime.
#
# Author: Sam Tilders sam@jovianprojects.com.au
#
# Based on the example event handler scripts and cmd.c/.cgi
#
# Requires:
#  GNU Date (for date formatting options)
#  Bash > 2.x (for inline variable regex substitution on the comment_data)
 
# Notes:
# 1) In order for Nagios to process any commands that
#    are written to the command file, you must enable
#    the check_external_commands option in the main
#    configuration file.
 
# Caveats:
#  Using "date" to validate the command line date format doesn't always pick
# up all mistakes in the date format. Sometimes "date" seems to invent something
# that might have been what you intented.
#  Makes no attempt to verify the hostname or service desc before passing them to
# the command pipe. Nagios seems to ignore the command if it doesn't match.
# Write a command to the Nagios command file to cause
# it to schedule host downtime
 
# Example:
# A cron entry to schedule downtime for the nntp service every day at 0400 while
# other cron jobs (locate database update) slow the machine down.
# 30 0 * * * schedule_svc_downtime news NNTP "`date --iso-8601` 04:00:00" "`date --iso-8601` 05:00:00" 1 3600 auto "while cron does things"
# There are utilities such as "shellsupport" that will do date manipulation allowing shell scripts
# to wrap around this command to schedule for days in advance instead of same date.
 
usage()
{
        echo "Usage: $0 <hostname> <service desc> <start time> <end time> <fixed> <duration> <user> <comment>"
        echo "   Times must be in the form \"CCYY-MM-DD HH:mm:ss\" and will probably need to be quoted."
        echo "   fixed is either 1 or 0 and indicates that the time period is fixed and duration should be ignored"
        echo "   length of the downtime in seconds, only used if not fixed downtime"
        echo "   user who is requesting the downtime"
        echo "   comment to place on the downtime, probably will need to be quoted."
}
 
if [ $# -lt 5 ]; then
        echo "$0: Too few parameters"
        usage
        exit 1
fi
if [ $# -gt 5 ]; then
        echo "$0: Too many parameters"
        usage
        exit 1
fi
 
hostname=$1
raw_start=$2
raw_end=$3
fixed=1
duration=""
comment_author=$4
# command is comment with ; replaced for space
comment_data=$5
#comment_data=${8/;/ }
trigger_id=0
 
 
echocmd="/bin/echo"
 
CommandFile="/usr/local/nagios/var/rw/nagios.cmd"
 
# get the current date/time in seconds since UNIX epoch
datetime=`date +%s`
 
 
start_time=`date -d "$raw_start" +%s`
if [ $? != 0 ]; then
        echo "Bad format for start time."
        usage
        exit 1
fi
end_time=`date -d "$raw_end" +%s`
if [ $? != 0 ]; then
        echo "Bad format for end time."
        usage
        exit 1
fi
if [ $fixed != 1 -a $fixed != 0 ]; then
        echo "Fixed must be 1 or 0"
        usage
        exit 1
fi
 
# create the command line to add to the command file
cmdline="[$datetime] SCHEDULE_HOST_DOWNTIME;$hostname;$start_time;$end_time;$fixed;$trigger_id;$duration;$comment_author;$comment_data"
 
# append the command to the end of the command file
`$echocmd $cmdline >> $CommandFile`
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Schedule downtime command

Post by tmcdonald »

What problems with permissions are you seeing? Can you post specific errors?
Former Nagios employee
ariarlet
Posts: 61
Joined: Wed Apr 22, 2015 11:04 am

Re: Schedule downtime command

Post by ariarlet »

I make thw shedule downtime with that code, and this run correctly

thanks for you help
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Schedule downtime command

Post by tgriep »

If everything is working, can we close this post?
Be sure to check out our Knowledgebase for helpful articles and solutions!
ariarlet
Posts: 61
Joined: Wed Apr 22, 2015 11:04 am

Re: Schedule downtime command

Post by ariarlet »

yes

thanks
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Schedule downtime command

Post by abrist »

Locking.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked