邮件报警脚本

#!/bin/bash
#安装邮件
rpm -q sendmail
 if [ $? -ne 0 ];then
         yum -y install sendmail
 fi
rpm -q mutt
 if [ $? -ne 0 ];then
         yum -y install mutt
 fi
systemctl restart sendmail

#设置变量
HOST=`hostname`
SYS=`uname -a`
DATE=`date "+%F %H:%M:%S"`
CPU=`cat /proc/cpuinfo |grep processor | wc -l`
ID=`vmstat | awk ‘NR==3{print $15 }‘`
WA=`vmstat | awk ‘NR==3{print $16 }‘`
LOAD=`w | awk ‘NR==1{print $8}‘ |awk -F "," ‘{print $1}‘`
DISK=`df |awk ‘{if(NR==7){print int($5)}}‘`
FREE=`free -m | awk ‘NR==2{print $4}‘`
CACHE=`free -m | awk ‘NR==2{print $7}‘`
TCP=`netstat -atunlp`
IF=`iftop -i ens33 -P -Nn -L 100 -s 1 -t`

#cpu报警
 if [ $CPU -eq 4 ];then
  echo "wa=$WA and id=$ID cpu processor is ok"
 else
  echo "wa=$WA and id=$ID cpu processor have problem" |mutt -s "SYSTEM-memory" *********@163.com
 fi
 if [ $LOAD -gt 0.05 ];then
  echo "CPU-LOAD is beyond the rate" |mutt -s "CPU-LOAD" ***********@163.com
 else
  echo "CPU-LOAD is ok"
 fi
#磁盘报警
 if [ $DISK -gt 80 ];then
  echo "SYSTEM-DISK is beyond the 80%" |mutt -s "SYSTEM-DISK" ************@163.com
 else
  echo "SYSTEM-DISK is ok"
 fi
#内存报警
memory=$(($FREE+$CACHE))
echo $memory
 if [ $memory -lt 1000 ];then
  echo "SYSTEM-memory less than 1000M " |mutt -s "SYSTEM-memory" *************@163.com
        else
                echo "SYSTEM-memory is ok"
        fi

原文地址:https://www.cnblogs.com/cuiyupu/p/10405741.html

时间: 2024-12-25 14:19:50

邮件报警脚本的相关文章

线上一个简单检测Ping状态的邮件报警脚本

Step1.安装sendmail来发邮件 # yum -y install sendmail # /etc/init.d/sendmail start # chkconfig sendmail on Step2.安装邮件客户端 # yum -y install mutt 2.1添加发件人信息,如下 # vim /etc/Muttrc set charset="utf-8"           #设置发邮件编码 set envelope_from=yes set rfc2047_para

zabbix的短信与邮件报警脚本

#!/usr/bin/python # -*- coding: utf-8 -* import sys import smtplib from email import encoders from email.header import Header from email.mime.text import MIMEText from email.utils import parseaddr, formataddr def send_email(to_addr,subject,body): msg

nagios邮件报警脚本

目的:主要作用于nagios监控系统邮件报警功能,也可以稍作修改使用于其他地方: 使用方法: perl notify_service_by_mail.pl -t connact -s subject -m message perl notify_host_by_mail.pl -t connact -s subject -m message 服务报警代码: #!/usr/bin/env perl #notify_service_by_mail.pl use strict; use warning

Zabbix 邮件报警-脚本

#!/bin/bashSMTP_server='smtp.mopon.cn' # SMTP服务器username='[email protected]' # 用户名password='taijiu,.2017' # 密码from_email_address='[email protected]' # 发件人Email地址to_email_address="$1" # 收件人Email地址,zabbix传入的第一个参数message_subject_utf8="$2"

zabbix邮件报警脚本

#!/usr/bin/python #coding:utf-8 import smtplib from email.mime.text import MIMEText import sys mail_host = 'smtp.exmail.qq.com' mail_user = '邮箱全称' mail_pass = '密码' mail_postfix = '域名' def send_mail(to_list,subject,content): me = mail_user+"<"

zabbix邮件报警脚本(Python)

#!/usr/bin/python #coding:utf-8 import smtplib from email.mime.text import MIMEText import sys mail_host = 'smtp.exmail.qq.com' mail_user = '邮箱全称' mail_pass = '密码' mail_postfix = '域名' def send_mail(to_list,subject,content): me = mail_user+"<"

使用shell编写一个脚本,磁盘超过80%邮件报警

方法1: 监控磁盘或CPU超过一定值邮件报警脚本: [[email protected] scripts]# cat check.sh #!/bin/bash LANG=en_US.UTF-8 cpuUsed=`top -n 1|awk -F '[, %]+' 'NR==3 {print100-$11}'` diskUsed=$(df -h|awk -F '[ %]+'  '/\/$/{print $5}') logFile=/tmp/jk.log function Sendmail(){ ma

通过脚本发送zabbix邮件报警

zabbix原生的报警媒介类型中,邮件报警是我们常用的方式.当我们在CentOS6上面安装zabbix3.0并配置邮件报警的时候,在邮件配置正确的前提下,不管触发器如何触发,邮件总是发送不出去,但是在CentOS7上面安装的zabbix3.0却可以正常发送邮件.究其原因,是因为zabbix3.0对服务器上的libcurl版本有要求(CentOS6.9上的默认curl版本为7.19.7,而CentOS7.2上的默认libcurl版本为7.29.0),zabbix3.0所要求的的版本说明在zabbi

zabbix3.2.1邮件报警设置

abbix监控服务端.客户端都已经部署完成,被监控主机已经添加,Zabiix监控运行正常. 在Zabbix服务端设置邮件报警,当被监控主机宕机或者达到触发器预设值时,会自动发送报警邮件到指定邮箱. 具体操作: 以下操作在Zabbix监控服务端进行 然后安装那两个依赖包,命令是: yum install perl-Net-SSLeay perl-IO-Socket-SSL -y 解压软件,然后将sendemail复制到/usr/local/bin/目录下,并加上可执行权限,然后修改用户和群组. [