How to set downtime for any particular nagios node for a specific time from the command line through curl?

I need to set the schedule downtime for a specific nagios node from the command line using curl .. how to do this?

here is something that i'm already using to enable / disable service / host notification from the command line.

curl -d "some input here" url "user:pass" 

Like I need to do what is needed for a simple schedule. Now the problem is that the downtime option has more options: start time, end time, comment, etc.

So how do I do this by curling from the command line?

curl -d " some key value pair(hostname,servicename" url "username:passowrd"

which will enable and disable the service / host notification from the command line. Therefore, I want to use curl in such a way as to provide downtime for a particular nagios server.

The above script does not work for it, because the nagios downtime revealed more parameters, and I tried to fill them in the script .. but it didn’t work. We need to provide start time, end time and comment value.

Plus I tried the curl parameter called --form and --form-string, with this script .. could not get through.

The crazy idea is that instead of going to the Nagios web interface, we want to do this from the command line (we have successfully completed the service / host service and notification).

I hope now I am absolutely clear.

TIA

Baskar

+5
source share
4 answers

Anders, script , --data-urlencode. , Nagios. , .

#!/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
+6

curl --data(-d). Nagios:

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"
+2

Sarels.

  • Nagios 3.5.1 ( cmd_typ, childoptions, ).
  • HOST USER arg
  • using $ USER (current user) by default
  • password prompt added (without hard-coded password)
  • post author added nagios

My version:

#!/bin/bash

# Bash script to schedule downtime for Host
# source: http://stackoverflow.com/a/9198181
# Author: Sarel Botha http://stackoverflow.com/users/35264/

function die {
  echo $1;
  exit 1;
}

if [ $# -lt 1 ]; then
  echo "$0 <host> [<user>]"
  exit 0;
elif [ $# -ge 2 ]; then
  USER=$2
fi

HOST=$1
NAGURL=https://nagios.example.com/nagios3/cgi-bin/cmd.cgi
MINUTES=30

echo Scheduling downtime on nagios for $HOST

export MINUTES

# read password
read -s  -p "Password for $USER:" PASS
echo ""  # newline after prompt

# The following is urlencoded already
STARTDATE=`date "+%d-%m-%Y+%H%%3A%M%%3A%S"`
# This gives us the date/time X minutes from now
ENDDATE=`date "+%d-%m-%Y+%H%%3A%M%%3A%S" -d "$MINUTES min"`
curl --silent --show-error \
    --data cmd_typ=55 \
    --data cmd_mod=2 \
    --data host=$HOST \
    --data "com_author=$USER" \
    --data "com_data=reboot+due+to+security+updates" \
    --data trigger=0 \
    --data "start_time=$STARTDATE" \
    --data "end_time=$ENDDATE" \
    --data fixed=1 \
    --data hours=2 \
    --data minutes=0 \
    --data childoptions=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
+1
source

To do this, in order to work on my Nagios, I had to add an extra line under "data host = $ HOST"

- data "com_author = Automatic + Downtime" \

Without this, my Nagios would not agree to a downtime.

0
source

All Articles