def get_events(self):
        '''
        Method to collect events from Metis API
        - Gets access token and stream position from Azure Vault
        - Requests events (retries if error HTTP code)
        - Collect events lists from Metis API, returns full list of events
        '''
        
        events = []
        retry_count = 0
        more_events = True
        
        if self.is_valid == "NO" or int(self.retry_counter) >= 10:
            logging.info("Please check API key, Auth API responds with Invalid Client error after 10 retries")
            return events

        if not self.access_token:
            self.get_oauth()

        if self.access_token:
            # Added cycle count to avoid long data polling
            cycle_count = 0
            while more_events and retry_count < 10 and cycle_count < 10 :
                logging.info("Fetching Events from Position {}".format(self.stream_position))
                try:
                    response = requests.get(self.api_domain + "/events?eventType=DEVICE,THREAT,AUDIT",
                                            headers=self.header(self.access_token),
                                            params={"streamPosition": self.stream_position})
                    if response.status_code == 400 and response.json()['errorCode'] in self.stale_token_errors:
                        self.refresh_oauth()
                        continue
                    elif response.status_code != requests.codes.ok:
                        logging.info("Received error code {}, trying again to get events".format(response.status_code))
                        retry_count = retry_count + 1
                        continue
                except requests.exceptions.ProxyError as e:
                    logging.error("Cannot connect to proxy. Remote end closed connection without response")                
                except requests.exceptions.RequestException as e:
                    logging.error(e)                
                    
                cycle_count = cycle_count + 1
                events = events + response.json()['events']
                self.stream_position = response.json()['streamPosition']
                
                #update stream position in Azure Vault
                self.az_kv.set_secret("StreamPosition", self.stream_position)

                more_events = response.json()['moreEvents']
                logging.info("Fetched Event Count {}".format(len(events)))
                logging.info("More Events to Fetch : {}".format(more_events))

            if retry_count >= 10:
                logging.error("Too many failed attempts to retrieve events, shutting down.")
                sys.exit(2)


        return events

        Method to collect events from Metis API
        - Gets access token and stream position from Azure Vault
        - Requests events (retries if error HTTP code)
        - Collect events lists from Metis API, returns full list of events
        
Solutions/Lookout/Data Connectors/LookoutAPISentinelConnector/mes_request.py