@@ -44,11 +44,12 @@ import (
44
44
45
45
// MonElement describes the real metric element generated by MQ
46
46
type MonElement struct {
47
- Parent * MonType
48
- Description string // An English phrase describing the element
49
- MetricName string // Reformatted description suitable as label
50
- Datatype int32
51
- Values map [string ]int64
47
+ Parent * MonType
48
+ Description string // An English phrase describing the element
49
+ DescriptionNLS string // A translated phrase for the current locale
50
+ MetricName string // Reformatted description suitable as label
51
+ Datatype int32
52
+ Values map [string ]int64
52
53
}
53
54
54
55
// MonType describes the "types" of data generated by MQ. Each class generates
@@ -89,11 +90,20 @@ const maxBufSize = 100 * 1024 * 1024 // 100 MB
89
90
var Metrics AllMetrics
90
91
91
92
var qList []string
93
+ var locale string
92
94
93
95
func GetDiscoveredQueues () []string {
94
96
return qList
95
97
}
96
98
99
+ /*
100
+ * A collector can set the locale (eg "Fr_FR") before doing the discovery
101
+ * process to get access to the MQ-translated strings
102
+ */
103
+ func SetLocale (l string ) {
104
+ locale = l
105
+ }
106
+
97
107
/*
98
108
DiscoverAndSubscribe does all the work of finding the
99
109
different resources available from a queue manager and
@@ -284,6 +294,70 @@ func discoverElements(ty *MonType) error {
284
294
return err
285
295
}
286
296
297
+ // Rerun the subscription for elements, but this time adding a locale into the topic
298
+ // so that we can get the translated description. It's up to the collector program to
299
+ // then make use of that description.
300
+ func discoverElementsNLS (ty * MonType , locale string ) error {
301
+ var err error
302
+ var data []byte
303
+ var sub ibmmq.MQObject
304
+
305
+ if locale == "" {
306
+ return nil
307
+ }
308
+
309
+ sub , err = subscribe (ty .elementTopic + "/" + locale )
310
+ if err == nil {
311
+ // Don't wait - if there's nothing on that topic, then get out fast
312
+ data , err = getMessage (false )
313
+ sub .Close (0 )
314
+
315
+ if err != nil {
316
+ mqreturn := err .(* ibmmq.MQReturn )
317
+ if mqreturn .MQRC == ibmmq .MQRC_NO_MSG_AVAILABLE {
318
+ err = nil
319
+ }
320
+ }
321
+
322
+ elemList , _ := parsePCFResponse (data )
323
+
324
+ for i := 0 ; i < len (elemList ); i ++ {
325
+
326
+ if elemList [i ].Type == ibmmq .MQCFT_STRING && elemList [i ].Parameter == ibmmq .MQCA_TOPIC_STRING {
327
+ continue
328
+ }
329
+
330
+ if elemList [i ].Type != ibmmq .MQCFT_GROUP {
331
+ continue
332
+ }
333
+
334
+ group := elemList [i ]
335
+ description := ""
336
+ elementIndex := 0
337
+
338
+ for j := 0 ; j < len (group .GroupList ); j ++ {
339
+ e := group .GroupList [j ]
340
+ switch e .Parameter {
341
+
342
+ case ibmmq .MQIAMO_MONITOR_ELEMENT :
343
+ elementIndex = int (e .Int64Value [0 ])
344
+
345
+ case ibmmq .MQCAMO_MONITOR_DESC :
346
+ description = e .String [0 ]
347
+
348
+ }
349
+ }
350
+
351
+ if description != "" {
352
+ ty .Elements [elementIndex ].DescriptionNLS = description
353
+ fmt .Printf ("Updated element %v\n " , ty .Elements [elementIndex ])
354
+ }
355
+ }
356
+ }
357
+
358
+ return err
359
+ }
360
+
287
361
/*
288
362
Discover the complete set of available statistics in the queue manager
289
363
by working through the classes, types and individual elements.
@@ -312,6 +386,9 @@ func discoverStats(metaPrefix string) error {
312
386
if err == nil {
313
387
for _ , ty := range cl .Types {
314
388
err = discoverElements (ty )
389
+ if err == nil && locale != "" {
390
+ err = discoverElementsNLS (ty , locale )
391
+ }
315
392
}
316
393
}
317
394
}
0 commit comments