Skip to content

Commit

Permalink
http reporting generalized
Browse files Browse the repository at this point in the history
  • Loading branch information
glaslos committed Mar 30, 2017
1 parent 1123eee commit fe140c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion glutton.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (g *Glutton) registerHandlers() {
}
g.logger.Debugf("[glutton ] new connection: %s:%s -> %d", host, port, uint(md.TargetPort))

err = g.producer.LogHTTP(conn, md, "", "")
err = g.producer.LogHTTP(conn, md, nil, "")
if err != nil {
g.logger.Error(err)
}
Expand Down
25 changes: 13 additions & 12 deletions producer/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package producer

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"net"
Expand All @@ -22,15 +23,15 @@ type Config struct {

// Event is a struct for glutton events
type Event struct {
Timestamp time.Time `json:"timestamp"`
SrcHost string `json:"srcHost"`
SrcPort string `json:"srcPort"`
DstPort string `json:"dstPort"`
SensorID string `json:"sensorID"`
Rule string `json:"rule"`
ConnKey [2]uint64 `json:"connKey"`
Payload interface{} `json:"payload"`
Direction string `json:"direction"`
Timestamp time.Time `json:"timestamp"`
SrcHost string `json:"srcHost"`
SrcPort string `json:"srcPort"`
DstPort string `json:"dstPort"`
SensorID string `json:"sensorID"`
Rule string `json:"rule"`
ConnKey [2]uint64 `json:"connKey"`
Payload string `json:"payload"`
Action string `json:"action"`
}

// Init initializes the producer
Expand All @@ -44,7 +45,7 @@ func Init(sensorID string, log freki.Logger, logHTTP string) *Config {
}

// LogHTTP send logs to HTTP endpoint
func (conf *Config) LogHTTP(conn net.Conn, md *freki.Metadata, payload interface{}, direction string) (err error) {
func (conf *Config) LogHTTP(conn net.Conn, md *freki.Metadata, payload []byte, action string) (err error) {
host, port, err := net.SplitHostPort(conn.RemoteAddr().String())
if err != nil {
return
Expand All @@ -66,8 +67,8 @@ func (conf *Config) LogHTTP(conn net.Conn, md *freki.Metadata, payload interface
SensorID: conf.sensorID,
Rule: md.Rule.String(),
ConnKey: connKey,
Payload: payload,
Direction: direction,
Payload: base64.StdEncoding.EncodeToString(payload),
Action: action,
}
data, err := json.Marshal(event)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions telnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func writeMsg(conn net.Conn, msg string, g *Glutton) error {
_, err := conn.Write([]byte(msg))
g.logger.Infof("[telnet ] send: %q", msg)
md := g.processor.Connections.GetByFlow(freki.NewConnKeyFromNetConn(conn))
g.producer.LogHTTP(conn, md, msg, "write")
g.producer.LogHTTP(conn, md, []byte(msg), "write")
return err
}

Expand All @@ -63,7 +63,7 @@ func readMsg(conn net.Conn, g *Glutton) (msg string, err error) {
}
g.logger.Infof("[telnet ] recv: %q", msg)
md := g.processor.Connections.GetByFlow(freki.NewConnKeyFromNetConn(conn))
g.producer.LogHTTP(conn, md, msg, "read")
g.producer.LogHTTP(conn, md, []byte(msg), "read")
return msg, err
}

Expand Down

0 comments on commit fe140c6

Please sign in to comment.