class_docstr: An app that collects events from the ActionTrail feature of Aliyun.
  
  Results are paginated, with a NextToken field provided that is used in subsequent queries.
  The result of a successful api call is json whose outermost schema is
  
  {
    "EndTime": <end of the time range of events>,
    "NextToken": <the token to use to request the next page of data>,
    "RequestId": <the ID of the request>,
    "StartTime": <start of the time range of events>,
    "Events": [entries],
  }
  
  If there are no more events in the queried range, the 'NextToken' element is not present.
  
  Resource:
      https://www.alibabacloud.com/help/doc-detail/28849.htm
docstr: Fetch ActionTrail events and return a list of events
  
  Example response from do_action_with_exception method
  
  {
    'EndTime': '2019-08-22T04:41:32Z',
    'NextToken': '2',
    'RequestId': '562D9C08-E766-4038-B49F-B0D2BE1980FE',
    'StartTime': '2019-08-01T04:31:52Z',
    'Events': [{
      'eventId': '60.152_1566447558068_1247',
      'eventVersion': '1',
      'acsRegion': 'cn-hangzhou',
      'additionalEventData': {
        'mfaChecked': 'true',
        'callbackUrl': 'https://home.console.aliyun.com/'
      },
      'eventType': 'ConsoleSignin',
      'errorMessage': 'success',
      'eventTime': '2019-08-22T04:19:18Z',
      'eventName': 'ConsoleSignin',
      'userIdentity': {
        'userName': 'dead_joke',
        'type': 'ram-user',
        'principalId': '222222222222222222',
        'accountId': '1111111111111111'
      },
      'eventSource': 'signin.aliyun.com',
      'requestId': '60.152_1566447558068_1247',
      'userAgent': 'some browser version',
      'sourceIpAddress': '1.1.1.1',
      'serviceName': 'AasSub'
    }, {
      'eventId': '029B39F0-5E23-4931-B4C9-BA72C7261ADF',
      ...
      'eventTime': '2019-08-21T22:26:09Z',
      ...
    }]
  }
docstr_tok: ["Fetch","ActionTrail","events","and","return","a","list","of","events","Example","response","from","do_action_with_exception","method","{","'EndTime","'",":","'2019-08-22T04:41:32Z","'",",","'NextToken","'",":","'","2","'",",","'RequestId","'",":","'562D9C08-E766-4038-B49F-B0D2BE1980FE","'",",","'StartTime","'",":","'2019-08-01T04:31:52Z","'",",","'Events","'",":","[","{","'eventId","'",":","'60.152_1566447558068_1247","'",",","'eventVersion","'",":","'","1","'",",","'acsRegion","'",":","'cn-hangzhou","'",",","'additionalEventData","'",":","{","'mfaChecked","'",":","'true","'",",","'callbackUrl","'",":","'https",":","\/\/home.console.aliyun.com\/'","}",",","'eventType","'",":","'ConsoleSignin","'",",","'errorMessage","'",":","'success","'",",","'eventTime","'",":","'2019-08-22T04:19:18Z","'",",","'eventName","'",":","'ConsoleSignin","'",",","'userIdentity","'",":","{","'userName","'",":","'dead_joke","'",",","'type","'",":","'ram-user","'",",","'principalId","'",":","'222222222222222222","'",",","'accountId","'",":","'1111111111111111'","}",",","'eventSource","'",":","'signin.aliyun.com","'",",","'requestId","'",":","'60.152_1566447558068_1247","'",",","'userAgent","'",":","'some","browser","version","'",",","'sourceIpAddress","'",":","'","1.1.1.1","'",",","'serviceName","'",":","'AasSub'","}",",","{","'eventId","'",":","'029B39F0-5E23-4931-B4C9-BA72C7261ADF","'",",","...","'eventTime","'",":","'2019-08-21T22:26:09Z","'",",","...","}","]","}"]
code: def _gather_logs(self):
      """Fetch ActionTrail events and return a list of events
  
      Example response from do_action_with_exception method
  
      {
        'EndTime': '2019-08-22T04:41:32Z',
        'NextToken': '2',
        'RequestId': '562D9C08-E766-4038-B49F-B0D2BE1980FE',
        'StartTime': '2019-08-01T04:31:52Z',
        'Events': [{
          'eventId': '60.152_1566447558068_1247',
          'eventVersion': '1',
          'acsRegion': 'cn-hangzhou',
          'additionalEventData': {
            'mfaChecked': 'true',
            'callbackUrl': 'https://home.console.aliyun.com/'
          },
          'eventType': 'ConsoleSignin',
          'errorMessage': 'success',
          'eventTime': '2019-08-22T04:19:18Z',
          'eventName': 'ConsoleSignin',
          'userIdentity': {
            'userName': 'dead_joke',
            'type': 'ram-user',
            'principalId': '222222222222222222',
            'accountId': '1111111111111111'
          },
          'eventSource': 'signin.aliyun.com',
          'requestId': '60.152_1566447558068_1247',
          'userAgent': 'some browser version',
          'sourceIpAddress': '1.1.1.1',
          'serviceName': 'AasSub'
        }, {
          'eventId': '029B39F0-5E23-4931-B4C9-BA72C7261ADF',
          ...
          'eventTime': '2019-08-21T22:26:09Z',
          ...
        }]
      }
      """
      try:
          response = self.client.do_action_with_exception(self.request)
          json_response = json.loads(response)
  
          # Note: ActionTrail API return ActionTrail events in sorted order, and
          # it is latest events first. There still has a small chance that it may not get
          # all the logs when there are still more logs to pull when lambda function
          # timeout reached, and remaining logs will be lost because the last_timestamp
          # is updated to "EndTime" during the first lambda function call.
          #
          # To lower the data loss possibility, suggest to have longer timeout for lambda
          # function (aliyun app) and set app schedule more frequently, e.g. every 10 mins
          self._last_timestamp = json_response["EndTime"]
          if "NextToken" in json_response:
              self._more_to_poll = True
              self.request.set_NextToken(json_response["NextToken"])
          else:
              self._more_to_poll = False
          return json_response["Events"]
  
      except (ServerException, ClientException) as e:
          LOGGER.exception("%s error occurred", e.get_error_type())
          raise
  
file_path: streamalert/streamalert/apps/_apps/aliyun.py
imports: from datetime import datetime
  import json
  import re
  from aliyunsdkcore.client import AcsClient
  from aliyunsdkcore.acs_exception.exceptions import ServerException, ClientException
  from aliyunsdkactiontrail.request.v20171204 import LookupEventsRequest
  from .None import AppIntegration, StreamAlertApp, get_logger
label_desc: Use image node_id 5 for calling the AliyunApp obj's underlying member method code with example usage: obj._gather_logs() and returns: json_response