parent
62d548890d
commit
7cf7adc197
1 changed files with 11 additions and 5 deletions
|
|
@ -71,24 +71,30 @@ func GetAuditLogs(path string) (io.Reader, error) {
|
||||||
func GetJournalctlLogs(path string, useFile bool) (io.Reader, error) {
|
func GetJournalctlLogs(path string, useFile bool) (io.Reader, error) {
|
||||||
var logs []systemdLog
|
var logs []systemdLog
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
var value string
|
var unfilteredValue string
|
||||||
|
|
||||||
if useFile {
|
if useFile {
|
||||||
content, err := os.ReadFile(filepath.Clean(path))
|
content, err := os.ReadFile(filepath.Clean(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
value = string(content)
|
unfilteredValue = string(content)
|
||||||
} else {
|
} else {
|
||||||
// journalctl -b -o json > systemd.log
|
// journalctl -b -o json --output-fields=MESSAGE > systemd.log
|
||||||
cmd := exec.Command("journalctl", "--boot", "--output=json")
|
cmd := exec.Command("journalctl", "--boot", "--output=json", "--output-fields=MESSAGE")
|
||||||
cmd.Stdout = &stdout
|
cmd.Stdout = &stdout
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
value = stdout.String()
|
unfilteredValue = stdout.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value := ""
|
||||||
|
for _, v := range strings.Split(unfilteredValue, "\n") {
|
||||||
|
if strings.Contains(v, "apparmor") {
|
||||||
|
value += v + "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
value = strings.Replace(value, "\n", ",\n", -1)
|
value = strings.Replace(value, "\n", ",\n", -1)
|
||||||
value = strings.TrimSuffix(value, ",\n")
|
value = strings.TrimSuffix(value, ",\n")
|
||||||
value = `[` + value + `]`
|
value = `[` + value + `]`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue