Пример #1
0
func (a *Agent) Start() {
	var err error
	// send a first reset event to the analyzers
	a.Graph.DelSubGraph(a.Root)

	addr, port, err := config.GetAnalyzerClientAddr()
	if err != nil {
		logging.GetLogger().Errorf("Unable to parse analyzer client %s", err.Error())
		os.Exit(1)
	}

	if addr != "" {
		a.Gclient = graph.NewAsyncClient(addr, port, "/ws/graph")
		graph.NewForwarder(a.Gclient, a.Graph)
		a.Gclient.Connect()
	}

	a.TopologyProbeBundle = tprobes.NewTopologyProbeBundleFromConfig(a.Graph, a.Root)
	a.TopologyProbeBundle.Start()

	a.FlowProbeBundle = fprobes.NewFlowProbeBundleFromConfig(a.TopologyProbeBundle, a.Graph)
	a.FlowProbeBundle.Start()

	go a.TopologyServer.ListenAndServe()
	go a.GraphServer.ListenAndServe()
}
Пример #2
0
func (a *Agent) Start() {
	var err error

	go a.WSServer.ListenAndServe()

	addr, port, err := config.GetAnalyzerClientAddr()
	if err != nil {
		logging.GetLogger().Errorf("Unable to parse analyzer client %s", err.Error())
		os.Exit(1)
	}

	if addr != "" {
		authOptions := &shttp.AuthenticationOpts{
			Username: config.GetConfig().GetString("agent.analyzer_username"),
			Password: config.GetConfig().GetString("agent.analyzer_password"),
		}
		authClient := shttp.NewAuthenticationClient(addr, port, authOptions)
		a.WSClient, err = shttp.NewWSAsyncClient(addr, port, "/ws", authClient)
		if err != nil {
			logging.GetLogger().Errorf("Unable to instantiate analyzer client %s", err.Error())
			os.Exit(1)
		}

		graph.NewForwarder(a.WSClient, a.Graph)
		a.WSClient.Connect()

		// send a first reset event to the analyzers
		a.Graph.DelSubGraph(a.Root)
	}

	a.TopologyProbeBundle = tprobes.NewTopologyProbeBundleFromConfig(a.Graph, a.Root)
	a.TopologyProbeBundle.Start()

	a.FlowProbeBundle = fprobes.NewFlowProbeBundleFromConfig(a.TopologyProbeBundle, a.Graph)
	a.FlowProbeBundle.Start()

	if addr != "" {
		a.EtcdClient, err = etcd.NewEtcdClientFromConfig()
		if err != nil {
			logging.GetLogger().Errorf("Unable to start etcd client %s", err.Error())
			os.Exit(1)
		}

		captureHandler := &api.BasicApiHandler{
			ResourceHandler: &api.CaptureHandler{},
			EtcdKeyAPI:      a.EtcdClient.KeysApi,
		}

		l, err := fprobes.NewOnDemandProbeListener(a.FlowProbeBundle, a.Graph, captureHandler)
		if err != nil {
			logging.GetLogger().Errorf("Unable to start on-demand flow probe %s", err.Error())
			os.Exit(1)
		}
		a.OnDemandProbeListener = l
		a.OnDemandProbeListener.Start()
	}

	go a.HTTPServer.ListenAndServe()
}
Пример #3
0
func NewRestClientFromConfig(authOptions *AuthenticationOpts) *RestClient {
	addr, port, err := config.GetAnalyzerClientAddr()
	if err != nil {
		logging.GetLogger().Errorf("Unable to parse analyzer client %s", err.Error())
		return nil
	}

	return NewRestClient(addr, port, authOptions)
}
Пример #4
0
func NewFlowProbeBundleFromConfig(tb *probes.TopologyProbeBundle, g *graph.Graph) *FlowProbeBundle {
	list := config.GetConfig().GetStringSlice("agent.flow.probes")

	logging.GetLogger().Infof("Flow probes: %v", list)

	gfe := mappings.NewGraphFlowEnhancer(g)

	var aclient *analyzer.Client

	addr, port, err := config.GetAnalyzerClientAddr()
	if err != nil {
		logging.GetLogger().Errorf("Unable to parse analyzer client: %s", err.Error())
		return nil
	}

	if addr != "" {
		aclient, err = analyzer.NewClient(addr, port)
		if err != nil {
			logging.GetLogger().Errorf("Analyzer client error %s:%d : %s", addr, port, err.Error())
			return nil
		}
	}

	probes := make(map[string]probe.Probe)
	for _, t := range list {
		if _, ok := probes[t]; ok {
			continue
		}

		switch t {
		case "ovssflow":
			ofe := mappings.NewOvsFlowEnhancer(g)
			pipeline := mappings.NewFlowMappingPipeline(gfe, ofe)

			o := NewOvsSFlowProbesHandler(tb, g, pipeline, aclient)
			if o != nil {
				probes[t] = o
			}
		case "pcap":
			pipeline := mappings.NewFlowMappingPipeline(gfe)

			o := NewPcapProbesHandler(tb, g, pipeline, aclient)
			if o != nil {
				probes[t] = o
			}
		default:
			logging.GetLogger().Errorf("unknown probe type %s", t)
		}
	}

	p := probe.NewProbeBundle(probes)

	return &FlowProbeBundle{
		ProbeBundle: *p,
		Graph:       g,
	}
}