()
| 61 | } |
| 62 | |
| 63 | func (p *Process) getEventTemplate() *event.Event { |
| 64 | if tmpl := p.tmpl.Load(); tmpl != nil { |
| 65 | return tmpl |
| 66 | } |
| 67 | |
| 68 | tmpl := p.global.Config.GetEventTemplate() |
| 69 | tmpl.Set("process_id", fmt.Sprintf("%d", p.PID)) |
| 70 | |
| 71 | if path, err := os.Readlink(fmt.Sprintf("/proc/%d/exe", p.PID)); err == nil { |
| 72 | tmpl.Set("process_executable_name", filepath.Base(path)) |
| 73 | } |
| 74 | |
| 75 | if info, err := os.Stat(fmt.Sprintf("/proc/%d/exe", p.PID)); err == nil { |
| 76 | tmpl.Set("process_executable_size", fmt.Sprintf("%d", info.Size())) |
| 77 | } |
| 78 | |
| 79 | if cmdline, err := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", p.PID)); err == nil { |
| 80 | var parts []string |
| 81 | args := bytes.Split(cmdline, []byte{0}) |
| 82 | for i := 0; i < len(args)-1; i++ { |
| 83 | parts = append(parts, string(args[i])) |
| 84 | } |
| 85 | tmpl.Set("process_command_line", strings.Join(parts, " ")) |
| 86 | } |
| 87 | |
| 88 | if info, err := os.Stat(fmt.Sprintf("/proc/%d", p.PID)); err == nil { |
| 89 | if sys, ok := info.Sys().(*syscall.Stat_t); ok { |
| 90 | if name, err := findUsername(sys.Uid); err == nil && name != "" { |
| 91 | tmpl.Set("process_user", name) |
| 92 | } else { |
| 93 | tmpl.Set("process_user", fmt.Sprintf("%d", sys.Uid)) |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | p.tmpl.Store(tmpl) |
| 99 | return tmpl |
| 100 | } |
| 101 | |
| 102 | func (p *Process) LogValue() slog.Value { |
| 103 | select { |
no test coverage detected