Ejemplo n.º 1
0
func main() {
	flag.Parse()

	cfg := new(config)
	err := gcfg.ReadFileInto(cfg, *configFile)
	if err != nil {
		fmt.Println("Config Error: ", err)
		os.Exit(1)
	}

	lmi := logmein.NewLMI(cfg.RSS.ProfileID, cfg.RSS.Key)
	computers := lmi.Fetch()
	for _, computer := range computers {
		log.Println("FETCH: ", computer.Name())
	}

	recv := make(chan *logmein.Computer)
	stop := make(chan struct{})
	go lmi.Watch(recv, stop, true)

	for {
		computer := <-recv
		fmt.Printf("EVENT  [%d]\n\tName: %s\n\tIP: %s\n\tStatus: %d\n\tTimestamp: %s\n", computer.HostID(), computer.Name(), computer.IPAddress(), computer.Status(), computer.Timestamp())
		if computer.Unchanged() {
			fmt.Println("\t• Unchanged")
		}
		if computer.IsDeleted() {
			fmt.Println("\t• IsDeleted")
		}
		if computer.IsNew() {
			fmt.Println("\t• IsNew")
		}
		if computer.IsChangedHostID() {
			fmt.Printf("\t• IsChangedHostID [%d -> %d]\n", computer.OldHostID(), computer.HostID())
		}
		if computer.IsChangedName() {
			fmt.Printf("\t• IsChangedName [%s -> %s]\n", computer.OldName(), computer.Name())
		}
		if computer.IsChangedIPAddress() {
			fmt.Printf("\t• IsChangedIPAddress [%s -> %s]\n", computer.OldIPAddress(), computer.IPAddress())
		}
		if computer.IsChangedStatus() {
			fmt.Printf("\t• IsChangedStatus [%d -> %d]\n", computer.OldStatus(), computer.Status())
		}
		fmt.Println("")
	}
}
Ejemplo n.º 2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

	cfg := new(config)
	err := gcfg.ReadFileInto(cfg, *configFile)
	if err != nil {
		fmt.Println("Config Error: ", err)
		os.Exit(1)
	}

	l, err := net.Listen("tcp", "127.0.0.1:23232")
	if err != nil {
		panic(err)
	}

	lmi := logmein.NewLMI(cfg.RSS.ProfileID, cfg.RSS.Key)

	svr := &lmiServer{
		logmein:              lmi,
		regexpSet:            make(map[string]*regexp.Regexp),
		hostIDSubscribers:    make(map[uint64][]chan<- *logmein.Computer),
		nameMatchSubscribers: make(map[*regexp.Regexp][]chan<- *logmein.Computer),
		ipMatchSubscribers:   make(map[string][]chan<- *logmein.Computer),
	}

	grpcServer := grpc.NewServer()
	lmifeedr.RegisterLMIFeedrServer(grpcServer, svr)
	go func() { panic(grpcServer.Serve(l)) }()

	recv := make(chan *logmein.Computer)
	stop := make(chan struct{})
	go lmi.Watch(recv, stop, false)

	for {
		svr.processComputer(<-recv)
	}
}