def init_and_clear_db(): # Initialize the database schema. init_db() # Remove all users and pulse users created by the web app. for pulse_user in PulseUser.query.all(): try: pulse_management.delete_user(pulse_user.username) except PulseManagementException: pass # Clear the database of old data. for queue in Queue.query.all(): db_session.delete(queue) for pulse_user in PulseUser.query.all(): db_session.delete(pulse_user) for user in User.query.all(): db_session.delete(user) db_session.commit() logger.info('Finished initializing database.')
def init_and_clear_db(): # Initialize the database schema. init_db() # Remove all users and pulse users created by the web app. for rabbitmq_account in RabbitMQAccount.query.all(): try: pulse_management.delete_user(rabbitmq_account.username) except pulse_management.PulseManagementException: pass # Clear the database of old data. for queue in Queue.query.all(): db_session.delete(queue) for binding in Binding.query.all(): db_session.delete(binding) for rabbitmq_account in RabbitMQAccount.query.all(): db_session.delete(rabbitmq_account) for user in User.query.all(): db_session.delete(user) db_session.commit() logger.info('Finished initializing database.')
self.notify_connection_error() self._increase_interval() except KeyboardInterrupt: break except Exception: self.notify_unknown_error() self._increase_interval() mozdef.log( mozdef.DEBUG, mozdef.OTHER, 'Sleeping for {} seconds'.format(self._polling_interval), ) time.sleep(self._polling_interval) def _queue_details_dict(self, queue): return { 'queuename': queue.name, 'queuesize': queue.size, 'warningthreshold': self.warn_queue_size, 'deletionthreshold': self.del_queue_size, } if __name__ == '__main__': # Initialize the database if necessary. init_db() pulse_guardian = PulseGuardian(emails=config.email_enabled) pulse_guardian.guard()
try: queues = pulse_management.queues() if queues: self.monitor_queues(queues) self.clear_deleted_queues(queues) if (self._connection_error_notified or self._unknown_error_notified): self._reset_notification_error_params() except (requests.ConnectionError, socket.error): self.notify_connection_error() self._increase_interval() except KeyboardInterrupt: break except Exception: self.notify_unknown_error() self._increase_interval() time.sleep(self._polling_interval) if __name__ == '__main__': # Add StreamHandler for development purposes logging.getLogger().addHandler(logging.StreamHandler()) # Initialize the database if necessary. init_db() pulse_guardian = PulseGuardian() pulse_guardian.guard()