如何设置特定的Nagios主机从命令行到curl的特定时间的停机时间? [英] How to set downtime for any specific nagios host for certain time from commandline through curl?

查看:107
本文介绍了如何设置特定的Nagios主机从命令行到curl的特定时间的停机时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过curl从命令行设置特定Nagios主机的计划停机时间.

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.

那么如何从命令行通过curl来完成它呢?

So how do I get it done by curl from the commandline?

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

,它将通过命令行打开和关闭服务/主机通知.因此,我想以这种方式使用curl来为特定的nagios服务器提供停机时间.

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.

上面的脚本不起作用,因为nagios的宕机选项接受了更多参数,并且我试图在脚本中注入这些参数..但是这种方法没有解决问题.我们还需要提供开始时间,结束时间和注释值.

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.

另外,我已经尝试使用该脚本使用curl的--form和--form-string选项.无法通过.

Plus I have tried curl's option called --form and --form-string with that script..not able to get through.

一个基本的想法不是要转到Nagios Web界面,而是要从命令行完成此操作(我们已经成功地实现了服务/主机服务和通知).

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).

希望我现在很清楚.

TIA

Bhaskar

推荐答案

我增强了Anders答案,以提供完整的脚本,并且不需要使用支持--data-urlencode的较新curl.这还将自动计算发送的结束时间,并检查请求是否已成功提交给Nagios.另外,这可以安排主机和主机上所有服务的停机时间.

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

这篇关于如何设置特定的Nagios主机从命令行到curl的特定时间的停机时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆