#!/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. maven跳过单元测试

    24.跳过单元测试 <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>mav ...

  2. 转:通过API获取和创建 Oracle GL Account Code Combination ID’s (CCID’s)的几种方法汇总

    1] FND_FLEX_EXT.GET_COMBINATION_ID: This API Finds combination_id for given set of key flexfield seg ...

  3. XML操作 之获取指定节点值

    根据节点名称快速查找 指定节点值 using (TextReader stringReader = new StringReader(clearPassResponse)) { XmlReaderSe ...

  4. Lucene/Solr开发经验

    1.开篇语2.概述3.渊源4.初识Solr5.Solr的安装6.Solr分词顺序7.Solr中文应用的一个实例8.Solr的检索运算符 [开篇语]按照惯例应该写一篇技术文章了,这次结合Lucene/S ...

  5. kindeditor-4.1.10在线编辑器的使用[多个]

    <script type="text/javascript" charset="utf-8" src="../../Editor/kindedi ...

  6. c#汉字与编码之间的转换(输出十六进制)

    /******************************************************************/ /*********************** ****** ...

  7. 原型模式(Prototype Pattern)

    原型模型:用于创建重复对象,同时保证性能. 这种模式实现一个原型接口,用于创建对象的克隆,当直接创建对象的代价比较大,则可以采用这种模式.例如:一个对象需要高代价的数据库操作之后被创建,这时可以缓存该 ...

  8. ASP.NET的GET和POST方式的区别归纳总结

    表单提交中,ASP.NET的Get和Post方式的区别归纳如下 几点: 1. get是从服务器上获取数据,post是向服务器传送数据. 2.  get是把参数数据队列加到提交表单的ACTION属性所指 ...

  9. linux/win7下安装websphere application server

    说明: 1.参考网址:http://www.ibm.com/developerworks/cn/aix/library/au-wasonlinux/ 2.在ibm官网上下载websphere appl ...

  10. std::string stringf(const char* format, ...)

    std::string stringf(const char* format, ...){ va_list arg_list; va_start(arg_list, format); // SUSv2 ...