#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author:anthony
# date:20171129
# used:监控功能程序
import os
import Smail
import time
import smtplib
sender = '[email protected]' # 邮件发送人
receivers = ['[email protected]'] # 邮件接收人
# 通知消息
message = """
service进程挂了,ip地址为192.168.145.131,赶紧看看。
microservice-web-api-user-0.0.1-SNAPSHOT_201711091536.jar
"""
# 检测进程是否存在
#servicename = raw_input('请输入进程全名称:')
process="/root/web_api.lock"
os.system("ps -ef|grep microservice-web-api-user-0.0.1-SNAPSHOT_201711091536.jar |grep -v grep >%s" % process)
# 报警邮件发送
if (os.path.getsize(process)):
#os.system("nohup /root/servicename &")
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print ("Successfully sent email")
except smtplib.SMTPException:
print("Error: unable to send email")