@@ -21,15 +21,17 @@ package config
2121import (
2222 "errors"
2323 "fmt"
24+ "reflect"
25+ "strconv"
26+
2427 "github.com/rabbitstack/fibratus/pkg/outputs"
2528 "github.com/rabbitstack/fibratus/pkg/outputs/amqp"
2629 "github.com/rabbitstack/fibratus/pkg/outputs/console"
2730 "github.com/rabbitstack/fibratus/pkg/outputs/elasticsearch"
31+ "github.com/rabbitstack/fibratus/pkg/outputs/http"
2832 "github.com/rabbitstack/fibratus/pkg/outputs/null"
2933 log "github.com/sirupsen/logrus"
3034 "golang.org/x/sys/windows/svc"
31- "reflect"
32- "strconv"
3335)
3436
3537var errNoOutputSection = errors .New ("no output section in config" )
@@ -71,8 +73,8 @@ func (c *Config) tryLoadOutput() error {
7173 }
7274
7375 for typ , config := range mapping {
74- switch typ {
75- case "console" :
76+ switch outputs . TypeFromString ( typ ) {
77+ case outputs . Console :
7678 var consoleConfig console.Config
7779 if err := decode (config , & consoleConfig ); err != nil {
7880 return errOutputConfig (typ , err )
@@ -82,7 +84,7 @@ func (c *Config) tryLoadOutput() error {
8284 }
8385 c .Output .Type , c .Output .Output = outputs .Console , consoleConfig
8486
85- case "amqp" :
87+ case outputs . AMQP :
8688 var amqpConfig amqp.Config
8789 if err := decode (config , & amqpConfig ); err != nil {
8890 return errOutputConfig (typ , err )
@@ -92,7 +94,7 @@ func (c *Config) tryLoadOutput() error {
9294 }
9395 c .Output .Type , c .Output .Output = outputs .AMQP , amqpConfig
9496
95- case "elasticsearch" :
97+ case outputs . Elasticsearch :
9698 var esConfig elasticsearch.Config
9799 if err := decode (config , & esConfig ); err != nil {
98100 return errOutputConfig (typ , err )
@@ -101,13 +103,22 @@ func (c *Config) tryLoadOutput() error {
101103 continue
102104 }
103105 c .Output .Type , c .Output .Output = outputs .Elasticsearch , esConfig
106+
107+ case outputs .HTTP :
108+ var httpConfig http.Config
109+ if err := decode (config , & httpConfig ); err != nil {
110+ return errOutputConfig (typ , err )
111+ }
112+ if ! httpConfig .Enabled {
113+ continue
114+ }
115+ c .Output .Type , c .Output .Output = outputs .HTTP , httpConfig
104116 }
105117 }
106118
107119 // if it is not an interactive session but the console output is enabled
108120 // we default to null output and warn about that
109- in , err := svc .IsAnInteractiveSession ()
110- if err == nil && ! in && c .Output .Output != nil {
121+ if isWindowsService () && c .Output .Output != nil {
111122 if c .Output .Type == outputs .Console {
112123 log .Warn ("running in non-interactive session with console output. " +
113124 "Please configure a different output type. Defaulting to null output" )
@@ -135,3 +146,12 @@ func findActiveOutputs(outputs map[string]interface{}) []string {
135146 }
136147 return outputTypes
137148}
149+
150+ // isWindowsService returns true if the process is running inside Windows Service.
151+ func isWindowsService () bool {
152+ interactive , err := svc .IsAnInteractiveSession ()
153+ if err != nil {
154+ return false
155+ }
156+ return ! interactive
157+ }
0 commit comments