def ws_restart_base(self): """ Places all base unit statuses into queue when websocket handler is started/restarted """ # This method is only called when websocket is operating # Cycle through all base unit statuses and place status in MPQ_WS queue for process in self.stat_base.keys(): try: MPQ_WS.put_nowait(['base', process, self.stat_base[process]]) except queue.Full: log = 'Can not place item in websocket queue, queue is full.' logger.exception(log)
def base(self, mpq_record: list): """ Places base process statuses into websocket and SNMP queues if status has changed. mpq_record[0] = process mpq_record[1] = process status :param mpq_record: list """ process = mpq_record[0] process_stat = mpq_record[1] # Only process record if process status has changed if process_stat != self.stat_base[process]: self.stat_base[process] = process_stat # Initialize base status database entry data_cdb_in = {process: self.stat_base[process]} # Update base_status document in CouchDB config database data_cdb_out, stat_cdb, http_cdb = dbase.cdb_request( cdb_cmd='upd_doc', cdb_name='config', cdb_doc='base_status', data_cdb_in=data_cdb_in, logfile=logfile) if stat_cdb == STAT_LVL['crit']: log = 'Failed to update base_status document in CouchDB config database.' logger.critical(log) # Only place into MPQs if processes/threads are functioning. try: if self.pid_websocket: MPQ_WS.put_nowait( ['base', process, self.stat_base[process]]) # Filter out SNMP-related messages, SNMP can not report on itself. if (process != 'snmp_agent') and (process != 'snmp_notify'): if self.tid_snmp_agent: self.MPQ_SNMPA2.put_nowait( [process, self.stat_base[process]]) if self.tid_snmp_notify: self.MPQ_SNMPN2.put_nowait( [process, self.stat_base[process]]) except queue.Full: log = 'Can not place item in base status queue, queue is full.' logger.exception(log)
def ws_restart_net(self): """ Places all network statuses into queue when websocket handler is started/restarted """ # This method is only called when websocket is operating # Cycle through network check values and place values into MPQ_WS try: MPQ_WS.put_nowait([ 'network', self.url_net, self.stat_net['network_interval'], self.stat_net['network_check_dtg'] ]) except queue.Full: log = 'Can not place item in websocket queue, queue is full.' logger.exception(log)
def network(self, mpq_record: list): """ Places network status into websocket and SNMP queues if status has changed. mpq_record[0] = network url checked mpq_record[1] = check interval mpq_record[2] = dtg :param mpq_record: list """ stat_change = False url = mpq_record[0] interval = mpq_record[1] check_dtg = mpq_record[2] # Only process record if key values have changed if url != self.url_net: self.url_net = url stat_change = True if interval != self.stat_net['network_interval']: self.stat_net['network_interval'] = interval stat_change = True if check_dtg != self.stat_net['network_check_dtg']: self.stat_net['network_check_dtg'] = check_dtg stat_change = True # If any key value has changed, process record if stat_change: # Initialize network check database entry data_cdb_in = { 'network_interval': self.stat_net['network_interval'], 'network_check_dtg': self.stat_net['network_check_dtg'] } # Update tasks document in CouchDB config database data_cdb_out, stat_cdb, http_cdb = dbase.cdb_request( cdb_cmd='upd_doc', cdb_name='config', cdb_doc='network', data_cdb_in=data_cdb_in, logfile=logfile) if stat_cdb == STAT_LVL['crit']: log = 'Failed to update tasks document in CouchDB config database.' logger.critical(log) # Only place into MPQ_WS if websocket handler processes is functioning. try: if self.pid_websocket: MPQ_WS.put_nowait([ 'network', self.url_net, self.stat_net['network_interval'], self.stat_net['network_check_dtg'] ]) except queue.Full: log = 'Can not place item in network queue, queue is full.' logger.exception(log)