Exemplo n.º 1
0
 def check(self):
     mailContent = {}
     for mail in ConfUtil.getGlobalMailList():
         mailContent[mail.strip()] = []
     for addr in self.__addrList:
         overviewUrl = 'http://' + addr.strip() + '/api/overview'
         try:
             res = requests.get(overviewUrl,
                                auth=(self.__username, self.__password))
         except ConnectionError, e:
             for mail in ConfUtil.getGlobalMailList():
                 mailContent[mail].append(addr + ' is dead.')
             continue
         queueUrl = 'http://' + addr.strip() + '/api/queues'
         res = requests.get(queueUrl,
                            auth=(self.__username, self.__password))
         for queue in json.loads(res.text):
             queueName = queue.get('name')
             if queueName in ConfUtil.getIgnoreQueueList():
                 continue
             messages = queue.get('messages', 0)
             doc = MonitorDao.findQueue(addr, queueName)
             if doc == None:
                 if messages > ConfUtil.getGlobalMsgTotalMax():
                     alarm = addr + ', ' + queueName + ', ' + 'msgTotal is ' + str(
                         messages) + '(' + str(
                             ConfUtil.getGlobalMsgTotalMax()) + ').'
                     for mail in ConfUtil.getGlobalMailList():
                         mailContent[mail].append(alarm)
             else:
                 try:
                     msgTotalMax = 0
                     if len(doc.get('msgTotalMax')) > 0:
                         msgTotalMax = (int)(doc.get('msgTotalMax'))
                 except Exception, e:
                     log.error(doc)
                 mailList = doc.get('mailList')
                 if messages > msgTotalMax:
                     alarm = addr + ', ' + queueName + ', ' + 'msgTotal is ' + str(
                         messages) + '(' + str(msgTotalMax) + ').'
                     for mail in mailList:
                         if mailContent.get(mail) == None:
                             mailContent[mail] = []
                         mailContent[mail.strip()].append(alarm)
Exemplo n.º 2
0
def getQueues(addr):
    queueUrl = 'http://' + addr.strip() + '/api/queues'
    res = requests.get(queueUrl, auth=(ConfUtil.getMQUsername(), ConfUtil.getMQPassword()))
    queues = []
    index = 0
    for queue in json.loads(res.text):
        queueName = queue.get('name')
        msgTotal = queue.get('messages', 0)
        dict = {}
        dict['queue'] = queueName
        dict['msgTotal'] = msgTotal
        index += 1
        dict['index'] = index
        doc = MonitorDao.findQueue(addr, queueName)
        dict['mailList'] = ''
        dict['msgTotalMax'] = ''
        if doc != None:
            dict['mailList'] = ','.join(doc.get('mailList'))
            dict['msgTotalMax'] = doc.get('msgTotalMax')
        queues.append(dict)
    return queues
Exemplo n.º 3
0
 def check(self):
     mailContent = {}
     for mail in ConfUtil.getGlobalMailList():
         mailContent[mail.strip()] = [] 
     for addr in self.__addrList:
         overviewUrl = 'http://' + addr.strip() + '/api/overview'
         try:
             res = requests.get(overviewUrl, auth=(self.__username, self.__password))
         except ConnectionError, e:
             for mail in ConfUtil.getGlobalMailList():
                 mailContent[mail].append(addr + ' is dead.')
             continue
         queueUrl = 'http://' + addr.strip() + '/api/queues'
         res = requests.get(queueUrl, auth=(self.__username, self.__password))
         for queue in json.loads(res.text):
             queueName = queue.get('name')
             if queueName in ConfUtil.getIgnoreQueueList():
                 continue
             messages = queue.get('messages', 0)
             doc = MonitorDao.findQueue(addr, queueName)
             if doc == None:
                 if messages > ConfUtil.getGlobalMsgTotalMax():
                     alarm = addr + ', ' + queueName + ', ' + 'msgTotal is ' + str(messages) + '(' + str(ConfUtil.getGlobalMsgTotalMax()) + ').'    
                     for mail in ConfUtil.getGlobalMailList():
                         mailContent[mail].append(alarm)
             else:
                 try:
                     msgTotalMax = 0
                     if len(doc.get('msgTotalMax')) > 0:
                         msgTotalMax = (int)(doc.get('msgTotalMax'))
                 except Exception, e:
                     log.error(doc)
                 mailList = doc.get('mailList')
                 if messages > msgTotalMax:
                     alarm = addr + ', ' + queueName + ', ' + 'msgTotal is ' + str(messages) + '(' + str(msgTotalMax) + ').'
                     for mail in mailList:
                         if mailContent.get(mail) == None:
                             mailContent[mail] = []
                         mailContent[mail.strip()].append(alarm)