Example #1
0
func TestModifiedConfig(t *testing.T) {
	// modify cfgfile's default location
	os.Args = []string{"../tests/redisbeat.yml"}
	cfg.ChangeDefaultCfgfileFlag("redisbeat")

	rb := New()
	err := rb.Config(&beat.Beat{})
	assert.Nil(t, err)

	expectedTime := 5 * time.Second
	assert.Equal(t, expectedTime, rb.period, "Configured time period should be %v", expectedTime)
	assert.Equal(t, "redis.testing.fake", rb.host, "Configured host should be %v", "redis.testing.fake")
	assert.Equal(t, 9736, rb.port, "Configured port should be %v", 9736)
	assert.Equal(t, "udp", rb.network, "Configured network should be %v", "udp")
	assert.Equal(t, 5, rb.maxConn, "Configured max connections should be %v", 5)
	assert.Equal(t, true, rb.auth, "Configured auth required should be %v", true)
	assert.Equal(t, "p@ssw0rd", rb.pass, "Configured auth required pass should be %v", "p@ssw0rd")
	assert.Equal(t, true, rb.serverStats, "Configured server stats should be %v", true)
	assert.Equal(t, false, rb.clientsStats, "Configured client stats should be %v", false)
	assert.Equal(t, false, rb.memoryStats, "Configured memory stats should be %v", false)
	assert.Equal(t, false, rb.persistenceStats, "Configured persistence stats should be %v", false)
	assert.Equal(t, false, rb.statsStats, "Configured stats stats should be %v", false)
	assert.Equal(t, false, rb.replicationStats, "Configured replication stats should be %v", false)
	assert.Equal(t, false, rb.cpuStats, "Configured cpu stats should be %v", false)
	assert.Equal(t, false, rb.commandStats, "Configured command stats should be %v", false)
	assert.Equal(t, false, rb.clusterStats, "Configured cluster stats should be %v", false)
	assert.Equal(t, false, rb.keyspaceStats, "Configured keyspace stats should be %v", false)
}
Example #2
0
func TestDefaultConfig(t *testing.T) {
	// modify cfgfile's default location
	os.Args = []string{"../redisbeat.yaml"}
	cfg.ChangeDefaultCfgfileFlag("redisbeat")

	rb := New()
	err := rb.Config(&beat.Beat{})
	assert.Nil(t, err)

	assert.Equal(t, DEFAULT_PERIOD, rb.period, "Default time period should be %v", DEFAULT_PERIOD)
	assert.Equal(t, DEFAULT_HOST, rb.host, "Default host should be %v", DEFAULT_HOST)
	assert.Equal(t, DEFAULT_PORT, rb.port, "Default port should be %v", DEFAULT_PORT)
	assert.Equal(t, DEFAULT_NETWORK, rb.network, "Default network should be %v", DEFAULT_NETWORK)
	assert.Equal(t, DEFAULT_MAX_CONN, rb.maxConn, "Default max connections should be %v", DEFAULT_MAX_CONN)
	assert.Equal(t, DEFAULT_AUTH_REQUIRED, rb.auth, "Default auth required should be %v", DEFAULT_AUTH_REQUIRED)
	assert.Equal(t, DEFAULT_AUTH_REQUIRED_PASS, rb.pass, "Default auth required pass should be %v", DEFAULT_AUTH_REQUIRED_PASS)
	assert.Equal(t, DEFAULT_STATS_SERVER, rb.serverStats, "Default server stats should be %v", DEFAULT_STATS_SERVER)
	assert.Equal(t, DEFAULT_STATS_CLIENT, rb.clientsStats, "Default client stats should be %v", DEFAULT_STATS_CLIENT)
	assert.Equal(t, DEFAULT_STATS_MEMORY, rb.memoryStats, "Default memory stats should be %v", DEFAULT_STATS_MEMORY)
	assert.Equal(t, DEFAULT_STATS_PERSISTENCE, rb.persistenceStats, "Default persistence stats should be %v", DEFAULT_STATS_PERSISTENCE)
	assert.Equal(t, DEFAULT_STATS_STATS, rb.statsStats, "Default stats stats should be %v", DEFAULT_STATS_STATS)
	assert.Equal(t, DEFAULT_STATS_REPLICATION, rb.replicationStats, "Default replication stats should be %v", DEFAULT_STATS_REPLICATION)
	assert.Equal(t, DEFAULT_STATS_CPU, rb.cpuStats, "Default cpu stats should be %v", DEFAULT_STATS_CPU)
	assert.Equal(t, DEFAULT_STATS_COMMAND, rb.commandStats, "Default command stats should be %v", DEFAULT_STATS_COMMAND)
	assert.Equal(t, DEFAULT_STATS_CLUSTER, rb.clusterStats, "Default cluster stats should be %v", DEFAULT_STATS_CLUSTER)
	assert.Equal(t, DEFAULT_STATS_KEYSPACE, rb.keyspaceStats, "Default keyspace stats should be %v", DEFAULT_STATS_KEYSPACE)
}
Example #3
0
// handleFlags parses the command line flags. It handles the '-version' flag
// and invokes the HandleFlags callback if implemented by the Beat.
func (b *Beat) handleFlags() error {
	// Due to a dependence upon the beat name, the default config file path
	// must be updated prior to CLI flag handling.
	err := cfgfile.ChangeDefaultCfgfileFlag(b.Name)
	if err != nil {
		return fmt.Errorf("failed to set default config file path: %v", err)
	}
	flag.Parse()

	if *printVersion {
		fmt.Printf("%s version %s (%s), libbeat %s\n",
			b.Name, b.Version, runtime.GOARCH, defaultBeatVersion)
		return GracefulExit
	}

	if err := cfgfile.HandleFlags(); err != nil {
		return err
	}
	return handleFlags(b)
}
Example #4
0
// Reads and parses the default command line params
// To set additional cmd line args use the beat.CmdLine type before calling the function
func (beat *Beat) CommandLineSetup() {

	// The -c flag is treated separately because it needs the Beat name
	err := cfgfile.ChangeDefaultCfgfileFlag(beat.Name)
	if err != nil {
		fmt.Printf("Failed to fix the -c flag: %v\n", err)
		os.Exit(1)
	}

	flag.Parse()

	if *printVersion {
		fmt.Printf("%s version %s (%s)\n", beat.Name, beat.Version, runtime.GOARCH)
		os.Exit(0)
	}

	// if beater implements CLIFlags for additional CLI handling, call it now
	if flagsHandler, ok := beat.BT.(FlagsHandler); ok {
		flagsHandler.HandleFlags(beat)
	}
}
Example #5
0
// handleFlags parses the command line flags. It handles the '-version' flag
// and invokes the HandleFlags callback if implemented by the Beat.
func (bc *instance) handleFlags() error {
	// Due to a dependence upon the beat name, the default config file path
	// must be updated prior to CLI flag handling.
	err := cfgfile.ChangeDefaultCfgfileFlag(bc.data.Name)
	if err != nil {
		return fmt.Errorf("failed to set default config file path: %v", err)
	}

	flag.Parse()

	if *printVersion {
		fmt.Printf("%s version %s (%s), libbeat %s\n", bc.data.Name,
			bc.data.Version, runtime.GOARCH, defaultBeatVersion)
		return GracefulExit
	}

	// Invoke HandleFlags if FlagsHandler is implemented.
	if flagsHandler, ok := bc.beater.(FlagsHandler); ok {
		err = flagsHandler.HandleFlags(bc.data)
	}

	return err
}