-
Notifications
You must be signed in to change notification settings - Fork 0
/
auditEntryForNode.py
84 lines (57 loc) · 2.9 KB
/
auditEntryForNode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from queryAlf import runQuery
import pandas as pd, json
import os
from dotenv import load_dotenv
# Load environment variables from the .env file
load_dotenv()
BASE_URL= os.getenv("BASE_URL")
auth = os.getenv("auth")
user=os.getenv("user")
passwd=os.getenv("pass")
nodeID = []
appEntryID = []
appEntryDetails = []
appEntryDate = []
appEntryUser = []
cols = {0: 'nodeID',1:'auditEntryID',2:'entryDate',3:'details',4:'user'}
def pullAuditEntryForNode(nodeid):
auditEntryforNodeQuery = BASE_URL + '/alfresco/api/-default-/public/alfresco/versions/1/nodes/'+nodeid+'/audit-entries'
print ('query url is: ' + auditEntryforNodeQuery + ' with userpass: '+ user+passwd) #debug
data=runQuery('get',auditEntryforNodeQuery,'',user,passwd)
print ("data returned is: " + str(data)) #debug
return data
def pullAuditEntryDetailsForNode(auditentryid):
auditEntryDetailsForNodeQuery = BASE_URL + '/alfresco/api/-default-/public/alfresco/versions/1/audit-applications/alfresco-access/audit-entries/'+str(auditentryid)+'?fields=values'
data=runQuery('get',auditEntryDetailsForNodeQuery,'',user,passwd)
#See if the actual action data can be returned
actionDetailsForNode = data['entry']['values']['/alfresco-access/transaction/action']
actionUserForNode = data['entry']['values']['/alfresco-access/transaction/user']
return [actionDetailsForNode,actionUserForNode]
def main(nodeid):
#now clear the temp arrays now!
nodeID = []
appEntryID = []
appEntryDate = []
appEntryDetails = []
appEntryUser = []
auditentryfornodeDF = pd.DataFrame(None)
#print("node id is: "+nodeid) #debugging
for entry in pullAuditEntryForNode(nodeid)['list']['entries']:
#print(nodeid + '-' + str(entry['entry']['id'])) #debug
#set the entry details and user now so there's one call
entryDetails = pullAuditEntryDetailsForNode(entry['entry']['id'])[0]
entryUser = pullAuditEntryDetailsForNode(entry['entry']['id'])[1]
nodeID.append(nodeid) #this will be the same nodeid for each audit entry id
appEntryID.append(entry['entry']['id'])
appEntryDate.append(entry['entry']['createdAt'])
appEntryDetails.append(entryDetails) #this is coming from the pullauditdetailsentryfornode
appEntryUser.append(entryUser) #this is coming from the pullauditdetailsentryfornode
#print ("size of user array is: " + str(len(appEntryUser))) #debugging
auditentryfornodeDF = pd.DataFrame([nodeID,appEntryID,appEntryDate,appEntryDetails,appEntryUser]).T
auditentryfornodeDF.rename(columns=cols,inplace=True)
print (auditentryfornodeDF)
auditentryfornodeDF.to_excel('auditentryfornode.xlsx')
return auditentryfornodeDF
if __name__ == "__main__":
#nodeid = '0e0a3eba-3734-460f-a406-eb79eb6d2955' #testing node on rwilds232
main('bd7b45c0-5e60-4916-b4c1-fa93df39bbb6') #debug if this file is run directly not from flask app