Skip to content

Commit c10c376

Browse files
committed
Add NLS description discovery for mqmetric (issue #46)
1 parent 6f8a53a commit c10c376

File tree

3 files changed

+88
-11
lines changed

3 files changed

+88
-11
lines changed

ibmmq/mqi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,9 @@ func (object MQObject) Set(goSelectors map[int32]interface{}) error {
837837
v := goSelectors[s]
838838
// Force the returned value from the map to be int32 because we
839839
// can't check it at compile time.
840-
if _,ok := v.(int32);ok {
840+
if _, ok := v.(int32); ok {
841841
vv = v.(int32)
842-
} else if _,ok := v.(int);ok {
842+
} else if _, ok := v.(int); ok {
843843
vv = int32(v.(int))
844844
}
845845
intAttrs[intAttr] = vv

mqmetric/discover.go

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ import (
4444

4545
// MonElement describes the real metric element generated by MQ
4646
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
5253
}
5354

5455
// MonType describes the "types" of data generated by MQ. Each class generates
@@ -89,11 +90,20 @@ const maxBufSize = 100 * 1024 * 1024 // 100 MB
8990
var Metrics AllMetrics
9091

9192
var qList []string
93+
var locale string
9294

9395
func GetDiscoveredQueues() []string {
9496
return qList
9597
}
9698

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+
97107
/*
98108
DiscoverAndSubscribe does all the work of finding the
99109
different resources available from a queue manager and
@@ -284,6 +294,70 @@ func discoverElements(ty *MonType) error {
284294
return err
285295
}
286296

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+
287361
/*
288362
Discover the complete set of available statistics in the queue manager
289363
by working through the classes, types and individual elements.
@@ -312,6 +386,9 @@ func discoverStats(metaPrefix string) error {
312386
if err == nil {
313387
for _, ty := range cl.Types {
314388
err = discoverElements(ty)
389+
if err == nil && locale != "" {
390+
err = discoverElementsNLS(ty, locale)
391+
}
315392
}
316393
}
317394
}

samples/amqsset.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ var object ibmmq.MQObject
4444
* This is an example of how to call MQSET
4545
*/
4646
func setAttributes(obj ibmmq.MQObject) {
47-
// Create a map containing the selectors and their values. The values must be
47+
// Create a map containing the selectors and their values. The values must be
4848
// a string (for MQCA attributes) or an int/int32 for the MQIA values.
4949

5050
// The value being set in the TRIGDATA attribute has a timestamp so you can
5151
// see if it is successfully changed
5252
selectors := map[int32]interface{}{
53-
ibmmq.MQIA_INHIBIT_PUT: ibmmq.MQQA_PUT_INHIBITED,
54-
ibmmq.MQIA_TRIGGER_CONTROL: ibmmq.MQTC_ON,
53+
ibmmq.MQIA_INHIBIT_PUT: ibmmq.MQQA_PUT_INHIBITED,
54+
ibmmq.MQIA_TRIGGER_CONTROL: ibmmq.MQTC_ON,
5555
ibmmq.MQCA_TRIGGER_DATA: "Data set at " + time.Now().Format(time.RFC3339)}
5656

57-
// And call the MQI
57+
// And call the MQI
5858
err := obj.Set(selectors)
5959
if err != nil {
6060
fmt.Println(err)

0 commit comments

Comments
 (0)