X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b53513423ab948804425424278ac554870864997..d5c0acee9775de737003dff7ea165a155990fb66:/tools/user-activity/arvados_user_activity/main.py diff --git a/tools/user-activity/arvados_user_activity/main.py b/tools/user-activity/arvados_user_activity/main.py index 26a4f28067..ded96c3121 100755 --- a/tools/user-activity/arvados_user_activity/main.py +++ b/tools/user-activity/arvados_user_activity/main.py @@ -95,20 +95,20 @@ def getuserinfocsv(arv, uuid): collectionNameCache = {} def getCollectionName(arv, uuid, pdh): lookupField = uuid - filters = [["uuid","=",uuid]] + filters = [["uuid", "=", uuid]] cached = uuid in collectionNameCache # look up by uuid if it is available, fall back to look up by pdh - if len(uuid) != 27: + if uuid is None or len(uuid) != 27: # Look up by pdh. Note that this can be misleading; the download could # have happened from a collection with the same pdh but different name. # We arbitrarily pick the oldest collection with the pdh to lookup the # name, if the uuid for the request is not known. lookupField = pdh - filters = [["portable_data_hash","=",pdh]] + filters = [["portable_data_hash", "=", pdh]] cached = pdh in collectionNameCache if not cached: - u = arv.collections().list(filters=filters,order="created_at",limit=1).execute().get("items") + u = arv.collections().list(filters=filters, order="created_at", limit=1).execute().get("items") if len(u) < 1: return "(deleted)" collectionNameCache[lookupField] = u[0]["name"] @@ -169,17 +169,12 @@ def main(arguments=None): users[owner].append([loguuid, event_at,"Updated project %s" % (getname(e["properties"]["new_attributes"]))]) elif e["event_type"] in ("create", "update") and e["object_uuid"][6:11] == "gj3su": - since_last = None - if len(users[owner]) > 0 and users[owner][-1][-1].endswith("activity"): - sp = users[owner][-1][-1].split(" ") - start = users[owner][-1][1] - since_last = ciso8601.parse_datetime(event_at) - ciso8601.parse_datetime(sp[1]+" "+sp[2]) - span = ciso8601.parse_datetime(event_at) - ciso8601.parse_datetime(start) - - if since_last is not None and since_last < datetime.timedelta(minutes=61): - users[owner][-1] = [loguuid, start,"to %s (%02d:%02d) Account activity" % (event_at, span.days*24 + int(span.seconds/3600), int((span.seconds % 3600)/60))] - else: - users[owner].append([loguuid, event_at,"to %s (0:00) Account activity" % (event_at)]) + # Don't log token activity, it is too noisy (bug #19179) + pass + + # We want to report when a user goes through the login + # process, but controller doesn't do that yet, so revisit + # this when #19388 is done. elif e["event_type"] == "create" and e["object_uuid"][6:11] == "o0j2j": if e["properties"]["new_attributes"]["link_class"] == "tag": @@ -213,20 +208,19 @@ def main(arguments=None): users[owner].append([loguuid, event_at, "Deleted collection %s" % (getname(e["properties"]["old_attributes"]))]) elif e["event_type"] == "file_download": - users.setdefault(e["object_uuid"], []) - users[e["object_uuid"]].append([loguuid, event_at, "Downloaded file \"%s\" from \"%s\" (%s) (%s)" % ( - e["properties"].get("collection_file_path") or e["properties"].get("reqPath"), - getCollectionName(arv, e["properties"].get("collection_uuid"), e["properties"].get("portable_data_hash")), - e["properties"].get("collection_uuid"), - e["properties"].get("portable_data_hash"))]) - + users.setdefault(e["object_uuid"], []) + users[e["object_uuid"]].append([loguuid, event_at, "Downloaded file \"%s\" from \"%s\" (%s) (%s)" % ( + e["properties"].get("collection_file_path") or e["properties"].get("reqPath"), + getCollectionName(arv, e["properties"].get("collection_uuid"), e["properties"].get("portable_data_hash")), + e["properties"].get("collection_uuid"), + e["properties"].get("portable_data_hash"))]) elif e["event_type"] == "file_upload": - users.setdefault(e["object_uuid"], []) - users[e["object_uuid"]].append([loguuid, event_at, "Uploaded file \"%s\" to \"%s\" (%s)" % ( - e["properties"].get("collection_file_path") or e["properties"].get("reqPath"), - getCollectionName(arv, e["properties"].get("collection_uuid"), e["properties"].get("portable_data_hash")), - e["properties"].get("collection_uuid"))]) + users.setdefault(e["object_uuid"], []) + users[e["object_uuid"]].append([loguuid, event_at, "Uploaded file \"%s\" to \"%s\" (%s)" % ( + e["properties"].get("collection_file_path") or e["properties"].get("reqPath"), + getCollectionName(arv, e["properties"].get("collection_uuid"), e["properties"].get("portable_data_hash")), + e["properties"].get("collection_uuid"))]) else: users[owner].append([loguuid, event_at, "%s %s %s" % (e["event_type"], e["object_kind"], e["object_uuid"])]) @@ -235,8 +229,14 @@ def main(arguments=None): csvwriter = csv.writer(sys.stdout, dialect='unix') for k,v in users.items(): + # Skip system user if k is None or k.endswith("-tpzed-000000000000000"): continue + + # Skip users with no activity to report + if not v: + continue + if not args.csv: print(getuserinfo(arv, k)) for ev in v: