利用ansible监控远程机磁盘使用率邮件告警提示

#!/bin/bash
#by fuqiang
#2018-08-12


#取回系统盘使用率信息,只选择打印输出的第5列参数
ansible jira -m shell -a 'df -h | grep /dev/vda1' | awk '{print $5}' > /home/ansible/log/ansible-get-jira-disk-infomation.log
#去除第一行,留下第二行的参数
sed -i '1d' /home/ansible/log/ansible-get-jira-disk-infomation.log
#去除%,并赋值给变量num
num=`sed 's/.$//' /home/ansible/log/ansible-get-jira-disk-infomation.log`

#如果大于系统盘使用率大于等于95,邮件告警
if [ $num -ge 95 ];then
   sendEmail -f monitor-sy***@skieer.com -t fuqi***@skieer.com -t -t ***@skieer.com -t xiao***@skieer.com -s smtp.exmail.qq.com -u 'Jira Disk(system partition) Warning ' -xu monitor-sy***@skieer.com -xp Harry**** -m '1.Jira disk(system partion) usage percent >= 95%' -a /home/ansible/log/ansible-get-jira-disk-infomation.log
fi
#如果小于95,状态正常
if [ $num -lt 95 ];then 
   echo 'No errors!' > /home/ansible/log/NoErrors-monitor-jira-disk.log
fi

你可能感兴趣的:(ansible)