1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-29 20:14:19 +00:00

Merge pull request #6521 from haiwen/event_msg_to_json

event msg to json
This commit is contained in:
JoinTyang 2024-08-19 09:58:45 +08:00 committed by GitHub
commit ae5c17b4bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 60 additions and 24 deletions

View File

@ -328,8 +328,9 @@ class ReposView(APIView):
utc_dt = datetime.datetime.utcnow() utc_dt = datetime.datetime.utcnow()
timestamp = utc_dt.strftime('%Y-%m-%d %H:%M:%S') timestamp = utc_dt.strftime('%Y-%m-%d %H:%M:%S')
org_id = request.user.org.org_id if is_org_context(request) else -1 org_id = request.user.org.org_id if is_org_context(request) else -1
from seahub.utils import send_user_login_msg
try: try:
seafile_api.publish_event('seahub.stats', 'user-login\t%s\t%s\t%s' % (email, timestamp, org_id)) send_user_login_msg(email, timestamp, org_id)
except Exception as e: except Exception as e:
logger.error('Error when sending user-login message: %s' % str(e)) logger.error('Error when sending user-login message: %s' % str(e))

View File

@ -1004,8 +1004,9 @@ class Repos(APIView):
if is_org_context(request): if is_org_context(request):
org_id = request.user.org.org_id org_id = request.user.org.org_id
from seahub.utils import send_user_login_msg
try: try:
seafile_api.publish_event('seahub.stats', 'user-login\t%s\t%s\t%s' % (email, timestamp, org_id)) send_user_login_msg(email, timestamp, org_id)
except Exception as e: except Exception as e:
logger.error('Error when sending user-login message: %s' % str(e)) logger.error('Error when sending user-login message: %s' % str(e))
response = HttpResponse(json.dumps(repos_json), status=200, response = HttpResponse(json.dumps(repos_json), status=200,

View File

@ -2,6 +2,7 @@ import hashlib
import os import os
import logging import logging
import posixpath import posixpath
import json
from seaserv import seafile_api from seaserv import seafile_api
@ -119,9 +120,16 @@ def send_draft_publish_msg(draft, username, path):
repo_id = draft.origin_repo_id repo_id = draft.origin_repo_id
old_path = draft.draft_file_path old_path = draft.draft_file_path
msg = '%s\t%s\t%s\t%s\t%s\t%s' % ("publish", "draft", repo_id, username, path, old_path) msg = {
'msg_type': 'publish',
'obj_type': draft,
'repo_id': repo_id,
'user_name': username,
'path': path,
'old_path': old_path,
}
try: try:
seafile_api.publish_event('seahub.draft', msg) seafile_api.publish_event('seahub.draft', json.dumps(msg))
except Exception as e: except Exception as e:
logger.error("Error when sending draft publish message: %s" % str(e)) logger.error("Error when sending draft publish message: %s" % str(e))

View File

@ -13,6 +13,7 @@ import tempfile
import configparser import configparser
import mimetypes import mimetypes
import contextlib import contextlib
import json
from datetime import datetime from datetime import datetime
from urllib.parse import urlparse, urljoin from urllib.parse import urlparse, urljoin
@ -1315,15 +1316,34 @@ def send_perm_audit_msg(etype, from_user, to, repo_id, path, perm):
- `path`: dir path - `path`: dir path
- `perm`: r or rw - `perm`: r or rw
""" """
msg = 'perm-change\t%s\t%s\t%s\t%s\t%s\t%s' % \
(etype, from_user, to, repo_id, path, perm) msg = {
'msg_type': 'perm-change',
'etype': etype,
'from_user': from_user,
'to': to,
'repo_id': repo_id,
'file_path': path,
'perm': perm,
}
try: try:
seafile_api.publish_event('seahub.audit', msg) seafile_api.publish_event('seahub.audit', json.dumps(msg))
except Exception as e: except Exception as e:
logger.error("Error when sending perm-audit-%s message: %s" % logger.error("Error when sending perm-audit-%s message: %s" %
(etype, str(e))) (etype, str(e)))
def send_user_login_msg(username, timestamp, org_id):
msg = {
'msg_type': 'user-login',
'user_name': username,
'timestamp': timestamp,
'org_id': org_id,
}
seafile_api.publish_event('seahub.stats', json.dumps(msg))
def get_origin_repo_info(repo_id): def get_origin_repo_info(repo_id):
repo = seafile_api.get_repo(repo_id) repo = seafile_api.get_repo(repo_id)
if repo.origin_repo_id is not None: if repo.origin_repo_id is not None:

View File

@ -1697,11 +1697,17 @@ def send_file_access_msg(request, repo, path, access_from):
ip = get_remote_ip(request) ip = get_remote_ip(request)
user_agent = request.headers.get("user-agent") user_agent = request.headers.get("user-agent")
msg = 'file-download-%s\t%s\t%s\t%s\t%s\t%s' % \ msg = {
(access_from, username, ip, user_agent, repo.id, path) 'msg_type': 'file-download-' + access_from,
'user_name': username,
'ip': ip,
'user_agent': user_agent,
'repo_id': repo.id,
'file_path': path,
}
try: try:
seafile_api.publish_event('seahub.audit', msg) seafile_api.publish_event('seahub.audit', json.dumps(msg))
except Exception as e: except Exception as e:
logger.error("Error when sending file-download-%s message: %s" % logger.error("Error when sending file-download-%s message: %s" %
(access_from, str(e))) (access_from, str(e)))