Skip to content

Commit 61d296e

Browse files
committed
Some linter-suggested changes
Correct index for SHORT/LONG status resposes
1 parent 2a31ece commit 61d296e

File tree

10 files changed

+56
-22
lines changed

10 files changed

+56
-22
lines changed

ibmmq/mqiPCF.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,9 @@ func ReadPCFEmbeddedHeader(buf []byte) (*MQEPH, int) {
321321
binary.Read(p, endian, &eph.CodedCharSetId)
322322
offset += 4
323323

324-
s := string(buf[offset : offset+8])
325-
s = trimToNull(s)
324+
// We don't actually use this next field
325+
// s := string(buf[offset : offset+8])
326+
// s = trimToNull(s)
326327
offset += 8
327328
p.Next(8)
328329

ibmmq/mqistr.go

+2
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,8 @@ func MQItoString(class string, value int) string {
14651465
s = "MQCMDL_LEVEL_935"
14661466
case 940:
14671467
s = "MQCMDL_LEVEL_940"
1468+
case 941:
1469+
s = "MQCMDL_LEVEL_941"
14681470
default:
14691471
s = ""
14701472
}

mqmetric/channel.go

+29-8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ const (
7373
SQUASH_CHL_STATUS_RUNNING = 2
7474
)
7575

76+
// If connected to a z/OS queue manager, the short/long index is
77+
// as setup here. Otherwise we need to swap 0/1 indices.
78+
func idxDefault(zos bool, val int) int {
79+
if zos {
80+
return val
81+
} else {
82+
return (1 - val)
83+
}
84+
}
85+
7686
/*
7787
Unlike the statistics produced via a topic, there is no discovery
7888
of the attributes available in object STATUS queries. There is also
@@ -88,6 +98,11 @@ func ChannelInitAttributes() {
8898
os := &ci.objectStatus[OT_CHANNEL]
8999
st := GetObjectStatus(GetConnectionKey(), OT_CHANNEL)
90100

101+
zos := false
102+
if ci.si.platform == ibmmq.MQPL_ZOS {
103+
zos = true
104+
}
105+
91106
if os.init {
92107
traceExit("ChannelInitAttributes", 1)
93108
return
@@ -143,26 +158,32 @@ func ChannelInitAttributes() {
143158
st.Attributes[attr].squash = true
144159
os.init = true
145160

161+
// Some of the short/long status values are the opposite way round on the different platforms!
162+
// Really a bug in the PCF code (internal reference 304982), but it's not likely to be fixed because of compatibility.
163+
// In most cases, and always on ZOS, the SHORT is first followed by LONG. But the following
164+
// attributes are reversed:
165+
// COMPRESSION_RATE, COMPRESSION_TIME, EXIT_TIME: Not reported here anyway
166+
// NETWORK_TIME, XMITQ_TIME, BATCH_SIZE: Reported here
146167
attr = ATTR_CHL_NETTIME_SHORT
147168
st.Attributes[attr] = newStatusAttribute(attr, "Network Time Short", ibmmq.MQIACH_NETWORK_TIME_INDICATOR)
148-
st.Attributes[attr].index = 0
169+
st.Attributes[attr].index = idxDefault(zos, 0)
149170
attr = ATTR_CHL_NETTIME_LONG
150171
st.Attributes[attr] = newStatusAttribute(attr, "Network Time Long", ibmmq.MQIACH_NETWORK_TIME_INDICATOR)
151-
st.Attributes[attr].index = 1
172+
st.Attributes[attr].index = idxDefault(zos, 1)
152173

153174
attr = ATTR_CHL_BATCHSZ_SHORT
154175
st.Attributes[attr] = newStatusAttribute(attr, "Batch Size Average Short", ibmmq.MQIACH_BATCH_SIZE_INDICATOR)
155-
st.Attributes[attr].index = 0
176+
st.Attributes[attr].index = idxDefault(zos, 0)
156177
attr = ATTR_CHL_BATCHSZ_LONG
157-
st.Attributes[attr] = newStatusAttribute(attr, "Batch Size Average Short", ibmmq.MQIACH_BATCH_SIZE_INDICATOR)
158-
st.Attributes[attr].index = 1
178+
st.Attributes[attr] = newStatusAttribute(attr, "Batch Size Average Long", ibmmq.MQIACH_BATCH_SIZE_INDICATOR)
179+
st.Attributes[attr].index = idxDefault(zos, 1)
159180

160181
attr = ATTR_CHL_XQTIME_SHORT
161182
st.Attributes[attr] = newStatusAttribute(attr, "XmitQ Time Average Short", ibmmq.MQIACH_XMITQ_TIME_INDICATOR)
162-
st.Attributes[attr].index = 0
183+
st.Attributes[attr].index = idxDefault(zos, 0)
163184
attr = ATTR_CHL_XQTIME_LONG
164-
st.Attributes[attr] = newStatusAttribute(attr, "XmitQ Time Average Short", ibmmq.MQIACH_XMITQ_TIME_INDICATOR)
165-
st.Attributes[attr].index = 1
185+
st.Attributes[attr] = newStatusAttribute(attr, "XmitQ Time Average Long", ibmmq.MQIACH_XMITQ_TIME_INDICATOR)
186+
st.Attributes[attr].index = idxDefault(zos, 1)
166187

167188
attr = ATTR_CHL_SINCE_MSG
168189
st.Attributes[attr] = newStatusAttribute(attr, "Time Since Msg", -1)

mqmetric/cluster.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ func parseClusterData(cfh *ibmmq.MQCFH, buf []byte) string {
192192

193193
logTrace("parseClusterData - looking at elem %+v", elem)
194194
if !statusGetIntAttributes(GetObjectStatus(GetConnectionKey(), OT_CLUSTER), elem, key) {
195+
// There's not actually any additional attributes we care about for now
195196
switch elem.Parameter {
196-
case ibmmq.MQCA_CLUSTER_NAME:
197-
ClusterName = trimToNull(elem.String[0])
197+
//case ibmmq.MQCA_CLUSTER_NAME:
198+
// ClusterName = trimToNull(elem.String[0])
198199
}
199200
}
200201
}

mqmetric/discover.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func RediscoverAttributes(objectType int32, objectPatterns string) error {
277277
infoMap = amqpInfoMap
278278
fn = inquireAMQPChannelAttributes
279279
default:
280-
err = fmt.Errorf("Unsupported object type: ", objectType)
280+
err = fmt.Errorf("Unsupported object type: %d", objectType)
281281
}
282282

283283
if err == nil {
@@ -302,7 +302,7 @@ func discoverAndSubscribe(dc DiscoverConfig, redo bool) error {
302302
ci := getConnection(GetConnectionKey())
303303

304304
// What metrics can the queue manager provide?
305-
if err == nil && redo == false {
305+
if err == nil && !redo {
306306
err = discoverStats(dc)
307307
}
308308

@@ -759,7 +759,7 @@ func discoverQueues(monitoredQueuePatterns string) error {
759759
// For older levels of MQ, because of the possible complexities of pattern matching, we don't
760760
// actually fail the discovery process, but instead issue a warning and continue with
761761
// other queues.
762-
if strings.Contains(qName, "/") && ci.globalSlashWarning == false && GetCommandLevel() < ibmmq.MQCMDL_LEVEL_930 {
762+
if strings.Contains(qName, "/") && ci.globalSlashWarning && GetCommandLevel() < ibmmq.MQCMDL_LEVEL_930 {
763763
ci.localSlashWarning = true // First time through, issue the warning for all queues
764764
logError("Warning: Cannot subscribe to queue containing '/': %s", qName)
765765
continue

mqmetric/log.go

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func logError(format string, v ...interface{}) {
7474

7575
// Panic and Fatal are not going to be used for now but
7676
// are in here for completeness
77+
/*
7778
func logFatal(format string, v ...interface{}) {
7879
if logger != nil && logger.Fatal != nil {
7980
logger.Fatal(format, v...)
@@ -84,6 +85,7 @@ func logPanic(format string, v ...interface{}) {
8485
logger.Panic(format, v...)
8586
}
8687
}
88+
*/
8789

8890
// Some interfaces to enable tracing. In its simplest form, tracing the
8991
// entry point just needs the function name. There are often several exit

mqmetric/metrics.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,4 @@ Class: bufferpool/pageset
316316
ATTR_PS_TOTAL : pages_total
317317
ATTR_PS_UNUSED : pages_unused
318318

319-
This page was automatically generated from the source tree on 2024-06-11 06:33:21
319+
This page was automatically generated from the source tree on 2024-09-13 16:03:23

mqmetric/mqif.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ don't need to repeat common setups eg of MQMD or MQSD structures.
2525
*/
2626

2727
import (
28+
"errors"
2829
"fmt"
2930

3031
"github.com/ibm-messaging/mq-golang/v5/ibmmq"
@@ -212,13 +213,13 @@ func initConnectionKey(key string, qMgrName string, replyQ string, replyQ2 strin
212213
evEnabled := v[ibmmq.MQIA_PERFORMANCE_EVENT].(int32)
213214
if ci.useResetQStats && evEnabled == 0 {
214215
errorString = "Requested use of RESET QSTATS but queue manager has PERFMEV(DISABLED)"
215-
err = fmt.Errorf(errorString)
216+
err = errors.New(errorString)
216217
}
217218
} else {
218-
if cc.UsePublications == true {
219+
if cc.UsePublications {
219220
if ci.si.commandLevel < 900 && ci.si.platform != ibmmq.MQPL_APPLIANCE {
220221
errorString = "Unsupported system: Queue manager must be at least V9.0 for full monitoring. Disable the usePublications attribute for limited capability."
221-
err = fmt.Errorf(errorString)
222+
err = errors.New(errorString)
222223
mqreturn = &ibmmq.MQReturn{MQCC: ibmmq.MQCC_FAILED, MQRC: ibmmq.MQRC_ENVIRONMENT_ERROR}
223224
} else {
224225
ci.usePublications = cc.UsePublications
@@ -497,7 +498,7 @@ func (mqtd *MQTopicDescriptor) unsubscribe() {
497498

498499
subObj, err := ci.si.qMgr.Sub(mqsd, &ci.si.replyQObj)
499500
if err == nil {
500-
err = subObj.Close(ibmmq.MQCO_REMOVE_SUB)
501+
subObj.Close(ibmmq.MQCO_REMOVE_SUB)
501502
} else {
502503
logDebug("Resub failed for %s with %v %+v", topic, err, subObj)
503504
}

mqmetric/status.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ package mqmetric
2525
*/
2626

2727
import (
28-
"fmt"
28+
// "fmt"
2929
"strings"
3030
"time"
3131

3232
ibmmq "github.com/ibm-messaging/mq-golang/v5/ibmmq"
3333
)
3434

35-
var statusDummy = fmt.Sprintf("dummy")
35+
// var statusDummy = fmt.Sprintf("dummy")
3636
var timeTravelWarningIssued = false
3737

3838
/*

staticcheck.conf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Use the default set of options, but explicitly exclude some that I don't like.
2+
checks = [ "inherit", # Start with the default set
3+
"-S1023", # Redundant return statement (I like the explicitness)
4+
"-ST1005", # Error strings should not be capitalized
5+
"-S1005", # Unnecessary assignment to blank identifier (in particular in calls to "range")
6+
]

0 commit comments

Comments
 (0)