Skip to content

Commit

Permalink
Refactor to make encoding more consistent (#6995)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreYang authored Jun 26, 2020
1 parent 232edda commit 71599eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from six import iteritems

from datadog_checks.base import AgentCheck, ensure_bytes, ensure_unicode
from datadog_checks.base import AgentCheck, to_native_string

from .. import metrics

Expand Down Expand Up @@ -45,7 +45,7 @@ def __init__(self, config, service_check, gauge, log):
self.gauge = gauge

def get_pcf_channel_metrics(self, queue_manager):
args = {pymqi.CMQCFC.MQCACH_CHANNEL_NAME: ensure_bytes('*')}
args = {pymqi.CMQCFC.MQCACH_CHANNEL_NAME: pymqi.ensure_bytes('*')}
try:
pcf = pymqi.PCFExecute(queue_manager)
response = pcf.MQCMD_INQUIRE_CHANNEL(args)
Expand All @@ -57,7 +57,7 @@ def get_pcf_channel_metrics(self, queue_manager):
self.gauge(mname, channels, tags=self.config.tags_no_channel)

for channel_info in response:
channel_name = ensure_unicode(channel_info[pymqi.CMQCFC.MQCACH_CHANNEL_NAME]).strip()
channel_name = to_native_string(channel_info[pymqi.CMQCFC.MQCACH_CHANNEL_NAME]).strip()
channel_tags = self.config.tags_no_channel + ["channel:{}".format(channel_name)]

self._submit_metrics_from_properties(channel_info, metrics.channel_metrics(), channel_tags)
Expand All @@ -83,7 +83,7 @@ def _submit_channel_status(self, queue_manager, search_channel_name, tags, chann
channels_to_skip = channels_to_skip or []
search_channel_tags = tags + ["channel:{}".format(search_channel_name)]
try:
args = {pymqi.CMQCFC.MQCACH_CHANNEL_NAME: ensure_bytes(search_channel_name)}
args = {pymqi.CMQCFC.MQCACH_CHANNEL_NAME: pymqi.ensure_bytes(search_channel_name)}
pcf = pymqi.PCFExecute(queue_manager)
response = pcf.MQCMD_INQUIRE_CHANNEL_STATUS(args)
self.service_check(self.CHANNEL_SERVICE_CHECK, AgentCheck.OK, search_channel_tags)
Expand All @@ -95,7 +95,7 @@ def _submit_channel_status(self, queue_manager, search_channel_name, tags, chann
self.log.warning("Error getting CHANNEL status for channel %s: %s", search_channel_name, e)
else:
for channel_info in response:
channel_name = ensure_unicode(channel_info[pymqi.CMQCFC.MQCACH_CHANNEL_NAME]).strip()
channel_name = to_native_string(channel_info[pymqi.CMQCFC.MQCACH_CHANNEL_NAME]).strip()
if channel_name in channels_to_skip:
continue
channel_tags = tags + ["channel:{}".format(channel_name)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from six import iteritems

from datadog_checks.base import AgentCheck, ensure_bytes, ensure_unicode
from datadog_checks.base import AgentCheck, to_native_string
from datadog_checks.ibm_mq.metrics import GAUGE

from .. import metrics
Expand Down Expand Up @@ -80,7 +80,7 @@ def _discover_queues(self, queue_manager, mq_pattern_filter):
queues = []

for queue_type in SUPPORTED_QUEUE_TYPES:
args = {pymqi.CMQC.MQCA_Q_NAME: ensure_bytes(mq_pattern_filter), pymqi.CMQC.MQIA_Q_TYPE: queue_type}
args = {pymqi.CMQC.MQCA_Q_NAME: pymqi.ensure_bytes(mq_pattern_filter), pymqi.CMQC.MQIA_Q_TYPE: queue_type}
try:
pcf = pymqi.PCFExecute(queue_manager)
response = pcf.MQCMD_INQUIRE_Q(args)
Expand All @@ -89,7 +89,7 @@ def _discover_queues(self, queue_manager, mq_pattern_filter):
else:
for queue_info in response:
queue = queue_info[pymqi.CMQC.MQCA_Q_NAME]
queues.append(ensure_unicode(queue).strip())
queues.append(to_native_string(queue).strip())

return queues

Expand All @@ -112,7 +112,7 @@ def queue_stats(self, queue_manager, queue_name, tags):
Grab stats from queues
"""
try:
args = {pymqi.CMQC.MQCA_Q_NAME: ensure_bytes(queue_name), pymqi.CMQC.MQIA_Q_TYPE: pymqi.CMQC.MQQT_ALL}
args = {pymqi.CMQC.MQCA_Q_NAME: pymqi.ensure_bytes(queue_name), pymqi.CMQC.MQIA_Q_TYPE: pymqi.CMQC.MQQT_ALL}
pcf = pymqi.PCFExecute(queue_manager)
response = pcf.MQCMD_INQUIRE_Q(args)
except pymqi.MQMIError as e:
Expand Down Expand Up @@ -141,7 +141,7 @@ def _submit_queue_stats(self, queue_info, queue_name, tags):
def get_pcf_queue_status_metrics(self, queue_manager, queue_name, tags):
try:
args = {
pymqi.CMQC.MQCA_Q_NAME: ensure_bytes(queue_name),
pymqi.CMQC.MQCA_Q_NAME: pymqi.ensure_bytes(queue_name),
pymqi.CMQC.MQIA_Q_TYPE: pymqi.CMQC.MQQT_ALL,
pymqi.CMQCFC.MQIACF_Q_STATUS_ATTRS: pymqi.CMQCFC.MQIACF_ALL,
}
Expand All @@ -167,7 +167,7 @@ def get_pcf_queue_status_metrics(self, queue_manager, queue_name, tags):

def get_pcf_queue_reset_metrics(self, queue_manager, queue_name, tags):
try:
args = {pymqi.CMQC.MQCA_Q_NAME: ensure_bytes(queue_name)}
args = {pymqi.CMQC.MQCA_Q_NAME: pymqi.ensure_bytes(queue_name)}
pcf = pymqi.PCFExecute(queue_manager)
response = pcf.MQCMD_RESET_Q_STATS(args)
except pymqi.MQMIError as e:
Expand Down

0 comments on commit 71599eb

Please sign in to comment.