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)
}
//ResendEvent sends the selected event to a Rulesystem
func (handler LogServerHTTPHandler) ResendEvent(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
	event := r.FormValue(GETEVENTKEY)
	address := r.FormValue(GETADDRESSKEY)
	page := ""
	if address == "" {
		page = fmt.Sprintf(
			`<form action="%s">
			Where should the event sent be to?
			<input name="%s">
			<input type="hidden" name='%s' value='%s'>
			<input type="submit" value="send">
		</form>
		<pre>
		%s
		</pre>`, r.URL, GETADDRESSKEY, GETEVENTKEY, event, Strings.FormatJSON(event))
	} else {
		eventRPC := Outgoing.NewRPCInterface(address)
		err := eventRPC.Connect()
		if err != nil {
			page = err.Error()
		} else {
			err = eventRPC.CreateEvent([]byte(event))
			if err != nil {
				page = err.Error()
			} else {
				page = "Event was sent"
			}
			eventRPC.Disconnect()
		}

	}
	io.WriteString(w, "<html><body>")
	io.WriteString(w, page)
	io.WriteString(w, "</body></html>")
}
Example #3
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 #4
0
//NewClientOwnName creates a localClient or a RPC if a address is given and uses the given name as source
func NewClientOwnName(target, name string) (*Client, error) {
	if target == "" {
		//use local logger
		return NewLocalClient(), nil
	}
	logLocal := false
	logRPC := Outgoing.NewRPCInterface(target)
	if err := logRPC.Connect(); err != nil {
		fmt.Println(err)
		logLocal = true
	}

	var clientName string
	if name == "" {
		for name := range logRPC.Config.NameToCertificate {
			clientName = name
			break
		}
		if clientName == "" {
			var err error
			clientName, err = os.Hostname()
			if err != nil {
				return nil, err
			}
		}
	} else {
		clientName = name
	}
	err := logRPC.SendMessage(LogServer.NewDebugLogMessage(clientName, clientName+"-connected"))
	if err != nil {
		fmt.Println(err)
		logLocal = true
	}

	return &Client{logRPC: logRPC, name: clientName, localLogger: Local.GetLogger(), logLocal: logLocal}, nil
}