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-21 17:17:00 -05:00
|
|
|
import "image/color"
|
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
|
|
|
|
2019-05-12 17:32:38 -05:00
|
|
|
import "git.wit.com/wit/gui"
|
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
var mychannel chan *pb.Event
|
|
|
|
|
2019-05-23 00:33:16 -05:00
|
|
|
var currentMessage *pb.Event
|
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
func initChannel() {
|
|
|
|
mychannel = make(chan *pb.Event)
|
|
|
|
}
|
|
|
|
|
|
|
|
// func processEvents(mychannel chan *pb.Event) {
|
|
|
|
func processEvents() {
|
|
|
|
for {
|
2019-05-23 00:33:16 -05:00
|
|
|
currentMessage = <-mychannel
|
|
|
|
log.Println("processEvents() START on channel recieved a message = ", currentMessage)
|
|
|
|
if (currentMessage.Type == pb.Event_DEMO) {
|
2019-05-12 20:36:31 -05:00
|
|
|
log.Println("processEvents() do Event DEMO")
|
2019-05-21 17:17:00 -05:00
|
|
|
// figure out how to interact with the GUI here
|
|
|
|
// go ui.Main(gui.SetupDemoUI)
|
2019-05-12 20:49:59 -05:00
|
|
|
} else {
|
2019-05-23 00:33:16 -05:00
|
|
|
gui.Data.State = "bmath done"
|
|
|
|
/*
|
2019-05-15 12:02:47 -05:00
|
|
|
count := countVMS(message)
|
|
|
|
mh := addVmsTab(count)
|
2019-05-12 20:49:59 -05:00
|
|
|
ReadReceivedData(message, mh)
|
2019-05-23 00:33:16 -05:00
|
|
|
*/
|
2019-05-12 20:36:31 -05:00
|
|
|
}
|
2019-05-21 20:18:59 -05:00
|
|
|
log.Println("processEvents() END on channel")
|
2019-05-11 09:53:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 12:02:47 -05:00
|
|
|
func countVMS(data *pb.Event) int {
|
|
|
|
vms := data.GetVms()
|
|
|
|
log.Println("NUMBER OF vms=", len(vms))
|
|
|
|
// os.Exit(-1)
|
|
|
|
return len(vms)
|
|
|
|
}
|
|
|
|
|
2019-05-12 17:32:38 -05:00
|
|
|
func ReadReceivedData(data *pb.Event, mh *gui.TableData) {
|
2019-05-11 09:53:32 -05:00
|
|
|
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)
|
2019-05-12 23:00:55 -05:00
|
|
|
for row, item := range vms {
|
2019-05-13 00:05:56 -05:00
|
|
|
if (row % 2) == 1 {
|
2019-05-23 02:11:49 -05:00
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{100, 100, 100, 142} // makes the background of each other row grey
|
2019-05-13 00:05:56 -05:00
|
|
|
} else {
|
2019-05-23 15:57:24 -05:00
|
|
|
// mh.Rows[row].HumanData[0].Color = color.RGBA{0, 0, 0, 142}
|
|
|
|
// mh.Rows[row].HumanData[0].Color = nil
|
2019-05-13 00:05:56 -05:00
|
|
|
}
|
2019-05-21 17:17:00 -05:00
|
|
|
mh.Rows[row].HumanData[1].Text = item.Name
|
|
|
|
mh.Rows[row].HumanData[1].Color = color.RGBA{0, 0, 0, 0}
|
|
|
|
mh.Rows[row].HumanData[2].Text = item.Hostname
|
|
|
|
mh.Rows[row].HumanData[2].Color = color.RGBA{0, 0, 0, 0}
|
|
|
|
mh.Rows[row].HumanData[3].Text = fmt.Sprintf("%d",item.Cpus)
|
|
|
|
mh.Rows[row].HumanData[3].Color = color.RGBA{0, 0, 0, 0}
|
|
|
|
mh.Rows[row].HumanData[4].Text = fmt.Sprintf("%d",item.Memory)
|
|
|
|
mh.Rows[row].HumanData[4].Color = color.RGBA{0, 0, 0, 0}
|
|
|
|
mh.Rows[row].HumanData[5].Text = fmt.Sprintf("%d",item.Disk)
|
|
|
|
mh.Rows[row].HumanData[5].Color = color.RGBA{0, 0, 0, 0}
|
|
|
|
mh.Rows[row].HumanData[6].Text = fmt.Sprintf("Details %s",item.Name)
|
2019-05-12 23:00:55 -05:00
|
|
|
|
2019-05-12 23:20:58 -05:00
|
|
|
log.Println("\titem=", item)
|
2019-05-12 23:00:55 -05:00
|
|
|
log.Println("\titem.Name=", item.Name)
|
|
|
|
log.Println("\tRows[row]=", mh.Rows[row])
|
|
|
|
log.Println("\tRows[row]=", row)
|
|
|
|
log.Println("\tRows[row].Name=", mh.Rows[row].Name)
|
2019-05-12 14:55:11 -05:00
|
|
|
log.Println(item)
|
2019-05-12 17:32:38 -05:00
|
|
|
row += 1
|
|
|
|
}
|
|
|
|
|
2019-05-12 23:00:55 -05:00
|
|
|
/*
|
2019-05-12 17:32:38 -05:00
|
|
|
log.Println("ReadReceivedData() mh rows")
|
|
|
|
for row := 0; row < mh.RowCount; row++ {
|
|
|
|
log.Println("\trow=", row)
|
2019-05-12 23:00:55 -05:00
|
|
|
log.Println("\tRows[row]=", mh.Rows[row])
|
2019-05-11 09:53:32 -05:00
|
|
|
}
|
2019-05-12 23:00:55 -05:00
|
|
|
*/
|
2019-05-11 09:53:32 -05:00
|
|
|
}
|
|
|
|
|
2019-05-12 20:49:59 -05:00
|
|
|
func addSampleEvent() {
|
|
|
|
msg := pb.CreateSampleEvent()
|
|
|
|
msg.Name = "generated in addSampleEvent()"
|
|
|
|
|
|
|
|
addEvent(msg)
|
2019-05-11 09:53:32 -05:00
|
|
|
}
|
|
|
|
|
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-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()
|
|
|
|
}
|
2019-05-12 20:49:59 -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
|
|
|
|
}
|
|
|
|
pdata := pb.CreateSampleEvent()
|
|
|
|
err = proto.Unmarshal(buf.Bytes(), pdata)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
mychannel <- pdata
|
|
|
|
}
|