Skip to content

Commit

Permalink
edit log format (json)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfonteneau committed Sep 3, 2024
1 parent a171c14 commit 5da99f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If you are not under debian or if you do not have the packages available :
1. apt-get install python3-pip
2. pip3 install -r /opt/samba4-gaps/requirements.txt

show log application in syslog
show log in /var/log/samba4-gaps.log in json format

* If you are having issues with Google Permissions - you might need to add domain-wide authority to your service
Delegate domain-wide authority to your service account https://developers.google.com/drive/web/delegation#delegate_domain-wide_authority_to_your_service_account
Expand Down
2 changes: 1 addition & 1 deletion gaps.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
domain = yourdomain.com
replace_domain = false
dbpath=/opt/samba4-gaps/last_send.db

logfile = /var/log/samba4-gaps.log

[google]
admin_email = [email protected]
Expand Down
17 changes: 12 additions & 5 deletions gapslib.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/usr/bin/env python
import sys
import hashlib
import syslog
import json
import ldb
import os
import optparse
import hashlib
import pickle
import logging
import datetime
import json

logger = logging.getLogger()

try:
from Cryptodome import Random
Expand Down Expand Up @@ -39,6 +43,10 @@
config = configparser.ConfigParser()
config.read('/etc/gaps/gaps.conf')

logfile = config.get('common', 'logfile')
fhandler = logging.FileHandler(logfile)
logger.addHandler(fhandler)

db = SqliteDatabase(config.get('common', 'dbpath'))

def hash_for_data(data):
Expand Down Expand Up @@ -86,7 +94,7 @@ def update_password(mail, pwd, sha1hashnt):
try:
user = service.users().get(userKey = mail).execute()
except:
syslog.syslog(syslog.LOG_WARNING, '[WARNING] Account %s not found' % mail)
logger.warning(json.dumps({'status':"warning",'msg':'Account not found','timestamp': str(datetime.datetime.utcnow()),'mail':mail}))
return 0

try:
Expand All @@ -96,10 +104,9 @@ def update_password(mail, pwd, sha1hashnt):
response = request.execute()

LastSend.insert(mail=mail,sha1hashnt = sha1hashnt).on_conflict_replace().execute()
syslog.syslog(syslog.LOG_WARNING, '[NOTICE] Updated password for %s' % mail)

logger.info(json.dumps({'status':"ok",'msg':'updated password','timestamp': str(datetime.datetime.utcnow()),'mail':mail}))
except Exception as e:
syslog.syslog(syslog.LOG_WARNING, '[ERROR] %s : %s' % (mail,str(e)))
logger.error(json.dumps({'status':"error",'msg':str(e),'timestamp': str(datetime.datetime.utcnow()),'mail':mail}))
finally:
service = None

Expand Down

0 comments on commit 5da99f6

Please sign in to comment.