コード例 #1
0
ファイル: ethernet.go プロジェクト: terminiter/earthquake
func runEtherInspector(args []string) int {
	if err := etherFlagset.Parse(args); err != nil {
		log.Critical(err)
		return 1
	}

	useHookSwitch := _etherFlags.NFQNumber < 0

	if useHookSwitch && _etherFlags.HookSwitchZMQAddr == "" {
		log.Critical("hookswitch is invalid")
		return 1
	}
	if !useHookSwitch && _etherFlags.NFQNumber > 0xFFFF {
		log.Critical("nfq-number is invalid")
		return 1
	}

	if _etherFlags.AutopilotConfig != "" && _etherFlags.OrchestratorURL != ocutil.LocalOrchestratorURL {
		log.Critical("non-default orchestrator url set for autopilot orchestration mode")
		return 1
	}

	if _etherFlags.AutopilotConfig != "" {
		cfg, err := config.NewFromFile(_etherFlags.AutopilotConfig)
		if err != nil {
			panic(log.Critical(err))
		}
		autopilotOrchestrator, err := ocutil.NewAutopilotOrchestrator(cfg)
		if err != nil {
			panic(log.Critical(err))
		}
		log.Info("Starting autopilot-mode orchestrator")
		go autopilotOrchestrator.Start()
	}

	var etherInspector inspector.EthernetInspector
	if useHookSwitch {
		etherInspector = &inspector.HookSwitchInspector{
			OrchestratorURL:   _etherFlags.OrchestratorURL,
			EntityID:          _etherFlags.EntityID,
			HookSwitchZMQAddr: _etherFlags.HookSwitchZMQAddr,
			EnableTCPWatcher:  true,
		}
	} else {
		etherInspector = &inspector.NFQInspector{
			OrchestratorURL:  _etherFlags.OrchestratorURL,
			EntityID:         _etherFlags.EntityID,
			NFQNumber:        uint16(_etherFlags.NFQNumber),
			EnableTCPWatcher: true,
		}
	}

	if err := etherInspector.Start(); err != nil {
		panic(log.Critical(err))
	}

	// NOTREACHED
	return 0
}
コード例 #2
0
ファイル: earthquake.go プロジェクト: terminiter/earthquake
func StartOrchestrator(cfg config.Config) error {
	autopilotOrchestrator, err := ocutil.NewAutopilotOrchestrator(cfg)
	if err != nil {
		return err
	}
	autopilotOrchestrator.Start()
	return nil
}
コード例 #3
0
ファイル: fs.go プロジェクト: terminiter/earthquake
func runFsInspector(args []string) int {
	if err := fsFlagset.Parse(args); err != nil {
		log.Critical(err)
		return 1
	}

	if _fsFlags.OriginalDir == "" {
		log.Critical("original-dir is not set")
		return 1
	}

	if _fsFlags.Mountpoint == "" {
		log.Critical("mount-point is not set")
		return 1
	}

	if _fsFlags.AutopilotConfig != "" && _fsFlags.OrchestratorURL != ocutil.LocalOrchestratorURL {
		log.Critical("non-default orchestrator url set for autopilot orchestration mode")
		return 1
	}

	if logutil.Debug {
		// log level: 0..2
		hookfs.SetLogLevel(1)
	} else {
		hookfs.SetLogLevel(0)
	}

	if _fsFlags.AutopilotConfig != "" {
		cfg, err := config.NewFromFile(_fsFlags.AutopilotConfig)
		if err != nil {
			panic(log.Critical(err))
		}
		autopilotOrchestrator, err := ocutil.NewAutopilotOrchestrator(cfg)
		if err != nil {
			panic(log.Critical(err))
		}
		log.Info("Starting autopilot-mode orchestrator")
		go autopilotOrchestrator.Start()
	}

	hook := &inspector.FilesystemInspector{
		OrchestratorURL: _fsFlags.OrchestratorURL,
		EntityID:        _fsFlags.EntityID,
	}

	fs, err := hookfs.NewHookFs(_fsFlags.OriginalDir, _fsFlags.Mountpoint, hook)
	if err != nil {
		panic(log.Critical(err))
	}
	log.Infof("Serving %s", fs)
	log.Infof("Please run `fusermount -u %s` after using this, manually", _fsFlags.Mountpoint)
	if err = fs.Serve(); err != nil {
		panic(log.Critical(err))
	}
	// NOTREACHED
	return 0
}
コード例 #4
0
ファイル: proc.go プロジェクト: terminiter/earthquake
func runProcInspector(args []string) int {
	if err := procFlagset.Parse(args); err != nil {
		log.Critical(err)
		return 1
	}

	if _procFlags.RootPID <= 0 {
		log.Critical("root-pid is not set (or set to non-positive value)")
		return 1
	}

	if _procFlags.AutopilotConfig != "" && _procFlags.OrchestratorURL != ocutil.LocalOrchestratorURL {
		log.Critical("non-default orchestrator url set for autopilot orchestration mode")
		return 1
	}

	if _procFlags.AutopilotConfig != "" {
		cfg, err := config.NewFromFile(_procFlags.AutopilotConfig)
		if err != nil {
			panic(log.Critical(err))
		}
		autopilotOrchestrator, err := ocutil.NewAutopilotOrchestrator(cfg)
		if err != nil {
			panic(log.Critical(err))
		}
		log.Info("Starting autopilot-mode orchestrator")
		go autopilotOrchestrator.Start()
	}
	procInspector := &inspector.ProcInspector{
		OrchestratorURL: _procFlags.OrchestratorURL,
		EntityID:        _procFlags.EntityID,
		RootPID:         _procFlags.RootPID,
		WatchInterval:   _procFlags.WatchInterval,
	}

	if err := procInspector.Start(); err != nil {
		panic(log.Critical(err))
	}

	// NOTREACHED
	return 0
}