# Nagios - downtime on host/service from command line with curl

DevFeed: [Nagios - downtime on host/service from command line with curl](<https://devfeed.tech/articles/nagios-downtime-on-host-service-from-command-line-with-curl-27636.md>)

Original publisher: [Read original article](<https://gagor.pro/2016/01/nagios-downtime-on-hostservice-from-command-line-with-curl/>)

Author: Tom

Published: 2016-01-11T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tomasz Gągor](<https://devfeed.tech/sources/tomasz-gagor.md>)

Topics: [Deployment](<https://devfeed.tech/topics/deployment.md>), [Bash](<https://devfeed.tech/topics/bash.md>), [cURL](<https://devfeed.tech/topics/curl.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Script](<https://devfeed.tech/topics/script.md>), [Code](<https://devfeed.tech/topics/code.md>), [DateTime](<https://devfeed.tech/topics/datetime.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [code](<https://devfeed.tech/tags/code.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [curl](<https://devfeed.tech/tags/curl.md>), [deployment](<https://devfeed.tech/tags/deployment.md>), [downtime](<https://devfeed.tech/tags/downtime.md>), [http](<https://devfeed.tech/tags/http.md>), [linux](<https://devfeed.tech/tags/linux.md>), [monitoring](<https://devfeed.tech/tags/monitoring.md>), [script](<https://devfeed.tech/tags/script.md>), [timezone](<https://devfeed.tech/tags/timezone.md>)

## AI overview

This tutorial presents a Bash script that uses curl to schedule downtime for a Nagios host or service during deployments or other heavy tasks. It explains parameters for targeting a service or an entire host, authentication, and adapting date formats for Nagios and timezone configurations.

## Source excerpt

Sometimes deployment process or other heavy task may cause some Nagios checks to rise below normal levels and bother admin1. If this is expected and you want to add downtime on host/service during this task you may use this script: #!/bin/bash function die { echo $1; exit 1; } if [[ $# -eq 0 ]] ; then die "Give hostname and time in minutes as parameter!" fi if [[ $# -eq 1 ]] ; then MINUTES=15 else MINUTES=$2 fi HOST=$1 NAGURL=http://nagios.example.com/nagios/cgi-bin/cmd.cgi USER=nagiosuser PASS=nagiospassword SERVICENAME=someservice COMMENT="Deploying new code" export MINUTES echo "Scheduling downtime on $HOST for $MINUTES minutes..." # The following is urlencoded already STARTDATE=`date "+%d-%m-%Y %H:%M:%S"` # This gives us the date/time X minutes from now ENDDATE=`date "+%d-%m-%Y %H:%M:%S" -d "$MINUTES min"` curl --silent --show-error \ --data cmd_typ=56 \ --data cmd_mod=2 \ --data host=$HOST \ --data-urlencode "service=$SERVICENAME" \ --data-urlencode "com_data=$COMMENT" \ --data trigger=0 \ --data-urlencode "start_time=$STARTDATE" \ --data-urlencode "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 con tact nagios"; echo Scheduled downtime on nagios from $STARTDATE to $ENDDATE Threat this script as template with some tips: