温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

批量设置nagios的计划停机

发布时间:2020-03-19 12:29:23 阅读:899 作者:CMD_help_88 栏目:移动开发
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>
当我们要设置nagios监控下的所有服务和主机的计划停机时间时,如果一个个的手动点击web界面的“Schedule downtime for this host”和“Schedule downtime for all services on this host”会相当痛苦,那么有什么办法可以一次搞定呢?我们可以把请求发给nagios.cmd,nagios读取nagios.cmd文件,自动完成计划停机的设置#!/bin/bashEchoCmd="/bin/echo"CommandFile="/usr/local/nagios/var/rw/nagios.cmd"# get the current date/time in seconds since UNIX epochTodayTime=`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:00EndTime=`date -d "$Tomorrow 08:00:00" +%s`Comment_Author=nagiosadminComment_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界面执行的命令详细过程

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×