mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-05-17 14:47:15 +00:00
133 lines
3.9 KiB
Go
133 lines
3.9 KiB
Go
package api
|
|
|
|
import (
|
|
"bufio"
|
|
"log"
|
|
"plugin"
|
|
"time"
|
|
)
|
|
|
|
type Extension struct {
|
|
Name string
|
|
Path string
|
|
Plug *plugin.Plugin
|
|
InboundPorts []string
|
|
OutboundPorts []string
|
|
Dissector Dissector
|
|
}
|
|
|
|
type ConnectionInfo struct {
|
|
ClientIP string
|
|
ClientPort string
|
|
ServerIP string
|
|
ServerPort string
|
|
IsOutgoing bool
|
|
}
|
|
|
|
type TcpID struct {
|
|
SrcIP string
|
|
DstIP string
|
|
SrcPort string
|
|
DstPort string
|
|
Ident string
|
|
}
|
|
|
|
type GenericMessage struct {
|
|
IsRequest bool `json:"is_request"`
|
|
CaptureTime time.Time `json:"capture_time"`
|
|
Payload interface{} `json:"payload"`
|
|
}
|
|
|
|
type RequestResponsePair struct {
|
|
Request GenericMessage `json:"request"`
|
|
Response GenericMessage `json:"response"`
|
|
}
|
|
|
|
type OutputChannelItem struct {
|
|
Protocol string
|
|
Timestamp int64
|
|
ConnectionInfo *ConnectionInfo
|
|
Pair *RequestResponsePair
|
|
}
|
|
|
|
type Dissector interface {
|
|
Register(*Extension)
|
|
Ping()
|
|
Dissect(b *bufio.Reader, isClient bool, tcpID *TcpID, emitter Emitter)
|
|
Analyze(item *OutputChannelItem, entryId string, resolvedSource string, resolvedDestination string) *MizuEntry
|
|
Summarize(entry *MizuEntry) *BaseEntryDetails
|
|
}
|
|
|
|
type Emitting struct {
|
|
OutputChannel chan *OutputChannelItem
|
|
}
|
|
|
|
type Emitter interface {
|
|
Emit(item *OutputChannelItem)
|
|
}
|
|
|
|
func (e *Emitting) Emit(item *OutputChannelItem) {
|
|
log.Printf("item: %+v\n", item)
|
|
log.Printf("item.Pair: %+v\n", item.Pair)
|
|
log.Printf("item.Pair.Request.Payload: %v\n", item.Pair.Request.Payload)
|
|
log.Printf("item.Pair.Response.Payload: %v\n", item.Pair.Response.Payload)
|
|
e.OutputChannel <- item
|
|
}
|
|
|
|
type MizuEntry struct {
|
|
ID uint `gorm:"primarykey"`
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Entry string `json:"entry,omitempty" gorm:"column:entry"`
|
|
EntryId string `json:"entryId" gorm:"column:entryId"`
|
|
Url string `json:"url" gorm:"column:url"`
|
|
Method string `json:"method" gorm:"column:method"`
|
|
Status int `json:"status" gorm:"column:status"`
|
|
RequestSenderIp string `json:"requestSenderIp" gorm:"column:requestSenderIp"`
|
|
Service string `json:"service" gorm:"column:service"`
|
|
Timestamp int64 `json:"timestamp" gorm:"column:timestamp"`
|
|
Path string `json:"path" gorm:"column:path"`
|
|
ResolvedSource string `json:"resolvedSource,omitempty" gorm:"column:resolvedSource"`
|
|
ResolvedDestination string `json:"resolvedDestination,omitempty" gorm:"column:resolvedDestination"`
|
|
IsOutgoing bool `json:"isOutgoing,omitempty" gorm:"column:isOutgoing"`
|
|
EstimatedSizeBytes int `json:"-" gorm:"column:estimatedSizeBytes"`
|
|
}
|
|
|
|
type BaseEntryDetails struct {
|
|
Id string `json:"id,omitempty"`
|
|
Url string `json:"url,omitempty"`
|
|
RequestSenderIp string `json:"requestSenderIp,omitempty"`
|
|
Service string `json:"service,omitempty"`
|
|
Path string `json:"path,omitempty"`
|
|
StatusCode int `json:"statusCode,omitempty"`
|
|
Method string `json:"method,omitempty"`
|
|
Timestamp int64 `json:"timestamp,omitempty"`
|
|
IsOutgoing bool `json:"isOutgoing,omitempty"`
|
|
Latency int64 `json:"latency,omitempty"`
|
|
Rules ApplicableRules `json:"rules,omitempty"`
|
|
}
|
|
|
|
type ApplicableRules struct {
|
|
Latency int64 `json:"latency,omitempty"`
|
|
Status bool `json:"status,omitempty"`
|
|
}
|
|
|
|
type DataUnmarshaler interface {
|
|
UnmarshalData(*MizuEntry) error
|
|
}
|
|
|
|
func (bed *BaseEntryDetails) UnmarshalData(entry *MizuEntry) error {
|
|
entryUrl := entry.Url
|
|
service := entry.Service
|
|
bed.Id = entry.EntryId
|
|
bed.Url = entryUrl
|
|
bed.Service = service
|
|
bed.Path = entry.Path
|
|
bed.StatusCode = entry.Status
|
|
bed.Method = entry.Method
|
|
bed.Timestamp = entry.Timestamp
|
|
bed.RequestSenderIp = entry.RequestSenderIp
|
|
bed.IsOutgoing = entry.IsOutgoing
|
|
return nil
|
|
}
|