def do_job(self): refresh_email = initConfig().get('refresh_noc_monitor', 'refresh_email').split(',') subject = "**redis监控**" mailContent = "" alert_messages = [] if self.check_redis(initConfig().get('redis', 'host'), 6379) != "ok": alert_messages.append( self.check_redis(initConfig().get('redis', 'host'), 6379)) if self.check_redis(initConfig().get('redis', 'host_bak'), 6379) != "ok": alert_messages.append( self.check_redis(initConfig().get('redis', 'host_bak'), 6379)) for message in alert_messages: mailContent += str(message) + "\n" logger.debug(message) args = { "content": str(message), "phonenum": "13683011499;13910311138;18600219291" } urllib.request.urlopen( "http://logmonitor.chinacache.net:8888/mobile/", urllib.parse.urlencode(args), timeout=10) try: if len(alert_messages) > 0: sendEmail.send(refresh_email, subject, mailContent.encode('utf8')) except Exception: logger.debug(e)
def send(db,tasks): logger.debug( "init error_email start ....") try: for channel_code,tasks in merge(tasks).items(): logger.debug("send mail begining...") #logger.debug("get_addr:%s ,content:%s" % (get_addr(db,channel_code),get_content(tasks))) sendEmail.send(get_addr(db,channel_code), "刷新失败任务报警", get_content(tasks)) logger.debug( "send mail ending...") except Exception: logger.debug("send mail error:%s!" % e)
def send_mail(self, urls, toaddrs): devs_dict = self.get_error_devs(urls) logger.debug("%s devs_dict: %s , urlList_len:%s " % (self.customerName, len(devs_dict), len(urls))) if devs_dict: mailContent = self.initMailContent(urls, devs_dict) subject = u"**" + self.customerName + u"刷新失败列表**" try: sendEmail.send(toaddrs, subject, mailContent.encode('utf8')) logger.debug("%s send email! " % (self.customerName)) except Exception, e: logger.error(traceback.format_exc(e))
def do_job(self): alert_messages = [] alert_messages_noc = [] logging.info('mq_monitor start.') for mq in self.db.mq_status.find(): server_name = mq.get('_id') print server_name,mq.get('update_time') if time.mktime(datetime.now().timetuple()) - time.mktime(mq.get('update_time').timetuple()) > 300 and ( self.agent_last_send_time == '' or time.mktime( datetime.now().timetuple()) - self.agent_last_send_time > 1800): alert_messages.append("%s ageng is down!" % server_name) self.agent_last_send_time = time.mktime(datetime.now().timetuple()) for queue_status in mq.get('status'): if self.threshold.get(queue_status['name'], 0) < int(queue_status['m_ready']): alert_messages.append("%s %s %s" % (server_name, queue_status['name'], queue_status['m_ready'])) for queue_status in mq.get('status'): if self.threshold_noc.get(queue_status['name'], 0) < int(queue_status['m_ready']): alert_messages_noc.append("%s %s %s" % (server_name, queue_status['name'], queue_status['m_ready'])) config = initConfig() refresh_email = config.get('refresh_noc_monitor', 'refresh_email').split(',') subject = "**队列堆积报警**" mailContent = "" for message in alert_messages: mailContent += message + "\n" logging.warn(message) #args = {"content": message, "phonenum": "15910506097;13717961668;15801269880;15910506922"} #urllib2.urlopen("http://logmonitor.chinacache.net:8888/mobile/", urllib.urlencode(args), timeout=10) #根总借的帐号 config = {"username":"******","password":"******","mobile":"15910506097;13717961668;15801269880;15910506922","content":message} query = urllib.urlencode(config) print urllib2.urlopen(SMSURL, query, timeout=10).read() mailContent_noc = u"刷新队列堆积报警,请通知刷新组维护人员(张宏安、于善良、马欢)\n" subject_noc = "**队列堆积报警**" noc_email = config.get('refresh_noc_monitor', 'noc_email').split(',') for message in alert_messages_noc: mailContent_noc += message + "\n" logging.warn("refresh queue detail: %s: " % (message)) try: if len(alert_messages) > 0: sendEmail.send(refresh_email, subject, mailContent.encode('utf8')) if len(alert_messages_noc) > 0: sendEmail.send(noc_email, subject_noc, mailContent_noc.encode('utf8')) except Exception, e: logging.debug(e)
class details_fails_urls(object): def __init__(self, conn, begin_date, end_date, username, to_add): super(details_fails_urls, self).__init__() self.begin_date = begin_date self.end_date = end_date self.connect = conn self.username = username self.to_add = to_add self.collection_url = '' self.collection_dev = '' def get_fail_urls(self): find_url_dic = { "parent": self.username, "status": "FAILED", "created_time": { "$gte": self.begin_date, "$lt": self.end_date }, "finish_time": { "$exists": "true" } } field_dic = { "username": 1, "_id": 1, "dev_id": 1, "created_time": 1, "parent": 1, "url": 1 } self.collection_url = self.connect['url'] return self.collection_url.find(find_url_dic, field_dic) def run(self): fail_list = [] for url in self.get_fail_urls(): try: u_dic = {} u_dic['uid'] = str(url.get("_id")) u_dic['created_time'] = url.get("created_time").strftime( '%Y-%m-%d %H:%M:%S') u_dic['url'] = url.get("url") u_dic['failed'] = get_fail_url_device(self.connect['device'], url.get("dev_id")) fail_list.append(u_dic) except Exception, ex: logger.error('run error: %s' % traceback.format_exc(ex)) try: if fail_list: sendEmail.send( self.to_add, '%s error task alarm' % self.username, getEmail(self.username, self.end_date, fail_list)) except Exception, ex: logger.error(traceback.format_exc(ex))
def run(self): fail_list = [] for url in self.get_fail_urls(): try: u_dic = {} u_dic['uid'] = str(url.get("_id")) u_dic['created_time'] = url.get("created_time").strftime( '%Y-%m-%d %H:%M:%S') u_dic['url'] = url.get("url") u_dic['failed'] = get_fail_url_device(self.connect['device'], url.get("dev_id")) fail_list.append(u_dic) except Exception: logger.error('run error: %s' % traceback.format_exc()) try: if fail_list: sendEmail.send( self.to_add, '%s error task alarm' % self.username, getEmail(self.username, self.end_date, fail_list)) except Exception: logger.error(traceback.format_exc()) logger.info('process insert :{0}'.format(len(fail_list)))
def send_error_email(task_info, error_list): ''' 发送失败设备邮件 ''' task_id = task_info['_id'] cert_id = task_info['c_id'] username = task_info['username'] created_time = task_info['created_time'] all_error = [] dev_info = s1_db.cert_trans_dev.find_one( {'_id': ObjectId(task_info['dev_id'])}) content = '用户ID: %s , 证书ID: %s 于 %s 下发证书任务,失败设备如下: \n' % ( username, cert_id, created_time) table = '<table border="1">\n<tr><th>name</th><th>host</th><th>type</th><th>code</th><th>a_code</th><th>r_code</th><th>c_code</th>' # 下发 for h_k, h_d in list(dev_info['devices'].items()): if h_d['code'] == 200: continue table += '<tr><td>%s</td><td style="text-align:center">%s</td><td style="text-align:center">%s</td><td style="text-align:center">%s</td><td style="text-align:center">%s</td><td style="text-align:center">%s</td><td style="text-align:center">%s</td></tr>' % ( h_k, h_d['host'], h_d['type'], h_d['code'], h_d['a_code'], h_d['r_code'], 0) all_error.append(h_d) # 回调 暂时排除 0 for error_dev in error_list: e_code = int(error_dev.get('code', 0)) if e_code in [0, 524]: continue table += '<tr><td>%s</td><td style="text-align:center">%s</td><td style="text-align:center">%s</td><td style="text-align:center">%s</td><td style="text-align:center">%s</td><td style="text-align:center">%s</td><td style="text-align:center">%s</td></tr>' % ( error_dev['name'], error_dev['host'], error_dev['type'], 200, 200, 200, error_dev['code']) all_error.append(error_dev) table += '</table>\n' content_end = '请依照 wiki http://wiki.dev.chinacache.com/pages/viewpage.action?pageId=43014430 步骤操作 处理异常设备' all_content = content + table + content_end to_addrs = config.get('cert_trans', 'email_group') attch = store_error_host(cert_id, all_error) if attch: attchs = [attch] else: attchs = [] # noc 版本 sendEmail.send(eval(to_addrs), '自助证书下发邮件告警', all_content.encode('utf-8'), 'html', attchs) try: # 个人版 p_attch = store_error_host(cert_id, error_list) if p_attch: p_attchs = [p_attch] else: p_attchs = [] sendEmail.send(['*****@*****.**'], '自助证书下发邮件详情', all_content.encode('utf-8'), 'html', p_attchs) #sendEmail.send(['*****@*****.**'], '自助证书下发邮件详情', all_content.encode('utf-8'), 'html', p_attchs) except: pass