|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "io" |
4 | 5 | "net/http"
|
5 | 6 | "os"
|
6 | 7 | "os/signal"
|
@@ -45,6 +46,25 @@ func init() {
|
45 | 46 | rootLoggerCtx.Infof("version %s, build reversion %s, build branch %s, build at %s on host %s", Version, BuildRevision, BuildBranch, BuildTime, hostname)
|
46 | 47 | }
|
47 | 48 |
|
| 49 | +func reloadHandler(configLoggerCtx *alog.Entry) http.HandlerFunc { |
| 50 | + return func(w http.ResponseWriter, r *http.Request) { |
| 51 | + if r.Method == "POST" || r.Method == "PUT" { |
| 52 | + configLoggerCtx.Info("Triggered configuration reload from /-/reload HTTP endpoint") |
| 53 | + err := sc.ReloadConfig(*configFile) |
| 54 | + if err != nil { |
| 55 | + configLoggerCtx.WithError(err).Error("failed to reload config file") |
| 56 | + http.Error(w, "failed to reload config file", http.StatusInternalServerError) |
| 57 | + } |
| 58 | + configLoggerCtx.WithField("operation", "sc.ReloadConfig").Info("config file reloaded") |
| 59 | + |
| 60 | + w.WriteHeader(http.StatusOK) |
| 61 | + io.WriteString(w, "Configuration reloaded successfully!") |
| 62 | + } else { |
| 63 | + http.Error(w, "Only PUT and POST methods are allowed", http.StatusBadRequest) |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | + |
48 | 68 | // define new http handleer
|
49 | 69 | func metricsHandler() http.HandlerFunc {
|
50 | 70 | return func(w http.ResponseWriter, r *http.Request) {
|
@@ -136,7 +156,8 @@ func main() {
|
136 | 156 | }
|
137 | 157 | }()
|
138 | 158 |
|
139 |
| - http.Handle("/redfish", metricsHandler()) // Regular metrics endpoint for local Redfish metrics. |
| 159 | + http.Handle("/redfish", metricsHandler()) // Regular metrics endpoint for local Redfish metrics. |
| 160 | + http.Handle("/-/reload", reloadHandler(configLoggerCtx)) // HTTP endpoint for triggering configuration reload |
140 | 161 | http.Handle("/metrics", promhttp.Handler())
|
141 | 162 |
|
142 | 163 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
0 commit comments