Fix http server addr format

This commit is contained in:
Holger Obermaier 2023-09-15 14:12:59 +02:00
parent aac475fc98
commit baa45b833b
2 changed files with 11 additions and 3 deletions

View File

@ -54,15 +54,22 @@ func (r *HttpReceiver) Init(name string, config json.RawMessage) error {
if !strings.HasPrefix(p, "/") {
p = "/" + p
}
uri := fmt.Sprintf("%s:%s%s", r.config.Addr, r.config.Port, p)
cclog.ComponentDebug(r.name, "INIT", uri)
addr := fmt.Sprintf("%s:%s", r.config.Addr, r.config.Port)
uri := addr + p
cclog.ComponentDebug(r.name, "INIT", "listen on:", uri)
r.handler = influx.NewMetricHandler()
r.parser = influx.NewParser(r.handler)
r.parser.SetTimeFunc(DefaultTime)
// Create new router and register p as path
r.router = mux.NewRouter()
r.router.Path(p).HandlerFunc(r.ServerHttp)
r.server = &http.Server{Addr: uri, Handler: r.router}
// Create http server, with router as handler
r.server = &http.Server{
Addr: addr,
Handler: r.router,
}
return nil
}

View File

@ -11,6 +11,7 @@ import (
)
var AvailableReceivers = map[string]func(name string, config json.RawMessage) (Receiver, error){
"http": NewHttpReceiver,
"ipmi": NewIPMIReceiver,
"nats": NewNatsReceiver,
"redfish": NewRedfishReceiver,