Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
fh = logging.FileHandler(LOG_FILENAME)
fh.setFormatter(formatter)

logger = logging.getLogger('region_devs_retry')
logger.addHandler(fh)
logger.setLevel(logging.DEBUG)

# db = query_db_session()
# db = MongoClient("mongodb://*****:*****@172.16.21.205/bermuda", 27017)['bermuda']
# db = MongoClient("mongodb://*****:*****@172.16.21.205:27017/bermuda, 27017)['bermuda']
# db = MongoClient("mongodb://*****:*****@223.202.52.135/bermuda", 27017)['bermuda']
db =database.query_db_session()
preload_cache = redisfactory.getDB(1)
PRELOAD_DEVS = redisfactory.getDB(5)
MONITOR_USER = ["cztv"]
config = initConfig()


def get_result_by_id(url_id):
    try:
        result = preload_cache.get(url_id)
        if result:
            return json.loads(result)
        else:
            return db.preload_result.find_one({"_id": ObjectId(url_id)})
    except Exception, e:
        return {}


# """<?xml version="1.0" encoding="utf-8"?><preload_task sessionid="38be89acdb3a11e3a7c090e2ba343030">
# <action>refresh,preload</action><priority>0</priority><nest_track_level>0</nest_track_level><check_type>MD5</check_type><limit_rate>0</limit_rate><preload_address>127.0.0.1:80</preload_address><report_address need="yes">223.202.52.43:80</report_address><is_override>1</is_override><url_list><url id="53731c95922be573cf34d1e4">http://bakdl.sjk.ijinshan.com/apk/mumayi/338/com.mobi.common.main.fzlmv.14.2715306.apk</url><url id="53731c95922be573cf34d1e5">http://bakdl.sjk.ijinshan.com/apk/AppChina/285/kk.fruit_link.66.2156328.apk</url><url id="53731c95922be573cf34d1e6">http://bakdl.sjk.ijinshan.com/apk/AppChina/279/com.xs.cn.119.5529256.apk</url><url id="53731c95922be573cf34d1e7">http://bakdl.sjk.ijinshan.com/apk/mumayi/398/com.mobi.livewallpaper.hdsj4.37.3161195.apk</url><url id="53731c95922be573cf34d1e8">http://bakdl.sjk.ijinshan.com/apk/m91/94/com.douban.group.231.3097473.apk</url></url_list></preload_task>"""
Ejemplo n.º 4
0
import datetime
import argparse
import time
import sys
import requests

LOG_FILENAME = config.get("log","LOG_PATH")+'get_api.log'
logger = logging.getLogger('worker')
exec('logger.setLevel(%s)' % config.get('log', 'log_level'))
format = "%(asctime)s %(filename)s %(lineno)d %(levelname)s %(message)s"
handler = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME, "midnight", 1, 30)
handler.setFormatter(logging.Formatter(format))
handler.suffix = "%Y%m%d"
logger.addHandler(handler)

api_list_config = initConfig()
PACKAGE_SIZE = config.getint("package", "size")

now = datetime.datetime.now()

requestt = requests.get("http://alpha.elmeast.com.cn/api/calledForlikun/getDomainByUserName.php?username=Microsoft")
domainArr = requestt.json()
domainArr = ['update1.csgo.wmsj.cn']


def default(ts=None):
    try:
        if ts is None:
            x = datetime.datetime.now() - datetime.timedelta(hours=1)
            xx = x.strftime('%Y-%m-%d %H') + ':00:00'
            timeArray = time.strptime(xx, "%Y-%m-%d %H:%M:%S")