2019-05-11 09:53:32 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
import "log"
|
2019-05-21 17:17:00 -05:00
|
|
|
import "image/color"
|
2019-05-23 16:33:55 -05:00
|
|
|
import "runtime"
|
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-23 17:11:35 -05:00
|
|
|
var windowsTextVeryLightGrey = color.RGBA{10, 10, 10, 10}
|
|
|
|
var windowsTextBlack = color.RGBA{200, 200, 200, 200}
|
2019-05-23 16:33:55 -05:00
|
|
|
var windowsTextWhite = color.RGBA{255, 255, 255, 255}
|
|
|
|
var windowsTextYellow = color.RGBA{200, 200, 0, 200}
|
|
|
|
var windowsTextRed = color.RGBA{200, 0, 0, 200}
|
|
|
|
var windowsTextBlue = color.RGBA{0, 100, 200, 100}
|
|
|
|
var windowsBgGrey = color.RGBA{100, 100, 100, 142}
|
|
|
|
var windowsBgBlack = color.RGBA{55, 55, 55, 255}
|
|
|
|
|
|
|
|
var linuxTextBlue = color.RGBA{0, 100, 200, 100}
|
|
|
|
var linuxTextBlack = color.RGBA{0, 0, 0, 0}
|
2019-05-23 16:42:35 -05:00
|
|
|
var linuxTextYellow = color.RGBA{200, 200, 0, 200}
|
|
|
|
var linuxBgMauve = color.RGBA{72, 0, 0, 142}
|
|
|
|
var linuxBgBlack = color.RGBA{55, 55, 55, 255}
|
|
|
|
var linuxBgWhite = color.RGBA{0, 0, 0, 0}
|
2019-05-23 16:33:55 -05:00
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
func initChannel() {
|
|
|
|
mychannel = make(chan *pb.Event)
|
|
|
|
}
|
|
|
|
|
2019-05-23 20:04:00 -05:00
|
|
|
// Marshal & Unmarshal just to see if it ever fails
|
|
|
|
func addEvent(msg *pb.Event) {
|
|
|
|
data, err := proto.Marshal(msg)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("addEvent() something fucked up happened in Marshal")
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata := new(pb.Event)
|
|
|
|
err = proto.Unmarshal(data, pdata)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("addEvent() something fucked up happened in Unmarshal")
|
|
|
|
}
|
|
|
|
|
|
|
|
mychannel <- pdata
|
|
|
|
}
|
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
// 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-12 20:49:59 -05:00
|
|
|
} else {
|
2019-05-23 21:36:20 -05:00
|
|
|
log.Println("processEvents() NEW PROTOBUF")
|
2019-05-23 18:38:51 -05:00
|
|
|
gui.Data.State = "NEW PROTOBUF"
|
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-23 16:33:55 -05:00
|
|
|
defaultTextColor := linuxTextBlue
|
2019-05-23 16:42:35 -05:00
|
|
|
defaultTextYellow := linuxTextYellow
|
2019-05-23 16:33:55 -05:00
|
|
|
defaultTextBlack := linuxTextBlack
|
2019-05-23 16:42:35 -05:00
|
|
|
|
2019-05-23 16:33:55 -05:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
defaultTextColor = windowsTextRed
|
2019-05-23 16:42:35 -05:00
|
|
|
defaultTextBlack = windowsTextBlack
|
2019-05-23 16:33:55 -05:00
|
|
|
}
|
2019-05-23 16:11:18 -05:00
|
|
|
// if (row % 2) == 1 {
|
|
|
|
if (row == 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-23 16:11:18 -05:00
|
|
|
} else if (row == 2) {
|
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{0, 0, 0, 0} // makes the background of each other row grey
|
|
|
|
} else if (row == 3) {
|
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{255, 255, 255, 255} // makes the background of each other row grey
|
|
|
|
} else if (row == 4) {
|
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{255, 255, 255, 0} // makes the background of each other row grey
|
|
|
|
} else if (row == 5) {
|
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{55, 55, 55, 255} // makes the background of each other row grey
|
2019-05-13 00:05:56 -05:00
|
|
|
} else {
|
2019-05-23 16:42:35 -05:00
|
|
|
mh.Rows[row].HumanData[0].Color = linuxBgMauve
|
2019-05-13 00:05:56 -05:00
|
|
|
}
|
2019-05-21 17:17:00 -05:00
|
|
|
mh.Rows[row].HumanData[1].Text = item.Name
|
2019-05-23 16:33:55 -05:00
|
|
|
mh.Rows[row].HumanData[1].Color = defaultTextColor
|
2019-05-21 17:17:00 -05:00
|
|
|
mh.Rows[row].HumanData[2].Text = item.Hostname
|
2019-05-23 16:33:55 -05:00
|
|
|
mh.Rows[row].HumanData[2].Color = defaultTextYellow
|
2019-05-21 17:17:00 -05:00
|
|
|
mh.Rows[row].HumanData[3].Text = fmt.Sprintf("%d",item.Cpus)
|
2019-05-23 16:33:55 -05:00
|
|
|
mh.Rows[row].HumanData[3].Color = defaultTextColor
|
2019-05-21 17:17:00 -05:00
|
|
|
mh.Rows[row].HumanData[4].Text = fmt.Sprintf("%d",item.Memory)
|
2019-05-23 16:33:55 -05:00
|
|
|
mh.Rows[row].HumanData[4].Color = defaultTextBlack
|
2019-05-21 17:17:00 -05:00
|
|
|
mh.Rows[row].HumanData[5].Text = fmt.Sprintf("%d",item.Disk)
|
2019-05-23 16:33:55 -05:00
|
|
|
mh.Rows[row].HumanData[5].Color = defaultTextBlack
|
2019-05-21 17:17:00 -05:00
|
|
|
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 20:49:59 -05:00
|
|
|
}
|