微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用shell检测raid状态并制作表格发送到邮箱

catraid_fzt.sh
#!/bin/bash
#data:2018.3.9
#checkraidstatusandmailtosomeone
DIR="/home/s/ops/pantheon/argos/raid.check"#脚本所在目录
cd$DIR
LOG='raid_check.2018-03-09_11:17:31'
#LOG=$(ls-traid_check.`date+"%F"`.*|xargsecho|cut-d''-f1)
BAD_RAID=$(python/raid.check/marshalv3.py$LOG)#有问题Raid的列表

html_input(){
echo"<tr>
<td>$1</td>
<td>$2</td>
<td>$3</td>
<td>$4</td>
</tr>">>$DIR/mail.html
}#构造一横行表格信息

set_info(){
echo"<head>
<Metahttp-equiv="Content-Type"content="text/html\;charset=UTF-8">
<p><fontcolor="red">如下服务器硬件报警,请业务尽快报修,报修时请在报修工单中写明故障信息。</font></p>
</head>
<tableborder=1>
<tr>
<th>主机信息</th>
<th>Hermes信息</th>
<th>接口负责人</th>
<th>业务负责人</th>
</tr>">$DIR/mail.html
host_list=$(grep$1raid_info|awk'{print$1}')#主机信息列表
forhtml_hostin$host_list
do
html_owner=$(grep$html_hostraid_info|awk'{print$4}')#对应owner信息
html_hermes=$(grep$html_hostraid_info|awk'{print$2}')#对应hermes信息
echo$html_host$html_hermes$1$html_owner
html_input$html_host$html_hermes$1$html_owner#构造每行表格信息
done
echo"</table>
<p><font>如有问题请联系:</font><ahref="mailto:go-sa@mail.net">go-sa@mail.net</a></p>
<p><fontface="arial"color="red">此邮件为系统发送,请勿回复!!!</font></p>">>mail.html
#catmail.html>>all.html#报表汇总
muttmubai@mail.net-s"Raidcheck"-e"setcontent_type=text/html"<$DIR/mail.html#发送邮件
#mutt$1-s"Raid检测报警"-e"setcontent_type=text/html"<$DIR/mail.html
}#制作mail.html,并使用邮件发送

forhostin$BAD_RAID
do
HERMES=$(Pwhoismycluster$host|grep"hermes:"-A1|sed-n'2p'|cut-d:-f1|sed's/[[:space:]]//g')#
OWNER=$(curl-s"http://10.95.22.14:9093/element/findServerUserBy"-H"Content-Type:application/json"-d'{"HostnameIn":"'$host'"}'|grep-Po'"owner":".*?"'|awk-F":"'{print$NF}'|sed's/"//g')
OPS=$(curl-s"http://10.95.22.14:9093/element/findServerUserBy"-H"Content-Type:application/json"-d'{"HostnameIn":"'$host'"}'|grep-Po'"ops":".*?"'|awk-F":"'{print$NF}'|sed's/"//g')
OPS=${OPS:=fanzhengteng@360.net}
HERMES=${HERMES:=没查到HERMES}
OWNER=${OWNER:=没查到OWNER}
#echo$host$HERMES$OPS$OWNER
echo$host$HERMES$OPS$OWNER>>$DIR/raid_info
done#找到hosthermesopsowner信息并写入raid_info这个文件中,供后续处理

OPS_LIST=$(cat$DIR/raid_info|awk'{print$3}'|sort|uniq)#相同邮件人去重
forhtml_opsin$OPS_LIST
do
set_info$html_ops#set_info来发送邮件
done
rm$DIR/raid_info#删除raid_info这个文件

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐