func configureLogger() log.Logger {
	level := configParameters["nagios2opsgenie.logger"]
	var logFilePath = parameters["logPath"]

	if len(logFilePath) == 0 {
		logFilePath = "/var/log/opsgenie/nagios2opsgenie.log"
	}

	var tmpLogger log.Logger

	file, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)

	if err != nil {
		fmt.Println("Could not create log file \""+logFilePath+"\", will log to \"/tmp/nagios2opsgenie.log\" file. Error: ", err)

		fileTmp, errTmp := os.OpenFile("/tmp/nagios2opsgenie.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)

		if errTmp != nil {
			fmt.Println("Logging disabled. Reason: ", errTmp)
		} else {
			tmpLogger = golog.New(fileTmp, levels[strings.ToLower(level)])
		}
	} else {
		tmpLogger = golog.New(file, levels[strings.ToLower(level)])
	}

	return tmpLogger
}
Пример #2
0
func getLogger() l.Logger {
	if logger != nil {
		return logger
	}
	logger = golog.New(os.Stderr, getLevel(os.Getenv("LOG")))
	return logger
}
Пример #3
0
// GetFromFlags returns the logger defined by the command-line flags. This
// function runs flag.Parse() if it has not been run yet.
func GetFromFlags() log.Logger {
	if logger != nil {
		return logger
	}
	if !flag.Parsed() {
		flag.Parse()
	}

	threshold := getLevelFromName(*thresholdName)
	thresholdName = nil

	out := getStream(*logToStderr)
	logToStderr = nil

	flushThreshold := getLevelFromName(*flushThresholdName)
	flushThresholdName = nil

	if flushThreshold == log.None {
		logger = golog.New(out, threshold)
	} else {
		logger = buflog.New(out, threshold, flushThreshold)
	}

	return logger
}
func configureLogger() log.Logger {
	level := configParameters["zenoss2opsgenie.logger"]
	file, err := os.OpenFile("/var/log/opsgenie/zenoss2opsgenie.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	if err != nil {
		fmt.Println("Logging disabled. Reason: ", err)
	}

	return golog.New(file, levels[strings.ToLower(level)])
}
Пример #5
0
// New creates a new Logger. The out variable sets the destination to which
// log data will be written. The threshold variable defines the level under
// which logging will be ignored. The flushThreshold variable defines the
// level above which logging will be output.
func New(out io.Writer, threshold log.Level, flushThreshold log.Level) *Logger {
	logger := &Logger{
		Logger: golog.New(out, threshold),
		flush:  flushThreshold,
		buffer: bufio.NewWriter(out),
	}
	replaceWriter(logger)

	return logger
}
Пример #6
0
func main() {
	flagDebug := flag.Bool("debug", false, "enable debug logging")
	flagBindInterface := flag.String("listen-interface", "127.0.0.1", "interface to bind to")
	flag.Parse()

	logger = golog.New(os.Stderr, log.Info)
	if *flagDebug {
		logger.Info("enabling debug")
		logger = golog.New(os.Stderr, log.Debug)
	}

	irckit.SetLogger(logger)
	socket, err := net.Listen("tcp", *flagBindInterface+":6667")
	if err != nil {
		logger.Errorf("Failed to listen on socket: %v\n", err)
	}
	defer socket.Close()

	start(socket)
}
Пример #7
0
func init() {
	// Set a default null logger
	var b bytes.Buffer
	SetLogger(golog.New(&b, log.Debug))
}
Пример #8
0
func init() {
	logger = golog.New(os.Stderr, log.Info)
}
Пример #9
0
func main() {
	logger := golog.New(os.Stderr, log.Debug)
	//	http.Handle("/", http.FileServer(&assetfs.AssetFS{
	//		Asset:     Asset,
	//		AssetDir:  AssetDir,
	//		AssetInfo: AssetInfo,
	//		Prefix:    "asset/html"}))

	http.Handle("/", http.FileServer(http.Dir("asset/html")))

	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		logger.Error("Listen:", err)
		return
	}

	fmt.Println(ln.Addr().String())

	thrust.SetProvisioner(ThrustProvisioner{})
	thrust.InitLogger()
	thrust.Start()

	win := thrust.NewWindow(thrust.WindowOptions{
		HasFrame: true,
		RootUrl:  fmt.Sprintf("http://%s/", ln.Addr().String()),
	})
	win.Show()
	win.OpenDevtools()
	win.SetTitle("GVRTool")
	win.Focus()

	rpc, err := thrustrpc.NewRpc(win, logger)
	if err != nil {
		panic(err)
	}

	rpc.Register("add", func(arg []int) (int, error) {
		fmt.Println("add for", arg)
		sum := 0
		for _, v := range arg {
			sum += v
		}
		return sum, nil
	})

	_, err = win.HandleEvent("closed", func(er thrustcmd.EventResult, this *thrustwin.Window) {
		thrust.Exit()
	})

	if err != nil {
		fmt.Println(err)
		thrust.Exit()
	}

	go func() {
		counter := uint32(0)
		for {
			time.Sleep(time.Second)
			rpc.Call("setCounter", counter, time.Millisecond*200)
			counter++
		}
	}()

	http.Serve(ln, nil)
}
Пример #10
0
func main() {
	options := Options{}
	parser := flags.NewParser(&options, flags.Default)
	p, err := parser.Parse()
	if err != nil {
		if p == nil {
			fmt.Print(err)
		}
		os.Exit(1)
		return
	}

	if options.Pprof != 0 {
		go func() {
			fmt.Println(http.ListenAndServe(fmt.Sprintf("localhost:%d", options.Pprof), nil))
		}()
	}

	// Figure out the log level
	numVerbose := len(options.Verbose)
	if numVerbose > len(logLevels) {
		numVerbose = len(logLevels) - 1
	}

	logLevel := logLevels[numVerbose]
	sshchat.SetLogger(golog.New(os.Stderr, logLevel))

	if logLevel == log.Debug {
		// Enable logging from submodules
		chat.SetLogger(os.Stderr)
		sshd.SetLogger(os.Stderr)
	}

	privateKeyPath := options.Identity
	if strings.HasPrefix(privateKeyPath, "~/") {
		user, err := user.Current()
		if err == nil {
			privateKeyPath = strings.Replace(privateKeyPath, "~", user.HomeDir, 1)
		}
	}

	privateKey, err := ReadPrivateKey(privateKeyPath)
	if err != nil {
		fail(2, "Couldn't read private key: %v\n", err)
	}

	signer, err := ssh.ParsePrivateKey(privateKey)
	if err != nil {
		fail(3, "Failed to parse key: %v\n", err)
	}

	auth := sshchat.NewAuth()
	config := sshd.MakeAuth(auth)
	config.AddHostKey(signer)

	s, err := sshd.ListenSSH(options.Bind, config)
	if err != nil {
		fail(4, "Failed to listen on socket: %v\n", err)
	}
	defer s.Close()
	s.RateLimit = sshd.NewInputLimiter

	fmt.Printf("Listening for connections on %v\n", s.Addr().String())

	host := sshchat.NewHost(s, auth)
	host.SetTheme(message.Themes[0])

	err = fromFile(options.Admin, func(line []byte) error {
		key, _, _, _, err := ssh.ParseAuthorizedKey(line)
		if err != nil {
			return err
		}
		auth.Op(key, 0)
		return nil
	})
	if err != nil {
		fail(5, "Failed to load admins: %v\n", err)
	}

	err = fromFile(options.Whitelist, func(line []byte) error {
		key, _, _, _, err := ssh.ParseAuthorizedKey(line)
		if err != nil {
			return err
		}
		auth.Whitelist(key, 0)
		return nil
	})
	if err != nil {
		fail(6, "Failed to load whitelist: %v\n", err)
	}

	if options.Motd != "" {
		motd, err := ioutil.ReadFile(options.Motd)
		if err != nil {
			fail(7, "Failed to load MOTD file: %v\n", err)
		}
		motdString := strings.TrimSpace(string(motd))
		// hack to normalize line endings into \r\n
		motdString = strings.Replace(motdString, "\r\n", "\n", -1)
		motdString = strings.Replace(motdString, "\n", "\r\n", -1)
		host.SetMotd(motdString)
	}

	if options.Log == "-" {
		host.SetLogging(os.Stdout)
	} else if options.Log != "" {
		fp, err := os.OpenFile(options.Log, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			fail(8, "Failed to open log file for writing: %v", err)
		}
		host.SetLogging(fp)
	}

	go host.Serve()

	// Construct interrupt handler
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, os.Interrupt)

	<-sig // Wait for ^C signal
	fmt.Fprintln(os.Stderr, "Interrupt signal detected, shutting down.")
	os.Exit(0)
}