@@ -140,7 +140,7 @@ func main() {
140140 discoverConfig .MetaPrefix = config .cf .MetaPrefix
141141 err = mqmetric .DiscoverAndSubscribe (discoverConfig )
142142 e := mqmetric .RediscoverAttributes (ibmmq .MQOT_CHANNEL , config .cf .MonitoredChannels )
143- e = mqmetric .RediscoverAttributes (mqmetric .OT_CHANNEL_MQTT , config .cf .MonitoredMQTTChannels )
143+ _ = mqmetric .RediscoverAttributes (mqmetric .OT_CHANNEL_MQTT , config .cf .MonitoredMQTTChannels )
144144
145145 log .Debugf ("Returned from RediscoverAttributes with error %v tempErr %v" , err , e )
146146 }
@@ -205,16 +205,67 @@ func main() {
205205 }
206206}
207207
208+ // Experimenting ...
209+ // See https://github.com/prometheus/exporter-toolkit/blob/master/web/handler.go
210+ // for an example of how we might add authentication via Basic Auth in here.
211+ //
212+ // This function lets us chain handlers, inserting our own processing on the way
213+ // before the prometheus handler does any work.
214+ // The basic_auth block in the prometheus engine yaml gives us a plaintext password that
215+ // can be crypted/hashed and compared to what's in a local config store. If it's OK, then
216+ // pass the request on to the real processor. Otherwise fail with a suitable HTTP code and
217+ // response. Since this is called on every scrape, we'd want to cache the results of the crypt.
218+ /*
219+ func myHandler(next http.HandlerFunc) http.HandlerFunc {
220+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
221+ authOK := true
222+ u, p, auth := r.BasicAuth()
223+ // log.Infof(" U: %s P: %s A:%v", u, p, auth)
224+ //log.Infof("Handler headers: %v", r.Header)
225+ //authHeader, ok := r.Header["Authorization"]
226+ //if ok {
227+ // log.Infof("Auth header: %s", authHeader)
228+ //} else {
229+ // log.Infof("Auth header: %s", "N/A")
230+ //}
231+ if auth {
232+ authOK = validateUP(u, p)
233+ }
234+
235+ if authOK {
236+ next.ServeHTTP(w, r)
237+ } else {
238+ w.Header().Set("WWW-Authenticate", "Basic")
239+ http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
240+ }
241+ })
242+ }
243+ // A rather simplistic validator!
244+ func validateUP(u string, p string) bool {
245+ rc := true
246+ if u != "user" || p != "password" {
247+ rc = false
248+ }
249+
250+ return rc
251+ }
252+ */
253+
208254func startServer () {
209255 var err error
210256 // This function starts a new thread to handle the web server that will then run
211257 // permanently and drive the exporter callback that processes the metric messages
212258
213259 // Need to wait until signalled by the main thread that it's setup the gauges
214260 log .Debug ("HTTP server - waiting until MQ connection ready" )
261+
262+ //myHandlerFunc := myHandler(promhttp.Handler().(http.HandlerFunc))
263+
215264 <- startChannel
216265
217266 http .Handle (config .httpMetricPath , promhttp .Handler ())
267+ //http.Handle(config.httpMetricPath, myHandlerFunc)
268+
218269 http .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
219270 w .Write (landingPage ())
220271 })
0 commit comments