python邮件收发SAMPLE
#!/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的更多相关文章
- Python:sample函数
sample(序列a,n) 功能:从序列a中随机抽取n个元素,并将n个元素生以list形式返回. 例: from random import randint, sample date = [randi ...
- python——random.sample()的用法
写脚本过程中用到了需要随机一段字符串的操作,查了一下资料,对于random.sample的用法,多用于截取列表的指定长度的随机数,但是不会改变列表本身的排序: list = [0,1,2,3,4] r ...
- python参数Sample Code
import time import datetime import getopt import sys try: opts, args = getopt.getopt(sys.argv[1:], & ...
- Python Learning
这是自己之前整理的学习Python的资料,分享出来,希望能给别人一点帮助. Learning Plan Python是什么?- 对Python有基本的认识 版本区别 下载 安装 IDE 文件构造 Py ...
- Python本地化例子 - gettext 模块
关键字:Python 3.4,gettext,本地化,Localization OS:Windows 7,Mac 1. 创建一个locsample.py文件,文件内容如下,把所有需要本地化的字符串放到 ...
- 关于乱序(shuffle)与随机采样(sample)的一点探究
最近一个月的时间,基本上都在加班加点的写业务,在写代码的时候,也遇到了一个有趣的问题,值得记录一下. 简单来说,需求是从一个字典(python dict)中随机选出K个满足条件的key.代码如下(py ...
- 像Excel一样使用python进行数据分析
Excel是数据分析中最常用的工具,本篇文章通过python与excel的功能对比介绍如何使用python通过函数式编程完成excel中的数据处理及分析工作.在Python中pandas库用于数据处理 ...
- Python面向对象编程和模块
在面向对象编程中,你编写表示现实世界中的事物和情景的类,并基于这些类来创建对象. 编写类时,你定义一大类对象都有的通用行为.基于类创建对象时,每个对象都自动具备这种通用行为,然后根据需要赋予每个对象独 ...
- 阿里云收集服务器性能指标的python脚本
#!/usr/bin/python ######################################### # Function: sample linux performance ind ...
随机推荐
- ALTER---为已创建的表添加默认值
alter table table_name modify column_name default default_value; 例: alter table userinfo modify emai ...
- config文件中可以配置查询超时时间
web.config配置数据库连接 第一种:获取连接字符串 首先要定义命名空间 system.configuration 1. string connstr= string constr = Con ...
- Objective-c中的设计模式
如果你会写算法,又理解设计模式,你就牛逼了.后面一段时间我会尽可能易懂的描述来讲解iOS中的设计模式,并且每个设计模式都会有对应的demo:https://github.com/goodyboy6/D ...
- sublime text 3快捷键设置
sublime text 3 v-3103默认快捷键设置 [ { "keys": ["ctrl+shift+n"], "command": ...
- loadrunner简单的例子(demo)
刚刚做了一个loadrunner进行负载测试,把步骤截图给大伙看看.一共三个步骤 一创建/编辑脚本 二运行负载测试 三分析测试结果 首先是第一步的流程:第一步创建/编辑脚本 图一 图二 图三 图四 图 ...
- ElastciSearch常用APi
列出所有的索引: GET /_cat/indices?v 删除索引 DELETE /customer?pretty
- ACM——A + B Problem (1)
A + B Problem (1) 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:5907 测试通过:151 ...
- tomcat启动正常,404. Eclipse没有正确部署工程项目
http://blog.csdn.net/lynn_wgr/article/details/7751228 在eclipse中新建的Dynamic Web Project.写好代码后,选择Run on ...
- Object-C日志记录
在Object-C中,将日志信息输出到控制台是非常简单的.实际上NSLog()函数很像C语言里面的printf()函数,出了要用一个%@符号代表一个对象. NSLog(@"The curre ...
- Java实战之02Hibernate-01简介、常用接口、CRUD操作
一.Hibernate简介 1.Hibernate在开发中所处的位置 2.ORM映射 Object :面向对象领域的 Relational:关系数据库领域的 Mapping:映射 Object: Re ...