I need to set a schedule downtime for specific nagios host from the commandline by curl..how do I do that?
here is something I am already using for service/host notification enable/disable from commandline.
curl -d "some input here" url "user:pass"
Like way I need to do the thing for schedule downtime.Now the problem is that downtime option takes more options i.e starttime,endtime,comment etc.
So how do I get it done by curl from the commandline?
curl -d " some key value pair(hostname,servicename" url "username:passowrd"
which will do the service/host notification on and off from the commandline. So I want use curl in this fashion to provide downtime for specific nagios server.
Above script is not working for it because downtime option of nagios taked more parameter and I tried to infuse those in the script..but it didn't work out that way.We need provide starttime,endtime and comment value too.
Plus I have tried curl's option called --form and --form-string with that script..not able to get through.
The besic idea is instead of going to the Nagios web interface, we want to done this thing from the command line(we have succeded for service/host service and notification).
Hope I am absolutely clear now.
TIA
Bhaskar
I enhanced Anders answer to provide a complete script and to not require the use of a newer curl that supports --data-urlencode. This also automatically calculates the end time to send and checks that the request was successfully submitted to Nagios. Also, this schedules downtime for the host and all the services on the host.
#!/bin/bash
function die {
echo $1;
exit 1;
}
echo Scheduling downtime on nagios
HOST=monitoredhost
NAGURL=https://nagios.example.com/cgi-bin/nagios3/cmd.cgi
USER=nagiosuser
PASS=nagiospassword
MINUTES=10
export MINUTES
# The following is urlencoded already
STARTDATE=`date "+%Y-%m-%d+%H%%3A%M%%3A%S"`
# This gives us the date/time X minutes from now
ENDDATE=`date "+%Y-%m-%d+%H%%3A%M%%3A%S" -d "$MINUTES min"`
curl --silent --show-error \
--data cmd_typ=86 \
--data cmd_mod=2 \
--data host=$HOST \
--data "com_data=Updating+application" \
--data trigger=0 \
--data "start_time=$STARTDATE" \
--data "end_time=$ENDDATE" \
--data fixed=1 \
--data hours=2 \
--data minutes=0 \
--data btnSubmit=Commit \
--insecure \
$NAGURL -u "$USER:$PASS" | grep -q "Your command request was successfully submitted to Nagios for processing." || die "Failed to contact nagios";
echo Scheduled downtime on nagios
You can send multiple form field values with curl
simply by adding more --data(-d)
arguments. This should schedule service downtime on a Nagios system:
curl \
--data cmd_typ=56 \
--data cmd_mod=2 \
--data host=$HOSTNAME \
--data-urlencode "service=${SERVICENAME}" \
--data-urlencode "com_data=${COMMENT}" \
--data trigger=0 \
--data-urlencode "start_time=2011-07-31 00:00:00" \
--data-urlencode "end_time=2011-07-31 01:00:00" \
--data fixed=1 \
--data hours=2 \
--data minutes=0 \
--data btnSubmit=Commit \
$NAGIOS-URL "username:password"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With