20.23 20.4 20.5告警系统邮件引擎(上中下);20.26 运行告警系统

前端之家收集整理的这篇文章主要介绍了20.23 20.4 20.5告警系统邮件引擎(上中下);20.26 运行告警系统前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

20.23 20.4 20.4 告警系统邮件引擎(上中下)

shell项目-告警系统mail.sh

1. 创建mail.py脚本:

[root@hao-01 ~]# vim /usr/local/bin/mon/mail/mail.py

#####脚本使用说明######

#1. 首先定义好脚本中的邮箱账号和密码

#2. 脚本执行命令为:python mail.py 目标邮箱 "邮件主题" "邮件内容"

内容参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D22Z/mail.py

添加内容

#!/usr/bin/env python

#-*- coding: UTF-8 -*-

import os,sys

import getopt

import smtplib

from email.MIMEText import MIMEText

from email.MIMEMultipart import MIMEMultipart

from subprocess import *

def sendqqmail(username,password,mailfrom,mailto,subject,content):

gserver = 'smtp.163.com'

gport = 25

try:

msg = MIMEText(unicode(content).encode('utf-8'))

msg['from'] = mailfrom

msg['to'] = mailto

msg['Reply-To'] = mailfrom

msg['Subject'] = subject

smtp = smtplib.SMTP(gserver,gport)

smtp.set_debuglevel(0)

smtp.ehlo()

smtp.login(username,password)

smtp.sendmail(mailfrom,msg.as_string())

smtp.close()

except Exception,err:

print "Send mail Failed. Error: %s" % err

def main():

to=sys.argv[1]

subject=sys.argv[2]

content=sys.argv[3]

##定义邮箱的账号和密码,你需要修改成你自己的账号和密码(请不要把真实的用户名和密码放到网上公开)

sendqqmail('zhuneianxiang@163.com','mimaif __name__ == "__main__":

main()

2.设定脚本权限755

chmod 755 /usr/local/bin/mail.py

3. 创建mail.shvim /usr/local/bin/mail.sh

mail.sh内容 //其中mail.py内容到这里下载https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D22Z/mail.py

添加内容:

log=$1

t_s=`date +%s`

t_s2=`date -d "2 hours ago" +%s`

if [ ! -f /tmp/$log ]

then

echo $t_s2 > /tmp/$log

fi

t_s2=`tail -1 /tmp/$log|awk '{print $1}'`

echo $t_s>>/tmp/$log

v=$[$t_s-$t_s2]

echo $v

if [ $v -gt 3600 ]

./mail.py $1 $2 $3

echo "0" > /tmp/$log.txt

else

if [ ! -f /tmp/$log.txt ]

nu=`cat /tmp/$log.txt`

nu2=$[$nu+1]

echo $nu2>/tmp/$log.txt

if [ $nu2 -gt 10 ]

./mail.py $1 "trouble continue 10 min $2" "$3"

fi

20.26运行告警系统

暂时关闭502

[root@hao-01 ~]# vim /usr/local/bin/mon/conf/mon.conf

wKioL1nA1gDyaRj6AAAvA1kecHU889.png

spacer.gif

2. 暂时注释掉main.sh脚本中日志行mon/bin/main.sh

wKioL1nA1hrCLRWaAAAu2dxz3Ow122.png

spacer.gif

3. 执行main.sh

[root@hao-01 ~]# sh -x /usr/local/bin/mon/bin/4. 执行load.sh

[root@hao-01 ~]# bash/usr/local/bin/mon/shares/load.sh

wKiom1nA1mWxleExAAAL7DrAlHk475.png

原文链接:https://www.f2er.com/bash/390527.html

猜你在找的Bash相关文章