Beispiel #1
0
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())
	}

}
Beispiel #2
0
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())
	}

}
Beispiel #3
0
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 
}