Skip to content

Commit 9712a6b

Browse files
committed
mqmetric - add DESCR attribute for channels and queues to permit labelling (ibm-messaging/mq-metric/samples/#16)
1 parent ff54c09 commit 9712a6b

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

mqmetric/channel.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -465,18 +465,21 @@ func inquireChannelAttributes(objectPatternsList string, infoMap map[string]*Obj
465465
cfh.ParameterCount++
466466
buf = append(buf, pcfparm.Bytes()...)
467467

468-
// Add the parameters one at a time into a buffer
469-
pcfparm = new(ibmmq.PCFParameter)
470-
pcfparm.Type = ibmmq.MQCFT_INTEGER
471-
pcfparm.Parameter = ibmmq.MQIACH_CHANNEL_TYPE
472-
pcfparm.Int64Value = []int64{int64(ibmmq.MQCHT_SVRCONN)}
473-
cfh.ParameterCount++
474-
buf = append(buf, pcfparm.Bytes()...)
468+
// The original version of this function was only relevant for SVRCONN channels but DESCR is now being asked
469+
// for which applies to all channel types. It's OK to ask for attributes for the wrong type of channel though;
470+
// they are simply not returned.
471+
472+
//pcfparm = new(ibmmq.PCFParameter)
473+
//pcfparm.Type = ibmmq.MQCFT_INTEGER
474+
//pcfparm.Parameter = ibmmq.MQIACH_CHANNEL_TYPE
475+
//pcfparm.Int64Value = []int64{int64(ibmmq.MQCHT_SVRCONN)}
476+
//cfh.ParameterCount++
477+
//buf = append(buf, pcfparm.Bytes()...)
475478

476479
pcfparm = new(ibmmq.PCFParameter)
477480
pcfparm.Type = ibmmq.MQCFT_INTEGER_LIST
478481
pcfparm.Parameter = ibmmq.MQIACF_CHANNEL_ATTRS
479-
pcfparm.Int64Value = []int64{int64(ibmmq.MQIACH_MAX_INSTANCES), int64(ibmmq.MQIACH_MAX_INSTS_PER_CLIENT)}
482+
pcfparm.Int64Value = []int64{int64(ibmmq.MQIACH_MAX_INSTANCES), int64(ibmmq.MQIACH_MAX_INSTS_PER_CLIENT), int64(ibmmq.MQCACH_DESC)}
480483
cfh.ParameterCount++
481484
buf = append(buf, pcfparm.Bytes()...)
482485

@@ -564,8 +567,18 @@ func parseChannelAttrData(cfh *ibmmq.MQCFH, buf []byte, infoMap map[string]*ObjI
564567
ci.exists = true
565568

566569
}
567-
}
568570

571+
case ibmmq.MQCACH_DESC:
572+
v := elem.String[0]
573+
if v != "" {
574+
if ci, ok = infoMap[chlName]; !ok {
575+
ci = new(ObjInfo)
576+
infoMap[chlName] = ci
577+
}
578+
ci.Description = v
579+
ci.exists = true
580+
}
581+
}
569582
}
570583

571584
return

mqmetric/discover.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type AllMetrics struct {
8686
type ObjInfo struct {
8787
exists bool // Used during rediscovery
8888
firstCollection bool // To indicate discard needed of first stat
89+
Description string
8990
// These are used for queue information
9091
AttrMaxDepth int64 // The queue attribute value. Not the max depth reported by RESET QSTATS
9192
AttrUsage int64 // Normal or XMITQ
@@ -1349,3 +1350,20 @@ func patternMatch(s string, r string) bool {
13491350
// fmt.Printf("Comparing %s with %s %v\n",s,r,rc)
13501351
return rc
13511352
}
1353+
1354+
func GetObjectDescription(key string, objectType int32) string {
1355+
var o *ObjInfo
1356+
ok := false
1357+
switch objectType {
1358+
case ibmmq.MQOT_Q:
1359+
o, ok = qInfoMap[key]
1360+
case ibmmq.MQOT_CHANNEL:
1361+
o, ok = chlInfoMap[key]
1362+
}
1363+
1364+
if ok {
1365+
return o.Description
1366+
} else {
1367+
return ""
1368+
}
1369+
}

mqmetric/queue.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func inquireQueueAttributes(objectPatternsList string) error {
305305
pcfparm = new(ibmmq.PCFParameter)
306306
pcfparm.Type = ibmmq.MQCFT_INTEGER_LIST
307307
pcfparm.Parameter = ibmmq.MQIACF_Q_ATTRS
308-
pcfparm.Int64Value = []int64{int64(ibmmq.MQIA_MAX_Q_DEPTH), int64(ibmmq.MQIA_USAGE)}
308+
pcfparm.Int64Value = []int64{int64(ibmmq.MQIA_MAX_Q_DEPTH), int64(ibmmq.MQIA_USAGE), int64(ibmmq.MQCA_Q_DESC)}
309309
cfh.ParameterCount++
310310
buf = append(buf, pcfparm.Bytes()...)
311311

@@ -515,6 +515,13 @@ func parseQAttrData(cfh *ibmmq.MQCFH, buf []byte) {
515515
qInfo.AttrUsage = v
516516
}
517517
}
518+
case ibmmq.MQCA_Q_DESC:
519+
v := elem.String[0]
520+
if v != "" {
521+
if qInfo, ok := qInfoMap[qName]; ok {
522+
qInfo.Description = v
523+
}
524+
}
518525
}
519526

520527
}

0 commit comments

Comments
 (0)