重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

批量设置nagios的计划停机

当我们要设置nagios监控下的所有服务和主机的计划停机时间时,如果一个个的手动点击web界面的“Schedule downtime for this host”和“Schedule downtime for all services on this host”会相当痛苦,那么有什么办法可以一次搞定呢?我们可以把请求发给nagios.cmd,nagios读取nagios.cmd文件,自动完成计划停机的设置
#!/bin/bash
EchoCmd="/bin/echo"
CommandFile="/usr/local/nagios/var/rw/nagios.cmd"

为麻阳等地区用户提供了全套网页设计制作服务,及麻阳网站建设行业解决方案。主营业务为成都做网站、网站建设、麻阳网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

# get the current date/time in seconds since UNIX epoch
TodayTime=`date +%Y-%m-%d`
Tomorrow=`date +%Y-%m-%d --date='1 day'`
NowTime=`date +%s`
BeginTime=`date -d "$TodayTime 20:30:00" +%s`    //计划停机时间今天20:30到第二天的08:00
EndTime=`date -d "$Tomorrow 08:00:00" +%s`
Comment_Author=nagiosadmin
Comment_Data=xitongweihu_`date +%Y%m%d`
hostgroup=/data/backup/group.ini  //该文件保存计划停机的主机组名称
for X in $(cat $hostgroup)
    do
# create the command line to add to the command file //该项设置主机组下的所有主机计划停机
 CmdHostGroup="[$NowTime] SCHEDULE_HOSTGROUP_HOST_DOWNTIME;$X;$BeginTime;$EndTime;1;0;3600;$Comment_Author;$Comment_Data"
# append the command to the end of the command file
 `$EchoCmd $CmdHostGroup >> $CommandFile`

# create the command line to add to the command file    //该项设置主机组下的所有服务计划停机
 CmdServiceGroup="[$NowTime] SCHEDULE_HOSTGROUP_SVC_DOWNTIME;$X;$BeginTime;$EndTime;1;0;3600;$Comment_Author;$Comment_Data"
# append the command to the end of the command file
 `$EchoCmd $CmdServiceGroup >> $CommandFile`
done


备注:可以通过打开nagios.cfg里的日志级别,查看通过web界面执行的命令详细过程

 


当前文章:批量设置nagios的计划停机
标题路径:http://cqcxhl.com/article/pgoppd.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP