示例#1
0
文件: main.go 项目: barrowkwan/recon
func main() {
	log.SetPrefix("recond: ")

	var marksmanAddr = flag.String("marksman", "http://localhost:3000", "address of the marksman server")
	flag.Parse()

	conf, err := config.Init()
	if err != nil {
		log.Fatalln(err)
	}

	// agent represents a single agent on which the recond
	// is running.
	var agent = &Agent{
		UID: conf.UID,
	}

	err = agent.register(*marksmanAddr)
	if err != nil {
		log.Fatalln(err)
	}

	defer natsEncConn.Close()

	natsEncConn.Subscribe(agent.UID, func(s string) {
		fmt.Printf("Received a message: %s\n", s)
	})

	natsEncConn.Subscribe(agent.UID+"_policy", func(subj, reply string, p *policy.Policy) {
		fmt.Printf("Received a Policy: %v\n", p)
		err := p.Execute()
		natsEncConn.Publish(reply, err)
	})

	c := time.Tick(updateInterval)
	for now := range c {
		log.Println("Update sent at", now)
		agent.update()
	}
}
示例#2
0
func main() {
	log.SetPrefix("recond: ")

	flag.Parse()

	conf, err := config.Init()
	if err != nil {
		log.Fatalln(err)
	}

	// agent represents a single agent on which the recond
	// is running.
	var agent = &Agent{
		UID:      conf.UID,
		HostName: conf.HostName,
	}

	err = agent.register(*flagMarksmanAddr)
	if err != nil {
		log.Fatalln(err)
	}

	defer natsEncConn.Close()

	if err := addSystemDataPolicy(conf); err != nil {
		log.Fatal(err)
	}

	go runStoredPolicies(conf)

	natsEncConn.Subscribe(agent.UID+"_add_policy", AddPolicyHandler(conf))
	natsEncConn.Subscribe(agent.UID+"_delete_policy", DeletePolicyHandler(conf))
	natsEncConn.Subscribe(agent.UID+"_modify_policy", ModifyPolicyHandler(conf))

	// this is just to block the main function from exiting
	c := make(chan struct{})
	<-c
}