-
Notifications
You must be signed in to change notification settings - Fork 0
/
010openLogs.R
119 lines (94 loc) · 4.61 KB
/
010openLogs.R
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Import the latest logs to R
#
# Import log of EMu records modified on previous day ####
# # background & alternatives here:
# # https://stackoverflow.com/questions/33446888/r-convert-xml-data-to-data-frame
## NOTE:
## pathEMu & pathFiler are defined in 050checkRenv.R and .Renviron
# get date & local enviro variables
origdir <- getwd()
locEMu <- Sys.getenv("EMU_LOC")
locFiler <- Sys.getenv("FILER_LOC")
filerDate <- gsub("-","",(Sys.Date() - 1))
## Get most recent EMu audit log
## NOTE:
## EMu audit logs are generated by a periodic export
## - Tues-Fri EMu audit logs represent the previous day's activity
## - Mon EMu audit log represents Fri+Sat+Sun activity <-- TESTING THIS
# timeEMu <- file.info(list.files(paste(pathEMu), full.names = T))
timeEMu <- file.info(list.files(locEMu, full.names = T))
# dfEMu <- list.dirs(paste(pathEMu), full.names = T)
dfEMu <- list.dirs(locEMu, full.names = T)
if (NROW(list.dirs(locEMu)) < 2) {
print(paste("no EMu audit log for", filerDate))
write.table(print(paste("No EMu log for", filerDate)),
file = paste0("EMuauditErrorlog_",filerDate,".txt"))
} else {
emu1 <- read.csv(paste0(dfEMu[NROW(dfEMu)], "/",
list.files(dfEMu[NROW(dfEMu)], pattern = "eaudit")),
# rownames(dfEMu)[which.max(dfEMu$ctime)],
stringsAsFactors = F)
emu2 <- read.csv(paste0(dfEMu[NROW(dfEMu)], "/",
list.files(dfEMu[NROW(dfEMu)], pattern = "Group1")),
# rownames(dfEMu)[which.max(dfEMu$ctime)],
stringsAsFactors = F)
}
# Get most recent Filer audit log with corresponding EMu log
# dfFiler <- list.dirs(paste0(origdir, locFiler), full.names = T)
dfFiler <- list.dirs(locFiler, full.names = T)
# if (!dir.exists(paste0(origdir, locFiler, filerDate))) {
if (!dir.exists(paste0(locFiler, filerDate))) {
print(paste("no filer audit log for", filerDate))
# write.table(print(paste("No Filer log for", filerDate)),
# file = paste0("auditErrorlog_",filerDate,".txt"))
filerBU <- data.frame("timestamp.UTC." = character(),
"category" = character(),
"event.type" = character(),
"path.from" = character(),
"new.path.to" = logical(),
"user" = integer(),
"group" = integer(),
"sid" = integer(),
"share.export.name" = logical(),
"volume.type" = character(),
"client.IP" = logical(),
"snapshot.timestamp.UTC." = logical(),
"shared.link" = logical(),
stringsAsFactors = F)
} else {
filerBU <- read.csv(paste0(dfFiler[NROW(dfFiler)], "/",
list.files(dfFiler[NROW(dfFiler)], pattern = "audit")),
stringsAsFactors = F)
}
# On Mondays, get Friday logs, too.
# (May need to fix this -- On Mon, need Fri filer log; on Tues, need Sat & Sun Filer logs)
if (!is.null(timeEMu$ctime)) {
if (format(max(timeEMu$ctime), "%a") == "Mon") {
for (i in 2:3) {
filerDateMon <- gsub("-","",(Sys.Date() - i))
if (dir.exists(locFiler, filerDateMon)==FALSE) {
print(paste("no filer audit log for", (filerDateMon)))
filerTMP <- data.frame("timestamp.UTC." = character(),
"category" = character(),
"event.type" = character(),
"path.from" = character(),
"new.path.to" = logical(),
"user" = integer(),
"group" = integer(),
"sid" = integer(),
"share.export.name" = logical(),
"volume.type" = character(),
"client.IP" = logical(),
"snapshot.timestamp.UTC." = logical(),
"shared.link" = logical(),
stringsAsFactors = F)
} else {
locFilerMon <- paste0(locFiler, filerDateMon, sep = "/")
filerTMP <- read.csv(paste0(locFilerMon, "/",
list.files(locFilerMon, pattern = "audit")),
stringsAsFactors = F)
}
filerBU <- rbind(filerBU, filerTMP)
}
}
}