本文整理汇总了Python中mail.Mail.set_param方法的典型用法代码示例。如果您正苦于以下问题:Python Mail.set_param方法的具体用法?Python Mail.set_param怎么用?Python Mail.set_param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mail.Mail
的用法示例。
在下文中一共展示了Mail.set_param方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from mail import Mail [as 别名]
# 或者: from mail.Mail import set_param [as 别名]
def run(self):
try:
while True:
# Les conditions de crises sont prises de la configuration
maxCPU = self.config.get("crisis/max_cpu")
maxRAM = self.config.get("crisis/max_ram")
maxSwap = self.config.get("crisis/max_swap")
maxDisk = self.config.get("crisis/max_disk")
# On cherche les serveurs dans la BDD
for s in self.db.get_all("server"):
server = Server(s["name"], s["ip"], s["uptime"])
# Obtention de la date la plus actuelle
lastDate = self.db.get_last_date(server.name).next()[0]
# Obtention des stats
res = self.db.get_by_fields("stat",
["server_name", "timestamp"],
[server.name, lastDate]).next()
resDisks = self.db.get_by_fields("statDisk",
["server_name", "timestamp"],
[server.name, lastDate])
# Création d'objets à partir des données
cpu = ArrayDataObject();
cpu.used = float(res["cpu_used"])
ram = ArrayDataObject();
ram.total = int(res["ram_total"]);
ram.used = float(res["ram_used"])
swap = ArrayDataObject();
swap.total = int(res["swap_total"]);
swap.used = float(res["swap_used"])
disks = []
for line in resDisks:
d = ArrayDataObject()
d.mnt = line["mnt"]
d.total = int(line["total"])
d.used = float(line["used"])
disks.append(d)
# Détection de situation de crise
ramPercent = ram.used * 100 / ram.total
swapPercent = ram.used * 100 / ram.total
disksTotalUsed = 0
disksTotal = 0
for d in disks:
disksTotalUsed += d.used
disksTotal += d.total
disksPercent = disksTotalUsed * 100 / disksTotal
if (cpu.used >= float(maxCPU)
or ramPercent >= float(maxRAM)
or swapPercent >= float(maxSwap)
or disksPercent >= float(maxDisk)):
# Classe pour envoyer des mails
mail = Mail()
mail.set_param("server.name", server.name)
mail.set_param("server.ip", server.ip)
mail.set_param("cpu.used", "{:.1f}".format(cpu.used))
mail.set_param("ram.percent", "{:.1f}".format(ramPercent))
mail.set_param("swap.percent", "{:.1f}".format(swapPercent))
mail.set_param("disks.percent", "{:.1f}".format(disksPercent))
mail.send(self.config.get("email/address"), self.config.get("email/subject"),
self.config.get("email/template_html"), self.config.get("email/template_txt"))
print "Crise détectée. Un email a été envoyé à " + self.config.get("email/address")
# Fin for
time.sleep(self.DELAY)
# Recharge de la configuration
self.config.recharger()
# Fin while
except Exception, e:
raise