in rules/customer-fc/aggregate-ram-role-last-login-expired-check.py [0:0]
def sls_get_logs_cnt(region_id, project, logstore, resource_id):
config = open_api_models.Config(access_key_id=AK, access_key_secret=SK)
config.endpoint = region_id + '.log.aliyuncs.com'
client = Sls20201230Client(config)
x_days = 90
to_timestamp = int(round(time.time()))
from_timestamp = to_timestamp - x_days * 24 * 60 * 60
get_logs_request = sls_20201230_models.GetLogsRequest(
from_=from_timestamp,
to=to_timestamp,
query='event.userIdentity.principalId: ' + resource_id # event.userIdentity.principalId: 389051450072xxxxxx
)
try:
runtime = util_models.RuntimeOptions()
headers = {}
try:
response = client.get_logs_with_options(project, logstore,
get_logs_request, headers, runtime)
events_cnt = len(response.body)
return events_cnt
except Exception as error:
UtilClient.assert_as_string(error.message)
except Exception as e:
logger.error('GetLogsRequest error: %s' % e)