Exemplo n.º 1
0
    def __iter__(self):

        self.connectdb = command_ready()
        try:
            self.last_uids = self.connectdb.select_raw_mail_uid('mail')
        except:
            self.last_uids = []

#        print (type(self.last_uids), self.last_uids)

        try:
            self.pop3 = POP3MailServer(POP3['server'], POP3['user'],
                                       POP3['password'])
            self.ready = True
        except:
            self.ready = False

        print(self.ready)
        if self.ready == True and len(self.last_uids) != 0:
            for i in range(len(self.last_uids)):
                try:
                    self.mail_location = self.pop3.pegging_count(
                        self.last_uids[i][0])
                    print(self.mail_location)
                    break
                except:
                    pass
        else:
            self.mail_location = 0

        print("19191991191919199191 %s, %s" %
              (self.mail_location, self.pop3.total()))
        #        time.sleep(30)
        return self
Exemplo n.º 2
0
def MailProcessor():
    req_data = json_initialization(appid, appkey)
    json = req_data.json

    connectdb = command_ready()
    try:
        last_uids = connectdb.select_raw_mail_uid('mail')
    except:
        last_uids = []

    if len(last_uids) != 0:
        mail_data_filter = []
        universalID = last_uids[0][-1]
        json['id'] = universalID
        req = eval(requests.post(url, json=json).text)
#        print (req)
        if int(req['code']) == 200:
            mail_data = req['data'] 
            return mail_data
    
    else:
        req = eval(requests.post(url, json=json).text)
        if int(req['code']) == 200:
            mail_data = req['data']
          #  for i in range(len(mail_data)):
          #      if "customer_name_测试" in str(mail_data[i]['body'].split(':')):
          #          print ("\n", mail_data[i])

            return mail_data       
Exemplo n.º 3
0
    def _process(self):
        self.connectdb = command_ready()
        req_pending_data = self.connectdb.select_union_raw_custsystem("6")

        datas = req_pending_data

        return datas
Exemplo n.º 4
0
    def _process(self, mail):

        try:
            customer_name, monitor_name = mail_data_deal_forCustSystemCode(
                mail)
            print(customer_name, monitor_name)
            self.connectdb = command_ready()
            customer_system_code, customer_code, monitor_code, active_flg = self.connectdb.select_cust_systemCode_by_name(
                customer_name, monitor_name)

        except:
            customer_system_code, customer_code, monitor_code, active_flg = None, None, None, 0

        return customer_system_code, customer_code, monitor_code, active_flg
Exemplo n.º 5
0
    def start(self, period=30):
        while True:
            keys, datas, receive_info_idss = self._process()
            for i in range(len(datas)):            
                #print ("qqqqqqqqqqqqqqqqqq", datas[i])
                datas[i]["alert_time"] = self._time_ex(str(datas[i]["alert_time"]))
                #print (datas[i])
                self.connectdb = command_ready()
                self.connectdb.insert_analysis_data(datas[i],receive_info_idss[i])   
                self.connectdb.operation_close() 
                logging.info(datas[i])
                analysis_if_success_todb(receive_info_idss[i], 1)      

            time.sleep(period)
Exemplo n.º 6
0
    def _process(self):
        self.connectdb = command_ready()
        req_pending_data = self.connectdb.select_raw_alarm(Tables['receive_table'], 0)

        self.connectdb.operation_close()
        
        processed_data, receive_info_ids = analysis_format_data(req_pending_data)
            

        deal_data = [] 
        receive_info_idss = []
        str_ = ""       

        for num in range(len(processed_data)):
#            print ("11111111111111", processed_data[num])

            if Mail_newField['customer_code'] and Mail_newField['monitor_code'] not in processed_data[num][0]:
                connectdb = command_ready()
                customer_system_code, customer_code, monitor_code, active_flg = connectdb.select_cust_systemCode_by_name(processed_data[num][0][Mail_newField['customer_name']],processed_data[num][0][Mail_newField['monitor_name']])        
                print (customer_system_code, customer_code, monitor_code, active_flg)
                processed_data[num][0].update({Mail_newField['customer_code']: customer_code})
                processed_data[num][0].update({Mail_newField['monitor_code']: monitor_code})

            _str = processed_data[num][1]
            for i in range(len(_str)):
                str_ += _str[i]
#len(processed_data[num][1]) != 0
            if len(processed_data[num]) == 2 and len(str_) != 0:
                analysis_if_success_todb(receive_info_ids[num], 2)  #2表示解析失败
                logging.warn(processed_data[num][0])
            else:
                deal_data.append(processed_data[num])
                receive_info_idss.append(receive_info_ids[num])

        keys, filter_data_in_field, filter_data_not_in_field = datas_key_compare_if_exists(deal_data)
        return keys, filter_data_in_field, receive_info_idss
Exemplo n.º 7
0
    def start(self, period=30):
        while True:
            mail_data = MailProcessor()
            for mail in mail_data[::-1]:
                customer_system_code, customer_code, monitor_code, active_flg = self._process(
                    mail)
                ##                print (customer_system_code, mail)
                ##                print (customer_system_code, active_flg)
                #
                if int(active_flg) == 1:
                    #
                    self.connectdb = command_ready()
                    self.connectdb.insert_raw_mail_data(
                        customer_system_code, mail, 'mail', 1)
#                else:
#
#
#
            time.sleep(period)
Exemplo n.º 8
0
    def start(self, period=30):
        while True:

            for mail in self.mailProcessor:
                print(mail)
                customer_system_code, customer_code, monitor_code, active_flg = self._process(
                    mail)
                #                print (customer_system_code, mail)
                #                print (customer_system_code, active_flg)

                if int(active_flg) == 1:

                    self.connectdb = command_ready()
                    self.connectdb.insert_raw_mail_data(
                        customer_system_code, mail, 'mail', 1)


#                else:

            time.sleep(period)
Exemplo n.º 9
0
    def _ifrule(self, data_dict):
        connectdb = command_ready()

        customer_system_code, active_flg = connectdb.select_cust_systemCode(
            data_dict["customerCode"], data_dict["monitorCode"],
            data_dict["monitorVersion"])

        rule_data = select_CustCorrespondingRrule(customer_system_code)
        rule_data_default = select_DefaultCorrespondingRrule("default")
        ###############################rule_data 和 matched 的过滤中 怎么通过 rule_data 和 data_dict的规则对应提炼出新的规则   以便于规则递增加入
        ########
        #以 $$ 标记那些地方需要递增规则添加
        #########
        matched = self._deal_rule(rule_data, data_dict)
        matched_default = self._deal_rule(rule_data_default, data_dict)

        if len(rule_data) == 0:
            if (matched == None or matched == ""
                ) and matched_default != None and matched_default != "":
                insert_CustCorrespondingRule(matched_default,
                                             customer_system_code)
                self._ifmatched(data_dict, matched_default,
                                customer_system_code)

                return matched_default

            elif matched == None or matched == "" and matched_default == "" or matched_default == None:
                insert_CustCorrespondingRule("", customer_system_code)
                self._ifmatched(data_dict, matched, customer_system_code)
                return ""

        else:
            if matched != None and matched != "" and (matched_default == "" or
                                                      matched_default == None):
                self._ifmatched(data_dict, matched, customer_system_code)
                return matched

            elif matched != None and matched != "" and matched_default != None and matched_default != "":
                filter_, same_intersection = self._ifMatchedFilterRule(
                    matched, matched_default)

                filter_matched = ";".join(
                    list(set((rule_data[0][1] + ";" + filter_).split(";"))))
                update_CustCorrespondingRule(filter_matched,
                                             customer_system_code)
                self._ifmatched(data_dict, matched, customer_system_code,
                                str(same_intersection))

                return filter_

#############该处是 客户规则中没有被匹配上的规则,为空,在默认规则中匹配上了,这一点导致默认匹配上的规则直接向该客户的规则递增添加了.
            elif matched == "" and matched_default != None and matched_default != "":
                matched = ""
                if len(rule_data[0][1]) == 0:
                    matched_ = ";".join(list(set(
                        (matched_default).split(";"))))
                else:
                    matched_ = ";".join(
                        list(
                            set((rule_data[0][1] + ";" +
                                 matched_default).split(";"))))
                update_CustCorrespondingRule(matched_, customer_system_code)
                self._ifmatched(data_dict, matched_default,
                                customer_system_code)
                return matched_default

            elif matched == "" and (matched_default == None
                                    or matched_default == ""):
                self._ifmatched(data_dict, matched_default,
                                customer_system_code)
                return ""
Exemplo n.º 10
0
def update_anlysis_before_deal_status(info_id, deal_status):
    connectdb = command_ready()
    connectdb.update_anlysis_before_deal_status(info_id, deal_status)
Exemplo n.º 11
0
def update_matched_corresponding_rule(info_id, deal_status):
    connectdb = command_ready()
    connectdb.update_matched_corresponding_rule(info_id, deal_status)
Exemplo n.º 12
0
def insert_MatchedCorrespondingRule(data):
    connectdb = command_ready()
    matched_record = connectdb.insert_matched_corresponding_rule(data)
    return matched_record
Exemplo n.º 13
0
def insert_CustCorrespondingRule(matched_data, customer_system_code):
    connectdb = command_ready()
    insert_matched = connectdb.insert_cust_corresponding_rule(
        matched_data, customer_system_code)
    return insert_matched
Exemplo n.º 14
0
def update_customer(cust_system_code, customer_code, monitor_code,
                    monitor_version, active_flg):
    connectdb = command_ready()
    connectdb.update_customer_system(cust_system_code, customer_code,
                                     monitor_code, monitor_version, active_flg)
Exemplo n.º 15
0
def add_customer(cust_system_code, customer_code, customer_name, monitor_code,
                 monitor_name, monitor_version, active_flg):
    connectdb = command_ready()
    connectdb.insert_customer_system(cust_system_code, customer_code,
                                     customer_name, monitor_code, monitor_name,
                                     monitor_version, active_flg)
Exemplo n.º 16
0
def create_table():
    connectdb = command_ready()
    connectdb.create_raw_table()
    connectdb.create_rule_table()
    connectdb.create_customer_system_table()
    connectdb.operation_close()
Exemplo n.º 17
0
def create_rule_table():
    connectdb = command_ready()
    connectdb.create_rule_table()
    connectdb.operation_close()
Exemplo n.º 18
0
def update_CustCorrespondingRule(matched_data, customer_system_code):
    connectdb = command_ready()
    update_match = connectdb.update_cust_corresponding_rule(
        matched_data, customer_system_code)
    return update_match
Exemplo n.º 19
0
def analysis_if_success_todb(receive_info_id, analysis_flg):
    connectdb = command_ready()
    connectdb.update_raw_alarm(receive_info_id, analysis_flg)
Exemplo n.º 20
0
def select_CustCorrespondingRrule(customer_system_code):
    connectdb = command_ready()
    rule_data = connectdb.select_cust_corresponding_rule(customer_system_code)
    return rule_data
Exemplo n.º 21
0
def create_format_table():
    connectdb = command_ready()
    connectdb.create_analysis_table()
    connectdb.operation_close()