线上的Nagios Client端的监控脚本因为业务需求又发生改动了,某业务集群差不多就有23台(下面的list只列出了8台),而且其中的一个业务需求脚本前前后后改动了4次,如果手动操作的话会累死人,幸亏有Fabric这个轻量级的自动化运维工具,代码如下:
#!/usr/bin/python2.6 from fabric.api import * from fabric.colors import * from fabric.context_managers import * user = 'ec2-user' hosts = ['bidder1','bidder2','bidder3','bidder4','bidder5','bidder6','bidder7','bidder8'] # hosts = ['bidder1',] @task def put_task(): print yellow("Put Local File to remote") with settings(warn_only=True): put("/home/ec2-user/check_cpu_utili.sh","/home/ec2-user/check_cpu_utili.sh") sudo("cp /home/ec2-user/check_cpu_utili.sh /usr/local/nagios/libexec") sudo("chown nagios:nagios /usr/local/nagios/libexec/check_cpu_utili.sh") sudo("chmod +x /usr/local/nagios/libexec/check_cpu_utili") sudo("kill -9 `ps aux | grep nrpe | head -n1 | awk '{print $2}' `") sudo("/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d") print green("Put File success and restart nagios nrpe service!") for host in hosts: env.host_string = host put_task() #put_task()
文章版权声明
1 原创文章作者:yinyi,如若转载,请注明出处: https://www.52hwl.com/34498.html
2 温馨提示:软件侵权请联系469472785#qq.com(三天内删除相关链接)资源失效请留言反馈
3 下载提示:如遇蓝奏云无法访问,请修改lanzous(把s修改成x)
4 免责声明:本站为个人博客,所有软件信息均来自网络 修改版软件,加群广告提示为修改者自留,非本站信息,注意鉴别