mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-11-15 07:54:17 +01:00
feat(aa-log): speed up log generation.
This commit is contained in:
parent
863034438d
commit
f81ceb9185
@ -145,7 +145,7 @@ func (aaLogs AppArmorLogs) String() string {
|
|||||||
"UID", "AUID", "hostname", "class",
|
"UID", "AUID", "hostname", "class",
|
||||||
}
|
}
|
||||||
// Color template to use
|
// Color template to use
|
||||||
colors := map[string]string{
|
template := map[string]string{
|
||||||
"profile": fgBlue,
|
"profile": fgBlue,
|
||||||
"label": fgBlue,
|
"label": fgBlue,
|
||||||
"operation": fgYellow,
|
"operation": fgYellow,
|
||||||
@ -159,22 +159,23 @@ func (aaLogs AppArmorLogs) String() string {
|
|||||||
"interface": "interface=" + fgWhite,
|
"interface": "interface=" + fgWhite,
|
||||||
"member": "member=" + fgGreen,
|
"member": "member=" + fgGreen,
|
||||||
}
|
}
|
||||||
res := ""
|
var res strings.Builder
|
||||||
|
|
||||||
for _, log := range aaLogs {
|
for _, log := range aaLogs {
|
||||||
seen := map[string]bool{"apparmor": true}
|
seen := map[string]bool{"apparmor": true}
|
||||||
res += state[log["apparmor"]]
|
res.WriteString(state[log["apparmor"]])
|
||||||
fsuid := log["fsuid"]
|
fsuid := log["fsuid"]
|
||||||
ouid := log["ouid"]
|
ouid := log["ouid"]
|
||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if log[key] != "" {
|
if item, present := log[key]; present {
|
||||||
if key == "name" && fsuid == ouid && !strings.Contains(log["operation"], "dbus") {
|
if key == "name" && fsuid == ouid && !strings.Contains(log["operation"], "dbus") {
|
||||||
res += colors[key] + " owner" + reset
|
res.WriteString(template[key] + " owner" + reset)
|
||||||
}
|
}
|
||||||
if colors[key] != "" {
|
if temp, present := template[key]; present {
|
||||||
res += " " + colors[key] + toQuote(log[key]) + reset
|
res.WriteString(" " + temp + toQuote(item) + reset)
|
||||||
} else {
|
} else {
|
||||||
res += " " + key + "=" + toQuote(log[key])
|
res.WriteString(" " + key + "=" + toQuote(item))
|
||||||
}
|
}
|
||||||
seen[key] = true
|
seen[key] = true
|
||||||
}
|
}
|
||||||
@ -184,13 +185,13 @@ func (aaLogs AppArmorLogs) String() string {
|
|||||||
if slices.Contains(ignore, key) {
|
if slices.Contains(ignore, key) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !seen[key] && value != "" {
|
if _, present := seen[key]; !present && value != "" {
|
||||||
res += " " + key + "=" + toQuote(value)
|
res.WriteString(" " + key + "=" + toQuote(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res += "\n"
|
res.WriteString("\n")
|
||||||
}
|
}
|
||||||
return res
|
return res.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseToProfiles convert the log data into a new AppArmorProfiles
|
// ParseToProfiles convert the log data into a new AppArmorProfiles
|
||||||
|
Loading…
Reference in New Issue
Block a user