Esempio n. 1
0
func TestRenderSnippetFailedTemplate(t *testing.T) {
	engine := &NxConfig{
		Context:  context.NewContext(),
		Snippets: []nxsnippet{{name: "test-snippet", value: "{{non valid template}}"}},
	}

	result := engine.Render()

	expect := "{{non valid template}}\n"
	if !strings.Contains(string(result), expect) {
		t.Fail()
	}
}
Esempio n. 2
0
func TestRenderSnippetTemplate(t *testing.T) {
	engine := &NxConfig{
		Context:  context.NewContext(),
		Snippets: []nxsnippet{{name: "test-snippet", value: "{{.Version}}"}},
	}

	result := engine.Render()

	expect := common.CollectorVersion + "\n"
	if !strings.Contains(string(result), expect) {
		t.Fail()
	}
}
Esempio n. 3
0
func TestRenderSingleSnippet(t *testing.T) {
	engine := &NxConfig{
		Context:  context.NewContext(),
		Snippets: []nxsnippet{{name: "test-snippet", value: "snippet-data"}},
	}

	result := engine.Render()

	expect := "snippet-data\n"
	if !strings.Contains(string(result), expect) {
		t.Fail()
	}
}
Esempio n. 4
0
func main() {
	if commandLineSetup() {
		return
	}

	// setup system service
	serviceConfig := &service.Config{
		Name:        daemon.Daemon.Name,
		DisplayName: daemon.Daemon.DisplayName,
		Description: daemon.Daemon.Description,
	}

	supervisor := daemon.Daemon.NewSupervisor()
	s, err := service.New(supervisor, serviceConfig)
	if err != nil {
		log.Fatalf("Operating system is not supported: %s", err)
	}
	supervisor.BindToService(s)

	if len(*serviceParam) != 0 {
		err := service.Control(s, *serviceParam)
		if err != nil {
			log.Info("Valid service actions:\n", service.ControlAction)
			log.Fatal(err)
		}
		return
	}

	// initialize application context
	context := context.NewContext()
	err = context.LoadConfig(configurationFile)
	if err != nil {
		log.Fatal("Loading configuration file failed.")
	}
	if cfgfile.ValidateConfig() {
		log.Info("Config OK")
		return
	}

	backendSetup(context)

	// start main loop
	services.StartPeriodicals(context)
	err = s.Run()
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 5
0
func TestRenderMultipleSnippets(t *testing.T) {
	engine := &NxConfig{
		Context:  context.NewContext(),
		Snippets: []nxsnippet{{name: "test-snippet1", value: "snippet-data"}},
	}
	addition := &nxsnippet{name: "test-snippet2", value: "data-snippet"}
	engine.Snippets = append(engine.Snippets, *addition)

	result := engine.Render()

	expect1 := "snippet-data\n"
	expect2 := "data-snippet\n"
	if !(strings.Contains(string(result), expect1) && strings.Contains(string(result), expect2)) {
		t.Fail()
	}
}
Esempio n. 6
0
func TestRenderSingleTcpTlsGelfOutputWithAllowUntrust(t *testing.T) {
	engine := &NxConfig{
		Context: context.NewContext(),
		Canned: []nxcanned{{name: "test-tls-gelf-output1", kind: "output-gelf-tcp-tls", properties: map[string]interface{}{
			"server":          "127.0.0.1",
			"port":            "12201",
			"allow_untrusted": true,
		}}},
	}

	result := engine.Render()

	expect1 := "<Output test-tls-gelf-output1>\n"
	expect2 := "AllowUntrusted True\n"
	if !(strings.Contains(string(result), expect1) && strings.Contains(string(result), expect2)) {
		t.Fail()
	}
}
Esempio n. 7
0
func TestRenderTcpTlsGelfOutputWithFields(t *testing.T) {
	engine := &NxConfig{
		Context: context.NewContext(),
		Canned: []nxcanned{{name: "test-tls-gelf-output1", kind: "output-gelf-tcp-tls", properties: map[string]interface{}{
			"server": "127.0.0.1",
			"port":   "12201",
			"fields": map[string]interface{}{"field1": "data", "field2": "data"},
		}}},
	}

	result := engine.Render()

	expect1 := "Exec $field1 = \"data\";\n"
	expect2 := "Exec $field2 = \"data\";\n"
	if !(strings.Contains(string(result), expect1) && strings.Contains(string(result), expect2)) {
		t.Fail()
	}
}
Esempio n. 8
0
func TestRenderMultipleTcpTlsGelfOutputs(t *testing.T) {
	engine := &NxConfig{
		Context: context.NewContext(),
		Canned: []nxcanned{{name: "test-tls-gelf-output1", kind: "output-gelf-tcp-tls", properties: map[string]interface{}{
			"server": "127.0.0.1",
			"port":   "12201",
		}}},
	}
	addition := &nxcanned{name: "test-tls-gelf-output2", kind: "output-gelf-tcp-tls", properties: map[string]interface{}{
		"server": "127.0.0.1",
		"port":   "12201",
	}}
	engine.Canned = append(engine.Canned, *addition)

	result := engine.Render()

	expect1 := "<Output test-tls-gelf-output1>\n"
	expect2 := "<Output test-tls-gelf-output2>\n"
	if !(strings.Contains(string(result), expect1) && strings.Contains(string(result), expect2)) {
		t.Fail()
	}
}