Hi,
I am able to place the host/services in scheduled downtime using below command, this will place all related services on a host into scheduled downtime.
curl --silent --show-error --data cmd_typ=86 --data cmd_mod=2 --data host="XXXXX" --data com_data="Placing server in scheduled downtime from command line" --data trigger=0 --data start_time="06-04-2019 17:20:00" --data end_time="06-04-2019 17:30:00" --data fixed=1 --data hours=2 --data minutes=0 --data btnSubmit=Commit --insecure https://localhost/nagios/cgi-bin/cmd.cgi -u username:passwd
Can you advice if it is possible to place only specific services (not all the services) on a host into scheduled downtime ?
Maintenance mode on specific services
Re: Maintenance mode on specific services
You could use the REST API in Nagios XI to schedule downtime. Unfortunately, you would need to use separate commands for each service as it is not possible at the moment to pass all services as an array. For example, you may use a bash script as the one below:
make it executable:
and run it:
This example shows scheduling downtime on three services on localhost - PING, HTTP, and Total Processes. You can review the REST API documentation under the Help menu from the web UI in Nagios XI.
Hope this helps.
Code: Select all
#!/bin/bash
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/system/scheduleddowntime?apikey=xxx&pretty=1" -d "comment=Test downtime creation&start=1559681206&end=1559688406&services[localhost]=PING"
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/system/scheduleddowntime?apikey=xxx&pretty=1" -d "comment=Test downtime creation&start=1559681206&end=1559688406&services[localhost]=HTTP"
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/system/scheduleddowntime?apikey=xxx&pretty=1" -d "comment=Test downtime creation&start=1559681206&end=1559688406&services[localhost]=Total Processes"Code: Select all
chmod +x schedule_downtime.shCode: Select all
[root@main-nagios-xi tmp]# ./schedule_downtime.sh
{
"success": "Schedule downtime command(s) sent successfully.",
"scheduled": {
"services": {
"localhost": [
"PING"
]
}
}
}
{
"success": "Schedule downtime command(s) sent successfully.",
"scheduled": {
"services": {
"localhost": [
"HTTP"
]
}
}
}
{
"success": "Schedule downtime command(s) sent successfully.",
"scheduled": {
"services": {
"localhost": [
"Total Processes"
]
}
}
}Hope this helps.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Maintenance mode on specific services
We didn't see scheduled downtime under Help tab and getting below error
[root@XXXX ~]# curl -XPOST "http://XXXX/nagiosxi/api/v1/system/sche ... X&pretty=1" -d "comment=Test downtime creation&start=1560275926&end=1560276100&services[localhost]=PING"
{
"error": "Unknown API endpoint."
}
[root@XXXX ~]#
Kindly advice ?
[root@XXXX ~]# curl -XPOST "http://XXXX/nagiosxi/api/v1/system/sche ... X&pretty=1" -d "comment=Test downtime creation&start=1560275926&end=1560276100&services[localhost]=PING"
{
"error": "Unknown API endpoint."
}
[root@XXXX ~]#
Kindly advice ?
Last edited by bsivavani on Wed Jun 12, 2019 5:29 am, edited 2 times in total.
Re: Maintenance mode on specific services
I would recommend that you upgrade to the latest version of Nagios XI. There are numerous bug fixes, and new features added to the newer versions, including the REST API.
FYI, Nagios XI 5.6.3 just went out this morning. Here's our documentation on upgrading XI:
https://assets.nagios.com/downloads/nag ... ctions.pdf
FYI, Nagios XI 5.6.3 just went out this morning. Here's our documentation on upgrading XI:
https://assets.nagios.com/downloads/nag ... ctions.pdf
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Maintenance mode on specific services
We have a plan of setting up new environment in new domain with latest version in next 4 months.
As a interim solution in the current environment, we have to implement the requirement to place specific service into blackout.
Kindly advice if we can use functionality of below API ?
[root@XXXX ~]# curl -XPOST "http://XXXX/nagiosxi/api/v1/system/sche ... X&pretty=1" -d "comment=Test downtime creation&start=1560275926&end=1560276100&services[localhost]=PING"
{
"error": "Unknown API endpoint."
}
[root@XXXX ~]#
As a interim solution in the current environment, we have to implement the requirement to place specific service into blackout.
Kindly advice if we can use functionality of below API ?
[root@XXXX ~]# curl -XPOST "http://XXXX/nagiosxi/api/v1/system/sche ... X&pretty=1" -d "comment=Test downtime creation&start=1560275926&end=1560276100&services[localhost]=PING"
{
"error": "Unknown API endpoint."
}
[root@XXXX ~]#
Re: Maintenance mode on specific services
Unfortunately, scheduling downtime via the REST API won't be possible in Nagios XI 5.2.9 as it's not been added yet. You could however use external nagios commands to achieve your goal.
https://assets.nagios.com/downloads/nag ... and_id=119
For example, I added the following script to the /tmp directory on a Nagios XI 5.2.9 server:
I made it executable:
and ran it:
I went to the GUI to verify that a downtime has been scheduled for PING service on localhost.
https://assets.nagios.com/downloads/nag ... and_id=119
For example, I added the following script to the /tmp directory on a Nagios XI 5.2.9 server:
Code: Select all
#!/bin/sh
# This is a sample shell script showing how you can submit the SCHEDULE_SVC_DOWNTIME command
# to Nagios. Adjust variables to fit your environment as necessary.
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
/usr/bin/printf "[%lu] SCHEDULE_SVC_DOWNTIME;localhost;PING;1560282312;1560289512;1;0;7200;nagiosadmin;Testing The SCHEDULE_SVC_DOWNTIME External Command\n" $now > $commandfileCode: Select all
[root@TEST_XI_CentOS_6 tmp]# chmod +x test.shCode: Select all
[root@TEST_XI_CentOS_6 tmp]# ./test.sh
[root@TEST_XI_CentOS_6 tmp]#You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Maintenance mode on specific services
Hi,
We would need to run the below command from remote server to place specific service in maintenance mode.
/usr/bin/printf "[%lu] SCHEDULE_SVC_DOWNTIME;localhost;PING;1560282312;1560289512;1;0;7200;nagiosadmin;Testing The SCHEDULE_SVC_DOWNTIME External Command\n" $now > $commandfile
Kindly advice if we can achieve this ?
We would need to run the below command from remote server to place specific service in maintenance mode.
/usr/bin/printf "[%lu] SCHEDULE_SVC_DOWNTIME;localhost;PING;1560282312;1560289512;1;0;7200;nagiosadmin;Testing The SCHEDULE_SVC_DOWNTIME External Command\n" $now > $commandfile
Kindly advice if we can achieve this ?
Re: Maintenance mode on specific services
If you wanted to run the command from a remote server, you could use "sshpass" in order to log in as nagios user, and run the command.
Example:
Example:
Code: Select all
sshpass -p mypassword ssh [email protected] '/usr/bin/printf "[%lu] SCHEDULE_SVC_DOWNTIME;localhost;PING;1561406400;1561413600;1;0;7200;nagiosadmin;Testing The SCHEDULE_SVC_DOWNTIME External Command\n" $now > /usr/local/nagios/var/rw/nagios.cmd'You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!