//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() }
//NewRuleFileParser creates a new RuleFileParser, returns an error if the object is not valid func NewRuleFileParser(ruleFile string) (*RuleFileParser, error) { fileReader, err := os.Open(ruleFile) if err != nil { return nil, err } r := csv.NewReader(fileReader) r.TrimLeadingSpace = true r.Comment = '#' r.Comma = ';' records, err := r.ReadAll() if err != nil { return nil, err } lines := []RuleLine{} for _, elements := range records { command, args, err := parseCommand(elements[2]) if err != nil { return nil, err } if len(elements[0]) == 0 && len(elements[1]) == 0 { if len(lines) == 0 { return nil, fmt.Errorf("The first rule can not referance back") } lastRule := lines[len(lines)-1] lines = append(lines, RuleLine{name: lastRule.name, condition: lastRule.condition, command: command, args: args, flags: helper.StringToMap(elements[3], ",", "="), }) } else { lines = append(lines, RuleLine{name: elements[0], condition: elements[1], command: command, args: args, flags: helper.StringToMap(elements[3], ",", "="), }) } } client, err := Logging.NewClientOwnName(Config.GetClientConfig().LogServer.RPCInterface, "RuleSystem") if err != nil { return nil, err } return &RuleFileParser{ruleFile: ruleFile, lines: lines, externalModule: *Module.NewExternalModule(), LogClient: client}, nil }
//NewCollector constructs a new Livestatus Collector func NewCollector(logger Logging.Client, eventCreator Client.EventCreatable) *Collector { connector := Connector{LivestatusAddress: Config.GetClientConfig().Livestatus.Address, ConnectionType: Config.GetClientConfig().Livestatus.Type} converter := newLivestatusResultConverter(LogQuery) return &Collector{conn: connector, quit: make(chan bool), isRunning: false, logger: logger, creator: eventCreator, converter: converter} }
//NewRPCInterface constructs a new RPCInterface func NewRPCInterface(serverAddress string) *RPCInterface { config := TLS.GenerateClientTLSConfig(Config.GetClientConfig().TLS.Cert, Config.GetClientConfig().TLS.Key, Config.GetClientConfig().TLS.CaCert) return &RPCInterface{serverAddress: serverAddress, Config: config} }