国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > CentOS > 正文

Python腳本監(jiān)控CentOS磁盤(pán)空間

2024-06-28 16:00:16
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Python腳本監(jiān)控CentOS磁盤(pán)空間,任何一個(gè)分區(qū)空間使用大于80%即發(fā)郵件給到指定郵箱。

monitor.py

#-*- coding: utf-8 -*-import socketimport subPRocessimport smtplibfrom email.mime.text import MIMETextsender="xxx.xx@xxx.com"receiver= ["xxx.xx@xxx.com"]smtpHost="10.134.xxx.xxx"smtpPort="587"def get_ip():    hostname =  socket.getfqdn(socket.gethostname())    ip = socket.gethostbyname(hostname)    return ipdef send_mail(receiver,subject,content):    ip = get_ip()    msg = MIMEText(content,_subtype='plain',_charset='utf-8')    msg['Subject'] = subject    msg['From'] = 'CLOUD SERVER ' + ip    msg['To'] = ",".join(receiver)    try:        smtp = smtplib.SMTP(smtpHost,smtpPort)        #smtp.set_debuglevel(1)        smtp.docmd("HELO Server")        smtp.ehlo("ismetoad")        smtp.starttls()        smtp.helo("ismetoad")        smtp.sendmail(sender,receiver,msg.as_string())        smtp.close()    except Exception as error:        print(error)def run_cmd(cmd):    process = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE)        result_f,error_f = process.stdout,process.stderr    errors = error_f.read()    if errors:        pass    result = result_f.read().decode()    if result_f:        result_f.close()    if error_f:        error_f.close()    return resultdef disk_check():    subject = ''    result = run_cmd(cmd)    content = '[root@vm-vc02-SR910 ~]# ' + cmd + '/n' + result    result = result.split('/n')    for line in result:        if 'G ' in line or 'M ' in line:            line = line.split()            for i in line:                if '%' in i and int(i.strip('%')) > 80:                    subject = '[WARNING] SERVER FILESYSTEM USE% OVER ' + i + ', PLEASE CHECK!'    if subject:        send_mail(receiver,subject,content)        print('email sended')    else:        print('Everything is ok, keep on monitor.')                           if __name__ == '__main__':    cmd = 'df -h'    disk_check()


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 安泽县| 日喀则市| 宝丰县| 南部县| 明星| 扶沟县| 连州市| 巴林右旗| 青田县| 永泰县| 进贤县| 遵化市| 衡东县| 旺苍县| 隆子县| 贺兰县| 墨脱县| 密云县| 德保县| 丘北县| 天峻县| 宜良县| 宜兰市| 宁强县| 莱西市| 南昌市| 宜兰市| 双城市| 湘阴县| 桃园县| 容城县| 稷山县| 舟山市| 宕昌县| 济源市| 阿尔山市| 石棉县| 东乌珠穆沁旗| 渝北区| 东乡族自治县| 四川省|