コード例 #1
0
ファイル: video_check.py プロジェクト: ahcan/monitor
 def update_data(self, video_status, source_status):
     date_time = DateTime()
     opdate = date_time.get_now()
     child_thread_list = []
     profile = ProfileBLL()
     profile_data = {
         "video": video_status,
         "agent": self.agent,
         "ip": self.ip
     }
     self.logger.debug(
         "update profile data: video{0} - agent{1} - ip{2}".format(
             video_status, self.agent, self.ip))
     child_thread = threading.Thread(target=profile.put,
                                     args=(
                                         self.id,
                                         profile_data,
                                     ))
     child_thread.start()
     child_thread_list.append(child_thread)
     human_readable_status = self.get_human_readable_status(source_status)
     message = """%s %s (ip:%s) %s in host: %s (%s)""" % (
         self.name, self.type, self.source, human_readable_status, self.ip,
         self.agent)
     log_data = {
         "host": self.protocol + "://" + self.source,
         "tag": "status",
         "msg": message
     }
     rslog = {
         "sev": "Critical",
         "jname": self.name,
         "type": self.type,
         "res": self.source,
         "desc": human_readable_status,
         "cat": "Communication",
         "host": self.agent,
         "opdate": opdate,
         "cldate": opdate
     }
     self.logger.critical(json.dumps(rslog))
     log = LogBLL()
     child_thread = threading.Thread(target=log.post, args=(log_data, ))
     child_thread.start()
     child_thread_list.append(child_thread)
     """Update local snmp IPTV"""
     local_snmp = LocalSnmp(profile=self.source + "-" + self.type,
                            name=self.name,
                            status=2)
     child_thread = threading.Thread(target=local_snmp.set)
     child_thread.start()
     child_thread_list.append(child_thread)
     """
     Wait for update database complete
     """
     for child_thread in child_thread_list:
         child_thread.join()
     return 0
コード例 #2
0
ファイル: video_check.py プロジェクト: ahcan/monitor
 def check(self):
     if not SYSTEM["monitor"]["BLACK_SCREEN"]:
         message = "Black screen monitor is disable, check your config!"
         self.logger.warning(message)
         print message
         time.sleep(60)
         exit(0)
     try:
         profileBLL = ProfileBLL()
         data = profileBLL.get_video_check_list()
         if data["status"] == 200:
             profile_list = data["data"]
         else:
             print "Error code: " + str(data["status"])
             print data["message"]
             self.logger.error("Error code: " + str(data["status"]) + " " +
                               data["message"])
             exit(1)
         # ancestor_thread_list = []
         for profile in profile_list:
             while threading.activeCount() > profile['thread']:
                 time.sleep(1)
             check_video = VideoCheck(
                 id=profile["id"],
                 name=profile["name"],
                 type=profile["type"],
                 protocol=profile["protocol"],
                 source=profile["ip"],
                 last_status=profile["status"],
                 last_video_status=profile["video_status"],
                 agent=profile["agent"])
             t = threading.Thread(target=check_video.check_video)
             t.start()
         """
             ancestor_thread_list.append(t)
         Wait for all threads finish
         for ancestor_thread in ancestor_thread_list:
             ancestor_thread.join()
         """
         time.sleep(60)
     except Exception as e:
         self.logger.error(e)
         print "Exception: " + str(e)
         time.sleep(10)
コード例 #3
0
 def check(self):
     if not SYSTEM["monitor"]["SOURCE"]:
         message = "Black screen monitor is disable, check your config!"
         self.logger.warning(message)
         print message
         time.sleep(60)
         exit(0)
     try:
         profileBLL = ProfileBLL()
         data = profileBLL.get()
         if data["status"] == 200:
             profile_list = data["data"]
         else:
             self.logger.error(str(data["status"]) + " " + data["message"])
             print "Error code: " + str(data["status"])
             print data["message"]
             exit(1)
         # ancestor_thread_list = []
         for profile in profile_list:
             while threading.activeCount() > profile['thread']:
                 time.sleep(1)
             t = threading.Thread(target=self.check_source,
                                  args=(
                                      profile['protocol'] + '://' +
                                      profile['ip'],
                                      profile['status'],
                                      profile['id'],
                                      profile['agent'],
                                      profile['thread'],
                                      profile['name'],
                                      profile['type'],
                                  ))
             t.start()
         #     ancestor_thread_list.append(t)
         #
         # Wait for all threads finish
         #
         # for ancestor_thread in ancestor_thread_list:
         #     ancestor_thread.join()
     except Exception as e:
         self.logger.error(str(e))
         print e
     finally:
         time.sleep(20)
コード例 #4
0
 def update_data(self, ip):
     pf = ProfileBLL()
     ip = get_ip_from_ip_multicast(ip)
     data = pf.get_by_ip_multicast(ip)
     profile = None
     if data["status"] == 200:
         profile_list = data["data"]
         if len(profile_list):
             profile = profile_list[0]
     else:
         self.logger.error(str(data["status"]) + " " + data["message"])
         time.sleep(5)
         data = pf.get_by_ip_multicast(ip)
         if data["status"] == 200:
             profile_list = data["data"]
             if len(profile_list):
                 profile = profile_list[0]
         else:
             self.logger.error(str(data["status"]) + " " + data["message"])
     return profile
コード例 #5
0
ファイル: last_check.py プロジェクト: hhthuongbtr/monitor
    def check_source(self, source, last_status, id, agent, name, type):
        """
        Get status of profile, if stastus not change then update check equal 1.      
        Ffmpeg: Use Ffprobe to check stastus profile (source) and return flag 
        0 is down
        1 is up
        2 is video error
        3 is audio eror 
        """
        ffmpeg = Ffmpeg()
        check = ffmpeg.check_source(source)
        # print "%s : %s"%(check, last_status)
        self.logger.debug("Curent :%s <> Last: %s, %s %s %s"%(check, last_status, source, name, type))
        if check != last_status:
            date_time = DateTime()
            opdate = date_time.get_now()
            time.sleep(SYSTEM["BREAK_TIME"])
            self.logger.debug("Recheck : %s %s %s"%(source, name, type))
            recheck = ffmpeg.check_source(source)
            if recheck == check:
                status = {0: "DOWN       ", 1: "UP         ", 2: "VIDEO ERROR", 3: "AUDIO ERROR"} [check]
                """
                Update status and write log
                """
                child_thread_list = []
                profile = ProfileBLL()
                profile_data = {"status": check, "agent": agent, "ip": SYSTEM["HOST"]}
                child_thread = threading.Thread(target=profile.put, args=(id, profile_data,))
                child_thread.start()
                child_thread_list.append(child_thread)
                """Append log"""
                channel = """%s %s"""%(name, type)
                while len(channel) < 22:
                    channel += " "
                while len(source) < 27:
                    source += " "
                ip_config = SYSTEM["HOST"]
                while len(ip_config) < 16:
                    ip_config += " "
                message = """%s (ip:%s) %s in host: %s (%s)""" % (channel, source, status, ip_config, agent)
                cldate = date_time.get_now()
                rslog = {
                         "sev"        : "Critical",
                         "jname"      : name,
                         "type"       : type,
                         "res"        : source,
                         "desc"       : status,
                         "cat"        : "Communication",
                         "host"       : agent,
                         "opdate"     : opdate,
                         "cldate"     : cldate
                     }
                self.logger.critical(json.dumps(rslog))
                log_data = {"host": source, "tag": "status", "msg": message}
                log = LogBLL()
                child_thread = threading.Thread(target=log.post, args=(log_data,))
                child_thread.start()
                child_thread_list.append(child_thread)
                """Update local snmp IPTV"""
                if "origin" or "4500" in agent:
                    self.logger.debug("%s is core probe"%(agent))
                    time.sleep(2)
                    snmp = Snmp()
                    child_thread = threading.Thread(target=snmp.set)
                    child_thread.start()
                    child_thread_list.append(child_thread)

                """
                Wait for update database complete
                """
                for child_thread in child_thread_list:
                    child_thread.join()
                return 1
        return 0