2019-05-11 09:53:32 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
import "log"
|
|
|
|
import "net"
|
|
|
|
import "os"
|
|
|
|
import "io"
|
|
|
|
import "bytes"
|
2019-05-11 15:20:51 -05:00
|
|
|
import "strconv"
|
2019-05-11 09:53:32 -05:00
|
|
|
|
|
|
|
import "github.com/golang/protobuf/proto"
|
2019-05-11 14:45:17 -05:00
|
|
|
import pb "git.wit.com/wit/witProtobuf"
|
2019-05-11 09:53:32 -05:00
|
|
|
|
|
|
|
var mychannel chan *pb.Event
|
|
|
|
|
|
|
|
func initChannel() {
|
|
|
|
mychannel = make(chan *pb.Event)
|
|
|
|
}
|
|
|
|
|
|
|
|
// func processEvents(mychannel chan *pb.Event) {
|
|
|
|
func processEvents() {
|
|
|
|
for {
|
|
|
|
message := <-mychannel
|
2019-05-11 14:45:17 -05:00
|
|
|
log.Println("processEvents() on channel recieved a message = ", message)
|
2019-05-11 09:53:32 -05:00
|
|
|
ReadReceivedData(message)
|
2019-05-12 14:55:11 -05:00
|
|
|
addVmsTab()
|
2019-05-11 09:53:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ReadReceivedData(data *pb.Event) {
|
|
|
|
msgItems := data.GetResults()
|
2019-05-11 14:45:17 -05:00
|
|
|
log.Println("ReadReceivedData() Event msgItems=", msgItems)
|
2019-05-11 09:53:32 -05:00
|
|
|
for _, item := range msgItems {
|
2019-05-11 14:45:17 -05:00
|
|
|
log.Println(item)
|
2019-05-12 14:55:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
nets := data.GetNetworks()
|
|
|
|
log.Println("ReadReceivedData() Event networks=", nets)
|
|
|
|
for _, item := range nets {
|
|
|
|
log.Println(item)
|
|
|
|
}
|
|
|
|
|
|
|
|
vms := data.GetVms()
|
|
|
|
log.Println("ReadReceivedData() Event vms=", vms)
|
|
|
|
for _, item := range vms {
|
|
|
|
log.Println(item)
|
2019-05-11 09:53:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleProtoClient(conn net.Conn) {
|
|
|
|
fmt.Println("Connected!")
|
|
|
|
defer conn.Close()
|
|
|
|
var buf bytes.Buffer
|
|
|
|
_, err := io.Copy(&buf, conn)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
2019-05-11 14:45:17 -05:00
|
|
|
pdata := pb.CreateSampleEvent()
|
2019-05-11 09:53:32 -05:00
|
|
|
err = proto.Unmarshal(buf.Bytes(), pdata)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
mychannel <- pdata
|
|
|
|
}
|
|
|
|
|
2019-05-12 14:32:29 -05:00
|
|
|
// Marshal & Unmarshal just to see if it ever fails
|
|
|
|
func addEvent(msg *pb.Event) {
|
2019-05-11 09:53:32 -05:00
|
|
|
data, err := proto.Marshal(msg)
|
|
|
|
if (err != nil) {
|
2019-05-11 15:20:51 -05:00
|
|
|
log.Printf("addEvent() something fucked up happened in Marshal")
|
2019-05-11 09:53:32 -05:00
|
|
|
}
|
2019-05-11 15:20:51 -05:00
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
pdata := new(pb.Event)
|
|
|
|
err = proto.Unmarshal(data, pdata)
|
2019-05-11 15:20:51 -05:00
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("addEvent() something fucked up happened in Unmarshal")
|
|
|
|
}
|
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
mychannel <- pdata
|
2019-05-11 12:55:37 -05:00
|
|
|
}
|
|
|
|
|
2019-05-12 14:32:29 -05:00
|
|
|
func addSampleEvent() {
|
|
|
|
msg := pb.CreateSampleEvent()
|
|
|
|
msg.Name = "generated in addSampleEvent()"
|
|
|
|
|
|
|
|
data, err := proto.Marshal(msg)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("addSampleEvent() something fucked up happened in Marshal")
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata := new(pb.Event)
|
|
|
|
err = proto.Unmarshal(data, pdata)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("addSampleEvent() something fucked up happened in Unmarshal")
|
|
|
|
}
|
|
|
|
|
|
|
|
mychannel <- pdata
|
|
|
|
}
|
|
|
|
|
2019-05-11 12:55:37 -05:00
|
|
|
func sendEventToWIT() {
|
2019-05-11 14:45:17 -05:00
|
|
|
msg := pb.CreateSampleEvent()
|
2019-05-11 12:55:37 -05:00
|
|
|
|
2019-05-11 14:45:17 -05:00
|
|
|
var mybuf []byte
|
2019-05-11 12:55:37 -05:00
|
|
|
mybuf, err := proto.Marshal(msg)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("something fucked up happened")
|
|
|
|
}
|
|
|
|
writeBytesToSocket(mybuf)
|
2019-05-11 09:53:32 -05:00
|
|
|
}
|
2019-05-11 15:20:51 -05:00
|
|
|
|
|
|
|
func sendDataToDest() {
|
|
|
|
msg := pb.CreateSampleEvent()
|
|
|
|
msg.Name = "from dnssecsockettest()"
|
|
|
|
|
|
|
|
data, err := proto.Marshal(msg)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("something fucked up happened")
|
|
|
|
}
|
|
|
|
|
|
|
|
conn, err := net.Dial("tcp", "localhost:8080")
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Fatal error: %s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
n, err := conn.Write(data)
|
|
|
|
if err != nil {
|
|
|
|
// fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
|
|
|
log.Println("Fatal error: %s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pb.DumpEventData(msg)
|
|
|
|
log.Println("Sent " + strconv.Itoa(n) + " bytes")
|
|
|
|
// time.Sleep(3 * 1000 * 1000 * 1000)
|
|
|
|
conn.Close()
|
|
|
|
}
|