#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import os, socket
from time import localtime, strftime
from smtplib import SMTP

smtp = SMTP()
#smtp.set_debuglevel(debuglevel)
smtp.connect('d.g.g.g', 25)
smtp.login(')

from_addr = "234<234@f.f>"
to_addr_normal = ["234@f.f","234@f.f"]
to_addr_alert = ["234@f.f","s234@f.fm"]

# Limit in MiB
LIMIT=200000;

#Define current Time as Fri, 04 Mar 2011 08:47:10
TIME = strftime("%d %b %Y", localtime())

SPACE_LEFT=500000 / 1048576
SPACE_TOTAL = 1000000 / 1048576

if (SPACE_LEFT < LIMIT):
    STATUS = "Free Disk Space is ALERT!!!ALERT!!!ALERT!!! "
    SPACE_LEFT=SPACE_LEFT / 1024
    print ( TIME+"\n"+STATUS+"\n"+str(SPACE_LEFT)+" GB left on disk\n"+"Alert Space is:"+str((LIMIT/1024))+"GB")
    subj = "ALERT!!!ALERT!!!ALERT!!!["+str(SPACE_LEFT)+" GB left]Free disk space on wwwcom "+TIME
    message_text = TIME+"\n"+STATUS+"\n"+str(SPACE_LEFT)+" GB left on disk\n"+"Alert Space is:"+str((LIMIT/1024))+"GB"
    msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % ( from_addr, to_addr_alert, subj, TIME, message_text )
    smtp.sendmail(from_addr, to_addr_alert, msg)
    smtp.sendmail(from_addr, to_addr_alert, msg)
    smtp.sendmail(from_addr, to_addr_alert, msg)
    smtp.quit()
    print ('Done')

elif (SPACE_LEFT > LIMIT):
        STATUS = "Free Disk Space is OK on "
           SPACE_LEFT=SPACE_LEFT / 1024
        SPACE_TOTAL=SPACE_TOTAL / 1024
        print ( TIME+"\n"+STATUS+"\n"+str(SPACE_LEFT)+" GB left on disk("+str(SPACE_TOTAL)+"GB)\n"+"Alert Space is:"+str((LIMIT/1024))+"GB")
        subj = "["+str(SPACE_LEFT)+" GB left]Free disk space on ww) "+TIME
        message_text = TIME+"\n"+STATUS+"\n"+"Total space is :"+str(SPACE_TOTAL)+"GB\n"+str(SPACE_LEFT)+" GB left on disk\n"+"Alert Space is:"+str((LIMIT/1024))+"GB"
        msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % ( from_addr, to_addr_normal, subj, TIME, message_text )
        smtp.sendmail(from_addr, to_addr_normal, msg)
        smtp.quit()
        print ('Done!')

else:
        print ("""
A serius problem detected with the script.
Please check what mount points you monitor and check that they're in the MON_ARRAY aswell.
""" )

python邮件收发SAMPLE的更多相关文章

  1. Python:sample函数

    sample(序列a,n) 功能:从序列a中随机抽取n个元素,并将n个元素生以list形式返回. 例: from random import randint, sample date = [randi ...

  2. python——random.sample()的用法

    写脚本过程中用到了需要随机一段字符串的操作,查了一下资料,对于random.sample的用法,多用于截取列表的指定长度的随机数,但是不会改变列表本身的排序: list = [0,1,2,3,4] r ...

  3. python参数Sample Code

    import time import datetime import getopt import sys try: opts, args = getopt.getopt(sys.argv[1:], & ...

  4. Python Learning

    这是自己之前整理的学习Python的资料,分享出来,希望能给别人一点帮助. Learning Plan Python是什么?- 对Python有基本的认识 版本区别 下载 安装 IDE 文件构造 Py ...

  5. Python本地化例子 - gettext 模块

    关键字:Python 3.4,gettext,本地化,Localization OS:Windows 7,Mac 1. 创建一个locsample.py文件,文件内容如下,把所有需要本地化的字符串放到 ...

  6. 关于乱序(shuffle)与随机采样(sample)的一点探究

    最近一个月的时间,基本上都在加班加点的写业务,在写代码的时候,也遇到了一个有趣的问题,值得记录一下. 简单来说,需求是从一个字典(python dict)中随机选出K个满足条件的key.代码如下(py ...

  7. 像Excel一样使用python进行数据分析

    Excel是数据分析中最常用的工具,本篇文章通过python与excel的功能对比介绍如何使用python通过函数式编程完成excel中的数据处理及分析工作.在Python中pandas库用于数据处理 ...

  8. Python面向对象编程和模块

    在面向对象编程中,你编写表示现实世界中的事物和情景的类,并基于这些类来创建对象. 编写类时,你定义一大类对象都有的通用行为.基于类创建对象时,每个对象都自动具备这种通用行为,然后根据需要赋予每个对象独 ...

  9. 阿里云收集服务器性能指标的python脚本

    #!/usr/bin/python ######################################### # Function: sample linux performance ind ...

随机推荐

  1. Android_RadioButton,CheckBox

    xml文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...

  2. 练习题之ThreadLocal

    public class ThreadLocalMain { private static ThreadLocal<Integer> value = new ThreadLocal< ...

  3. JavaScript入门(3)

    一.认识DOM 文档对象模型DOM(Document Object Model)定义访问和处理HTML文档的标准方法.DOM将HTML文档呈现为带有元素.属性和文本的树结构(节点树). Eg: 将HT ...

  4. 如何在网页上显示html代码?

    a: 把代码写在文本区域 <textarea> 标签中.可以设置 disabled="disabled" 属性,禁止用户操作.b: 把要显示在html文档中标签的 &q ...

  5. nyoj89 汉诺塔(二)

    题目网址 :http://acm.nyist.net/JudgeOnline/problem.php?pid=89 汉诺塔问题的经典结论: 把i个盘子从一个柱子整体移到另一个柱子最少需要步数是 2的i ...

  6. pageContext.request.contextPath

    jsp:<c:set var="ctxStatic" value="${pageContext.request.contextPath}"/>嵌套d ...

  7. swift-07-使用for-in 遍历数组

    //for-in /* for 迭代变量 in集合变量 { 使用迭代变量便利所有数据 } */ //遍历数组 var arr = ["a" ,"b" ,&quo ...

  8. ReactNative-----环境搭建(android)

    1.参考文档 http://reactnative.cn/docs/0.26/getting-started.html http://reactnative.cn/docs/0.26/running- ...

  9. javaee学习-servlet初始化参数

    1.需要定义ServletConfig对象来接收servlet配置的初始化参数. 2.当servlet配置了初始化参数后,web容器在创建servlet实例对象时, 会自动将这些初始化参数封装到Ser ...

  10. WPF页面跳转

    WPF页面跳转有两种:一种是windows,另外一种是page  1:windows页面跳转windows 页面跳转相信学过winform编程的哥们都知道,先实例化该窗体然后show一下就可以了.eg ...