Exemplo n.º 1
0
# -*- coding:utf-8 -*-
import smtplib

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.header import Header
from utils.getConfig import get_conf

HOST = get_conf("mail", "HOST")
USER = get_conf("mail", "USER")
PASSWORD = get_conf("mail", "PASSWORD")
PORT = get_conf("mail", "PORT")


def sendmail(sender, receiver, subject, message, picList):
    '''
    :param message: 邮件正文
    :param picList: 邮件中的图片文件名列表
    '''
    def addimg(src, imgid):
        fp = open(src, 'rb')
        msgImage = MIMEImage(fp.read())
        fp.close()
        msgImage.add_header('Content-ID', imgid)
        return msgImage

    msgRoot = MIMEMultipart('related')
    msgtext = MIMEText(message, "html", "utf-8")
    msgRoot.attach(msgtext)
    for i in range(len(picList)):
Exemplo n.º 2
0
from cm_api.endpoints.types import ApiList
from utils.getConfig import get_conf
from utils.sendmail import sendmail
from utils.utc import utc2local
import utils.getDate
from utils.line_model import get_linear_model
from pygal.style import LightGreenStyle

reload(sys)
sys.setdefaultencoding('utf-8')

# 解决Matplotlib中文问题
pl.mpl.rcParams['font.sans-serif'] = ['SimHei']  #指定默认字体
pl.mpl.rcParams['axes.unicode_minus'] = False  #解决保存图像是负号'-
#邮箱配置
FROM = get_conf("mail", "FROM")
TO = string.splitfields(get_conf("mail", "TO"), ',')
SUBJECT = get_conf("mail",
                   "SUBJECT") + datetime.datetime.now().strftime('%Y-%m-%d')

CAPTION = get_conf("pic", "caption")
CAPTIONCPU = get_conf("pic", "captionCPU")
CAPTIONMEM = get_conf("pic", "captionMEM")
CAPTIONNET = get_conf("pic", "captionNET")
filenameCPU = get_conf("pic", "filenameCPU")
filenameMEM = get_conf("pic", "filenameMEM")
filenameNET = get_conf("pic", "filenameNET")
SUFIX = get_conf("pic", "SUFIX")

# WIDTH = get_conf("pic","WIDTH")
# HEIGHT = get_conf("pic","HEIGHT")
Exemplo n.º 3
0
from cm_api.endpoints.timeseries import *
from utils.utc import utc2local
from utils.getConfig import get_conf
from utils.sendmail import sendmail
import json
import urllib2
import string
from common.api_client import ApiClient
from cm_api.endpoints.services import get_service
from utils.date_util import round_milli_time
# 导入一个函数将数据转为字典

reload(sys)
sys.setdefaultencoding('utf-8')
#邮箱配置
FROM = get_conf("mail", "FROM")


def do_query(query, from_time, to_time):
    # return api_ts list
    responseList = []
    tsquery = TimeSeriesQuery()
    for response in tsquery.query(query, from_time, to_time):
        responseList.append(response)
    return responseList


# define function:getAllUserInfo to get all unique users
def getAllUserInfo(query, attrs, from_time, to_time):
    '''
    return a list of dict for each user info 返回一个由字典组成的列表,字典里面由各个属性加上对应的值的列表
Exemplo n.º 4
0
#!/usr/bin/env python
from utils.getConfig import get_conf
from cm_api.api_client import ApiResource, ApiException
from cm_api.http_client import HttpClient
from cm_api.resource import Resource

# CM_HOST = get_conf("clouderaTest", "CM_HOST")
# CM_USER = get_conf("clouderaTest", "CM_USER")
# CM_PASSWD = get_conf("clouderaTest", "CM_PASSWD")
# VERSION = get_conf("clouderaTest","VERSION")

CM_HOST = get_conf("clouderaProd", "CM_HOST")
CM_USER = get_conf("clouderaProd", "CM_USER")
CM_PASSWD = get_conf("clouderaProd", "CM_PASSWD")
VERSION = get_conf("clouderaProd","VERSION")

class ApiClient(object):
    """

    """

    def __init__(self):
        self._api = ApiResource(CM_HOST, username=CM_USER, password=CM_PASSWD, use_tls=False, version=VERSION)