2022-05-09 23:16:59 +02:00
|
|
|
package tracer
|
|
|
|
|
|
|
|
import (
|
2022-05-19 23:20:20 +02:00
|
|
|
"time"
|
2022-05-09 23:16:59 +02:00
|
|
|
)
|
|
|
|
|
2022-05-11 22:58:03 +02:00
|
|
|
type Strategy func(event Event)
|
|
|
|
|
2022-06-04 17:14:46 +02:00
|
|
|
type Tracer interface {
|
|
|
|
TraceEvent(event Event)
|
|
|
|
}
|
|
|
|
|
|
|
|
type tracer struct {
|
2022-05-11 22:58:03 +02:00
|
|
|
strategy Strategy
|
2022-05-09 23:16:59 +02:00
|
|
|
}
|
|
|
|
|
2022-06-04 17:14:46 +02:00
|
|
|
func Init(strategy Strategy) *tracer {
|
|
|
|
return &tracer{
|
2022-05-11 22:58:03 +02:00
|
|
|
strategy: strategy,
|
|
|
|
}
|
2022-05-09 23:16:59 +02:00
|
|
|
}
|
|
|
|
|
2022-06-04 17:14:46 +02:00
|
|
|
func (tracer *tracer) TraceEvent(event Event) {
|
2022-05-29 16:18:40 +02:00
|
|
|
event.DateTime = time.Now().UTC().Format(time.RFC3339)
|
2022-05-11 22:58:03 +02:00
|
|
|
tracer.strategy(event)
|
2022-05-09 23:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type Event struct {
|
2022-05-19 23:20:20 +02:00
|
|
|
DateTime string
|
2022-05-10 22:50:29 +02:00
|
|
|
RemoteAddr string
|
2022-05-17 23:32:00 +02:00
|
|
|
Protocol string
|
2022-05-10 22:50:29 +02:00
|
|
|
Command string
|
2022-05-17 23:32:00 +02:00
|
|
|
Status string
|
2022-05-10 22:50:29 +02:00
|
|
|
Msg string
|
|
|
|
ID string
|
|
|
|
Environ string
|
|
|
|
User string
|
|
|
|
Password string
|
|
|
|
Client string
|
2022-05-29 16:18:40 +02:00
|
|
|
Headers string
|
|
|
|
Cookies string
|
2022-05-10 22:50:29 +02:00
|
|
|
UserAgent string
|
|
|
|
HostHTTPRequest string
|
|
|
|
Body string
|
|
|
|
HTTPMethod string
|
|
|
|
RequestURI string
|
2022-05-31 22:39:56 +02:00
|
|
|
Description string
|
2022-05-09 23:16:59 +02:00
|
|
|
}
|
|
|
|
|
2022-05-10 22:50:29 +02:00
|
|
|
type Protocol int
|
|
|
|
|
|
|
|
const (
|
|
|
|
HTTP Protocol = iota
|
|
|
|
SSH
|
2022-07-03 17:15:38 +02:00
|
|
|
TCP
|
2022-05-10 22:50:29 +02:00
|
|
|
)
|
|
|
|
|
2022-05-17 23:32:00 +02:00
|
|
|
func (status Protocol) String() string {
|
2022-07-03 17:15:38 +02:00
|
|
|
return [...]string{"HTTP", "SSH", "TCP"}[status]
|
2022-05-17 23:32:00 +02:00
|
|
|
}
|
|
|
|
|
2022-05-09 23:16:59 +02:00
|
|
|
type Status int
|
|
|
|
|
|
|
|
const (
|
|
|
|
Start Status = iota
|
|
|
|
End
|
|
|
|
Stateless
|
|
|
|
Interaction
|
|
|
|
)
|
|
|
|
|
|
|
|
func (status Status) String() string {
|
|
|
|
return [...]string{"Start", "End", "Stateless", "Interaction"}[status]
|
|
|
|
}
|