def get_clients(self, endpoint): """ Get Clients for an endpoint :param endpoint: endpoint ip :type endpoint: str """ with session_scope() as session: return self._repository.connected_state.get_clients( session, endpoint)
def get_connected_state(self, endpoint=None): """ Get connected state for an endpoint if specified :param endpoint: endpoint ip :type endpoint: str """ with session_scope() as session: filters = {} if endpoint: filters['endpoint'] = endpoint return self._repository.connected_state.get_all(session, **filters)
def delete_connected_state(self, endpoint=None): """ Delete connected state for an endpoint :param endpoint: endpoint ip :type endpoint: str """ with session_scope() as session: if endpoint: self._repository.connected_state.delete(session, endpoint=endpoint) else: self._repository.connected_state.delete_all(session) session.commit()
def update_connected_state(self, endpoint, servers=None, clients=None): """ Update connected state for an endpoint :param endpoint: endpoint ip :type endpoint: str :param servers: list of (protocol, port) tuple :type servers: list :param clients: list of clients :type clients: list """ with session_scope() as session: self._repository.connected_state.update(session, endpoint, servers=servers, clients=clients)
def get_failures(self, start_time=None, end_time=None, destination=None, port=None): if not start_time: start_time = time.time() - 300 if not end_time: end_time = time.time() filters = {'success': False} if port: filters['port'] = port if destination: filters['dst'] = destination with session_scope() as session: return self._repository.record.get_records(session, start_time, end_time, **filters)
def get_success_count(self, start_time=None, end_time=None, destination=None, port=None): if not start_time: start_time = time.time() - 300 filters = {'success': True} if port: filters['port'] = port if destination: filters['dst'] = destination if not end_time: end_time = time.time() with session_scope() as session: return self._repository.record.get_record_count( session, start_time, end_time, **filters)
def record_traffic(self, record): with session_scope() as _session: self._repositery.create_record(_session, **record.as_dict())