Example #1
0
func main() {
	gob.Register(map[string]interface{}{})
	if len(os.Args) < 2 {
		os.Exit(1)
	}
	jsonString := os.Args[4]

	serverAddress := fmt.Sprintf("%s:%s", os.Args[1], os.Args[2])
	Config.InitClientConfig("clientConfig.gcfg")
	rpcClient := Outgoing.NewRPCInterface(serverAddress)
	if rpcClient == nil {
		panic(errors.New("Can not create RPC Client"))
	}
	rpcClient.Connect()

	result, err := rpcClient.MakeCall(os.Args[3], []byte(jsonString))
	if err != nil {
		panic(err)
	}
	rpcClient.Disconnect()
	result.Messages = append(result.Messages, Module.Message{Severity: "debug", Message: fmt.Sprintf("This event was sent over rpc: %s", result.Event), Source: "RPC Module"})
	jsonBytes, err := json.Marshal(result)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%s", jsonBytes)
}
Example #2
0
//Client starts a example client
func Client(configPath, cpuProfile string) {

	if cpuProfile != "" {
		f, err := os.Create(cpuProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	Config.InitClientConfig(configPath)

	var logger *Logging.Client
	logger, err := Logging.NewClientOwnName(Config.GetClientConfig().LogServer.RPCInterface, "Nagios Client")
	if err != nil {
		fmt.Println("using local logger")
		logger = Logging.NewLocalClient()
	}

	eventRPC := Outgoing.NewRPCInterface(Config.GetClientConfig().Backend.RPCInterface)
	err = eventRPC.Connect()
	if err != nil {
		logger.Error(err)
		os.Exit(2)
	}

	delayed(eventRPC, 10)
	delayed(eventRPC, 1)

	logger.Debug("Start")
	useLivestatus(logger, eventRPC)
	//multipleEvents(eventRPC)
	logger.Debug("Fertig")
	logger.Disconnect()
	eventRPC.Disconnect()
}
Example #3
0
//Server start a server config depending on the config file
func Server(serverConfigPath, clientConfigPath, cpuProfile string) {
	gob.Register(map[string]interface{}{})
	if cpuProfile != "" {
		f, err := os.Create(cpuProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
	}
	Config.InitServerConfig(serverConfigPath)
	Config.InitClientConfig(clientConfigPath)

	stoppables := []Stoppable{}

	rpcInterfaces := []string{}
	httpInterfaces := []string{}

	if Config.GetServerConfig().LogServer.Enabled {
		logServer := LogServer.NewLogServer()
		logServer.Start()
		stoppables = append(stoppables, logServer)
		fmt.Println("Starting: LogServer")
		if Config.GetServerConfig().LogServer.RPCInterface != "" {
			fmt.Println("Starting: LogServer - RPC Interface")
			logServerRPCI := rpcIncoming.NewLogServerRPCInterface(logServer.LogQueue)
			logServerRPCI.Start()
			stoppables = append(stoppables, logServerRPCI)
			rpcInterfaces = append(rpcInterfaces, Config.GetServerConfig().LogServer.RPCInterface)
		}
		if Config.GetServerConfig().LogServer.HTTPInterface != "" {
			fmt.Println("Starting: LogServer - HTTP Interface")
			logServerRPCI := httpIncoming.NewLogServerHTTPInterface(logServer.InfluxClient)
			logServerRPCI.Start()
			stoppables = append(stoppables, logServerRPCI)
			httpInterfaces = append(httpInterfaces, Config.GetServerConfig().LogServer.HTTPInterface)
		}
		time.Sleep(time.Duration(100) * time.Millisecond)
	}

	if Config.GetServerConfig().RuleSystem.Enabled {
		ruleSystem := RuleSystem.NewRuleSystem()
		ruleSystem.Start()
		stoppables = append(stoppables, ruleSystem)
		fmt.Println("Starting: RuleSystem")
		if Config.GetServerConfig().RuleSystem.RPCInterface != "" {
			fmt.Println("Starting: RuleSystem - RPC Interface")
			ruleSystemRPCI := rpcIncoming.NewRuleSystemRPCInterface(ruleSystem)
			if !Strings.Contains(rpcInterfaces, Config.GetServerConfig().RuleSystem.RPCInterface) {
				fmt.Println("Starting: RPC")
				ruleSystemRPCI.Start()
				stoppables = append(stoppables, ruleSystemRPCI)
			}
		}
	}

	if Config.GetServerConfig().Proxy.Enabled {
		fmt.Println("Starting: Proxy - RPC Interface")
		proxyRPCI := rpcIncoming.NewProxyRPCInterface()
		if !Strings.Contains(rpcInterfaces, Config.GetServerConfig().RuleSystem.RPCInterface) {
			fmt.Println("Starting: RPC")
			proxyRPCI.Start()
			stoppables = append(stoppables, proxyRPCI)
		}
	}

	interruptChannel := make(chan os.Signal, 1)
	signal.Notify(interruptChannel, syscall.SIGINT)
	signal.Notify(interruptChannel, syscall.SIGTERM)
	quit := make(chan bool)
	go func() {
		<-interruptChannel
		cleanUp(stoppables)
		quit <- true
	}()
	fmt.Println("Everything's ready!")
	//wait for the end to come
	<-quit
	if cpuProfile != "" {
		pprof.StopCPUProfile()
	}
	fmt.Println("Bye")
}