示例#1
0
def clear():
    """
    Produces timed status reports
    """
    # Clear queues at most every 24 hours to prevent filling up.
    # There is no better way to clear a multiprocessing queue other than run a loop.
    log = 'Attempting to clear activity and status queues.'
    logger.debug(log)
    MPQ_ACT.put_nowait([datetime.now().isoformat(' '), 'DEBUG', log])

    while not MPQ_STAT.empty():
        MPQ_STAT.get()
        time.sleep(0.001)

    while not MPQ_ACT.empty():
        MPQ_ACT.get()
        time.sleep(0.001)

    log = 'Activity and status queues cleared.'
    logger.info(log)
    MPQ_ACT.put_nowait([datetime.now().isoformat(' '), 'INFO', log])
示例#2
0
    def stat_listener(self):
        """
        Processes all heartbeat messages prior to pushing into other status queues.

        mpq_record[0][0] = type
        mpq_record[0][1] = data
        """
        # Do not start loop if class initialization did not cleaning execute
        # Do not continue loop if any heartbeat function did not cleanly execute
        while not self.stat_list:

            # All JanusESS status information enters this point
            if not MPQ_STAT.empty():
                mpq_record = MPQ_STAT.get()

                # This status catches changes in heartbeat log levels and implements
                # inside multiprocessing process
                if mpq_record[0] == 'log_level':
                    if mpq_record[1] == 'DEBUG':
                        logger.setLevel(logging.DEBUG)
                    elif mpq_record[1] == 'INFO':
                        logger.setLevel(logging.INFO)
                    elif mpq_record[1] == 'ERROR':
                        logger.setLevel(logging.ERROR)
                    elif mpq_record[1] == 'WARNING':
                        logger.setLevel(logging.WARNING)
                    elif mpq_record[1] == 'CRITICAL':
                        logger.setLevel(logging.CRITICAL)

                # This heartbeat status tracks if websocket handler process is functioning.
                # The websocket handler is only called when user loads/reloads a webpage.
                # If websocket handler is functioning, then statuses are placed in MPQ_WS.
                elif mpq_record[0] == 'websocket':
                    if mpq_record[1] != self.pid_websocket:
                        self.pid_websocket = mpq_record[1]

                        # Since activity listener is multiprocess, must pass pid via queue
                        MPQ_ACT_CMD.put_nowait([
                            'websocket',
                            self.pid_websocket,
                        ])

                        if self.pid_websocket:
                            self.ws_restart_base()
                            self.ws_restart_net()
                            self.ws_restart_ch()
                            self.ws_restart_mod()

                # This heartbeat status tracks if SNMP agent thread is functioning.
                # If SNMP agent is functioning, then statuses are placed in SNMP_AGENT_MPQ.
                elif mpq_record[0] == 'snmp_agent':
                    if mpq_record[1] != self.tid_snmp_agent:
                        self.tid_snmp_agent = mpq_record[1]
                        if self.tid_snmp_agent:
                            self.snmp_agent_restart_base()
                            self.snmp_agent_restart_ch()
                            self.snmp_agent_restart_mod()

                # This heartbeat status tracks if SNMP notification dispatcher thread
                # is functioning.  If SNMP notification dispatcher is functioning,
                # then statuses are placed in SNMP_NOTIFY_MPQ.
                elif mpq_record[0] == 'snmp_notify':
                    if mpq_record[1] != self.tid_snmp_notify:
                        self.tid_snmp_notify = mpq_record[1]

                # All base unit process statuses are pushed to base() method
                # for processing
                elif mpq_record[0] == 'base':
                    self.base(mpq_record[1])
                    log = 'Heartbeat base status record: {0}.'.format(
                        mpq_record[1])
                    logger.debug(log)

                # All network check statuses are pushed to network() method
                # for processing
                elif mpq_record[0] == 'network':
                    self.network(mpq_record[1])
                    log = 'Heartbeat network status record: {0}.'.format(
                        mpq_record[1])
                    logger.debug(log)

                # All interface lane statuses are pushed to lane() method
                # for processing
                elif mpq_record[0] == 'lane':
                    print('HEARTBEAT LANE: {0}'.format(mpq_record[1]))
                    self.lane(mpq_record[1])
                    log = 'Heartbeat lane status record: {0}.'.format(
                        mpq_record[1])
                    logger.debug(log)

                # All module statuses are pushed to module() method
                # for processing
                elif mpq_record[0] == 'module':
                    self.module(mpq_record[1])
                    log = 'Heartbeat module status record: {0}.'.format(
                        mpq_record[1])
                    logger.debug(log)

                # All module sensor polling data are pushed to poll() method
                # for processing
                elif mpq_record[0] == 'poll':
                    # print('HEARTBEAT POLLING VALUE: {0}'.format(mpq_record[1]))
                    self.poll(mpq_record[1])
                    log = 'Heartbeat polling value record: {0}.'.format(
                        mpq_record[1])
                    logger.debug(log)

            time.sleep(0.02)