コード例 #1
0
ファイル: FWSAdapter.go プロジェクト: sajeetharan/v6engine
func Attach(serverClass string) {

	agentConfig, err := config.GetMap("agent")

	if err == nil {
		client, err := NewFWSClient(agentConfig["cebUrl"].(string))

		if err == nil {

			if client == nil {
				fmt.Println("CLIENT IS NIL")
			}

			client.Resources["client"] = client

			client.Subscribe("command", "switch", Switch)
			client.Subscribe("command", "globalconfigrecieved", GlobalConfigRecieved)
			client.Subscribe("command", "getinfo", GetInfo)

			registerConfig(client)

			client.Register(serverClass+"@"+common.GetLocalHostName(), "1234")

			//forever := make(chan bool)
			//<-forever
		} else {
			fmt.Println("TCP Connection Error : " + err.Error())
		}
	} else {
		fmt.Println("Error retrieving agent configuration : " + err.Error())
	}

}
コード例 #2
0
ファイル: agent.go プロジェクト: sajeetharan/v6engine
func main() {

	data, err := ioutil.ReadFile("./agent.config")

	if err == nil {
		var settings map[string]interface{}
		settings = make(map[string]interface{})
		err := json.Unmarshal(data, &settings)

		if err == nil {

			a := &core.Agent{}

			c, err := fws.NewFWSClient(settings["cebUrl"].(string))
			if err == nil {
				c.Resources["agent"] = a
				c.Resources["client"] = c

				a.Client = c

				if c == nil {
					fmt.Println("CLIENT IS NIL")
				}

				a.Client.Subscribe("command", "switch", commands.AgentSwitch)
				a.Client.Subscribe("command", "getinfo", commands.GetInfo)

				registerCommands(a)
				registerConfig(a)
				registerStats(a)

				agentClass := settings["class"].(string)

				a.Client.Register(agentClass+"@"+common.GetLocalHostName(), "1234")

				forever := make(chan bool)
				<-forever
			} else {
				fmt.Println("TCP Connection Error : " + err.Error())
			}

		} else {
			fmt.Println("Configuration file is not in correct JSON format : " + err.Error())
		}

	} else {
		fmt.Println("Error accessing configuration file ./agent.config : " + err.Error())
	}

}
コード例 #3
0
ファイル: agentFactory.go プロジェクト: sajeetharan/v6engine
func New(agentClass string, callback func(s bool))(err error){

	data, err := ioutil.ReadFile("./agent.config")

	if err == nil {
		var settings map[string]interface{}
		settings = make(map[string]interface{})
		err := json.Unmarshal(data, &settings)

		if err == nil {

			a := &core.Agent{}
			agentInstance = a;
			c, err := ceb.NewCEBClient(settings["cebUrl"].(string), func (s bool){
				if (a.Client.CanMonitorOutput){
					term.AddPlugin(AgentLogger{})
				}
				callback(s)	
			})
			if err == nil {
				c.Resources["agent"] = a
				c.Resources["client"] = c

				a.Client = c

				if c == nil {
					fmt.Println("CLIENT IS NIL")
				}

				a.Client.OnCommand("switch", commands.AgentSwitch)
				a.Client.OnCommand("getinfo", commands.GetInfo)
				a.Client.OnCommand("applyconfig", commands.ApplyConfig)
				

				registerCommands(a)
				registerConfig(a)

				if (settings["showResourceStats"]!=nil){
					if (settings["showResourceStats"].(bool) == true){
						registerStats(a)
					}
				}

				if (settings["canMonitorOutput"]!=nil){
					if (settings["canMonitorOutput"].(bool) == true){
						a.Client.CanMonitorOutput = true;
					}
				}

				if agentClass == ""{
					agentClass = settings["class"].(string)	
				}
				

				a.Client.Register(agentClass+"@"+common.GetLocalHostName(), "1234")

			} else {
				fmt.Println("TCP Connection Error : " + err.Error())
			}

		} else {
			fmt.Println("Configuration file is not in correct JSON format : " + err.Error())
		}

	} else {
		fmt.Println("Error accessing configuration file ./agent.config : " + err.Error())
	}
	
	return 
}