Exemple #1
0
func Switch(from string, name string, data map[string]interface{}, resources map[string]interface{}) {

	if logger == nil {
		logger = &FWSLogger{}
	}

	client := resources["client"].(*FWSClient)

	fmt.Println(data)

	var attrib = data["state"].(string)

	if attrib == "on" {
		client.ListenerName = from
		fmt.Println("LOG Monitor Turned ON")
		term.AddPlugin(logger)

	} else if attrib == "off" {
		client.ListenerName = ""
		fmt.Println("LOG Monitor Turned OFF")
		term.RemovePlugin(logger)
	}
}
Exemple #2
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 
}