forked from danmia/pcapdaemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
131 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
// BUFFER FOR CAPTURE MESSAGES | ||
|
||
type RingBufferCapmsg struct { | ||
inputChannel <-chan Capmsg | ||
outputChannel chan Capmsg | ||
} | ||
|
||
|
||
func NewRingBufferCapmsg(inputChannel <-chan Capmsg, outputChannel chan Capmsg) *RingBufferCapmsg { | ||
return &RingBufferCapmsg{inputChannel, outputChannel} | ||
} | ||
|
||
func (r *RingBufferCapmsg) Run() { | ||
for v := range r.inputChannel { | ||
select { | ||
case r.outputChannel <- v: | ||
default: | ||
<-r.outputChannel | ||
r.outputChannel <- v | ||
} | ||
} | ||
close(r.outputChannel) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"node": "builder1.lab5", | ||
"interface": "bond1", | ||
"tags": "blah,tagme,stuff", | ||
"bpf": "dst ip 10.0.0.1", | ||
"customer": "paypal", | ||
"snap": 1500, | ||
"packets": 50, | ||
"alertid": 655443, | ||
"duration": 15 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PUBLISH capture '{"duration":15,"node":"builder1.lab5","interface":"bond1","tags":"blah,tagme,stuff","bpf":"dst ip 10.0.0.1","customer":"paypal","snap":1500,"packets":50,"alertid":655443}' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"encoding/json" | ||
"github.com/garyburd/redigo/redis" | ||
) | ||
|
||
var c redis.Conn | ||
var gerr error | ||
|
||
func subToRedis(server string, port int, subchannel string) { | ||
|
||
fmt.Println("Attempting connect to " + server) | ||
c, gerr = redis.Dial("tcp", server + ":" + strconv.Itoa(port)) | ||
if gerr != nil { | ||
fmt.Printf("Error connecting: %s\n", gerr) | ||
} | ||
fmt.Println("Connected to " + server) | ||
psc := redis.PubSubConn{c} | ||
psc.Subscribe(subchannel) | ||
|
||
for { | ||
var msg Capmsg | ||
switch v := psc.Receive().(type) { | ||
case redis.Message: | ||
fmt.Printf("%s: message: %s\n", v.Channel, v.Data) | ||
if err := json.Unmarshal(v.Data, &msg); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
if(*upPtr) { | ||
go func() { | ||
captureToBuffer(msg); | ||
}() | ||
} | ||
} | ||
case redis.Subscription: | ||
fmt.Printf("%s: %s %d\n", v.Channel, v.Kind, v.Count) | ||
case error: | ||
fmt.Printf("Error: %s\n", v) | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type Capmsg struct { | ||
Node string `json:"node,omitempty"` | ||
Interface string `json:"interface,omitempty"` | ||
Tags string `json:"tags,omitempty"` | ||
Bpf string `json:"bpf,omitempty"` | ||
Customer string `json:"customer,omitempty"` | ||
Snap int `json:"snap"` | ||
Packets int `json:"packets"` | ||
Alertid int `json:"alertid,omitempty"` | ||
Duration time.Duration `json:"duration,omitempty"` | ||
} | ||
|
||
type Capmsgs []Capmsg |