CÓMO

Determinar el último inicio de sesión en el portal de ArcGIS Enterprise y ArcGIS Online mediante el uso de ArcGIS API for Python

Last Published: September 12, 2023

Resumen

The last login dates are helpful in determining the list of active users in ArcGIS Enterprise portal and ArcGIS Online. Administrators have the required privileges to view audit logs and remove non-active users to free up licenses for new users. The last login dates can be determined using ArcGIS API for Python.

Causa


 

Procedimiento

Complete the steps below to determine the last login date in ArcGIS Enterprise portal and ArcGIS Online using ArcGIS API for Python.

  1. Import the necessary module, including the time module.
import arcgis
import time
from arcgis.gis import GIS
    1. Make an administrator connection to ArcGIS Enterprise portal or ArcGIS Online.

    ArcGIS Enterprise portal

    gis = GIS("https://domain.esri.com/portal", username="user1", password="pass1", verify_cert=False)
    print("connected")
    

    ArcGIS Online

    gis = GIS("https://arcgis.com", username="username", password="password")
    print("connected")
    
    1. Search for the list of users in ArcGIS Enterprise portal or ArcGIS Online. Set the maximum number of users if needed.
    a_users = gis.users.search(query='', max_users=200)
    a_users
    1. Loop through the list of available users, and print the login record for ArcGIS Enterprise portal or ArcGIS Online.
    for a_user in a_users:
        if a_user. lastLogin != -1:
            last_accessed = time.localtime(a_user. lastLogin/1000)
            print(str(a_user. fullName) + " was last active on: {}/{}/{}\n".format(last_accessed[0], last_accessed[1], last_accessed[2]))
    
        else:
          print(str(a_user. fullName) + " has never logged in.\n")

    The following shows the full script:

    import arcgis
    import time
    from arcgis.gis import GIS
    
    #For Portal for ArcGIS
    gis = GIS("https://domain.esri.com/portal", username="user1", password="pass1", verify_cert=False)
    
    
    #For ArcGIS Online
    gis = GIS("https://arcgis.com", username="username", password="password")
    
    print("connected")
    
    a_users = gis.users.search(query='', max_users=200)
    a_users
    
    for a_user in a_users:
        if a_user. lastLogin != -1:
            last_accessed = time.localtime(a_user. lastLogin/1000)
            print(str(a_user. fullName) + " was last active on: {}/{}/{}\n".format(last_accessed[0], last_accessed[1], last_accessed[2]))
    
        else:
          print(str(a_user. fullName) + " has never logged in.\n")

    The image below shows the result of the above script.

    Result of the Python script.

    Id. de artículo: 000022604

    Recibir notificaciones y encontrar soluciones a problemas nuevos o comunes

    Obtenga respuestas resumidas y soluciones de vídeo de nuestro nuevo chatbot de IA.

    Descargar la aplicación de soporte de Esri

    Información relacionada

    Descubrir más sobre este tema

    Obtener ayuda de expertos en ArcGIS

    Contactar con el soporte técnico

    Descargar la aplicación de soporte de Esri

    Ir a opciones de descarga