Skip to content

Commit

Permalink
Fix ibm_mq e2e import issue (#4140)
Browse files Browse the repository at this point in the history
* Fix ibm_mq e2e import issue

* Remove duplicate code

* Update comment wording
  • Loading branch information
AlexandreYang authored Jul 24, 2019
1 parent 3d4f125 commit 4982a50
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
51 changes: 27 additions & 24 deletions ibm_mq/datadog_checks/ibm_mq/ibm_mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,9 @@
except ImportError as e:
pymqiException = e
pymqi = None

log = logging.getLogger(__file__)


class IbmMqCheck(AgentCheck):

METRIC_PREFIX = 'ibm_mq'

SERVICE_CHECK = 'ibm_mq.can_connect'

QUEUE_MANAGER_SERVICE_CHECK = 'ibm_mq.queue_manager'
QUEUE_SERVICE_CHECK = 'ibm_mq.queue'

CHANNEL_SERVICE_CHECK = 'ibm_mq.channel'
CHANNEL_STATUS_SERVICE_CHECK = 'ibm_mq.channel.status'

CHANNEL_COUNT_CHECK = 'ibm_mq.channel.count'

else:
# Since pymqi is not be available/installed on win/macOS when running e2e,
# we load the following constants only pymqi import succeed
SUPPORTED_QUEUE_TYPES = [pymqi.CMQC.MQQT_LOCAL, pymqi.CMQC.MQQT_MODEL]

STATUS_MQCHS_UNKNOWN = -1
Expand Down Expand Up @@ -65,6 +50,24 @@ class IbmMqCheck(AgentCheck):
pymqi.CMQCFC.MQCHS_INITIALIZING: AgentCheck.WARNING,
}


log = logging.getLogger(__file__)


class IbmMqCheck(AgentCheck):

METRIC_PREFIX = 'ibm_mq'

SERVICE_CHECK = 'ibm_mq.can_connect'

QUEUE_MANAGER_SERVICE_CHECK = 'ibm_mq.queue_manager'
QUEUE_SERVICE_CHECK = 'ibm_mq.queue'

CHANNEL_SERVICE_CHECK = 'ibm_mq.channel'
CHANNEL_STATUS_SERVICE_CHECK = 'ibm_mq.channel.status'

CHANNEL_COUNT_CHECK = 'ibm_mq.channel.count'

def check(self, instance):
config = IBMMQConfig(instance)
config.check_properly_configured()
Expand Down Expand Up @@ -132,7 +135,7 @@ def discover_queues(self, queue_manager, config):
def _discover_queues(self, queue_manager, mq_pattern_filter):
queues = []

for queue_type in self.SUPPORTED_QUEUE_TYPES:
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}
try:
pcf = pymqi.PCFExecute(queue_manager)
Expand Down Expand Up @@ -264,18 +267,18 @@ def _submit_channel_status(self, queue_manager, search_channel_name, tags, confi
self._submit_status_check(channel_name, channel_status, channel_tags)

def _submit_status_check(self, channel_name, channel_status, channel_tags):
if channel_status in self.SERVICE_CHECK_MAP:
service_check_status = self.SERVICE_CHECK_MAP[channel_status]
if channel_status in SERVICE_CHECK_MAP:
service_check_status = SERVICE_CHECK_MAP[channel_status]
else:
self.log.warning("Status `{}` not found for channel `{}`".format(channel_status, channel_name))
service_check_status = AgentCheck.UNKNOWN
self.service_check(self.CHANNEL_STATUS_SERVICE_CHECK, service_check_status, channel_tags)

def _submit_channel_count(self, channel_name, channel_status, channel_tags):
if channel_status not in self.CHANNEL_STATUS_MAP:
if channel_status not in CHANNEL_STATUS_MAP:
self.log.warning("Status `{}` not found for channel `{}`".format(channel_status, channel_name))
channel_status = self.STATUS_MQCHS_UNKNOWN
channel_status = STATUS_MQCHS_UNKNOWN

for status, status_label in iteritems(self.CHANNEL_STATUS_MAP):
for status, status_label in iteritems(CHANNEL_STATUS_MAP):
status_active = int(status == channel_status)
self.gauge(self.CHANNEL_COUNT_CHECK, status_active, tags=channel_tags + ["status:" + status_label])
7 changes: 6 additions & 1 deletion ibm_mq/tests/test_ibm_mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import logging

import pymqi
import pytest
from six import iteritems

Expand Down Expand Up @@ -44,6 +43,9 @@ def test_service_check_connection_issues(aggregator, instance, seed_data):

@pytest.mark.usefixtures("dd_environment")
def test_service_check_from_status(aggregator, instance, seed_data):
# Late import to not require it for e2e
import pymqi

check = IbmMqCheck('ibm_mq', {}, {})

service_check_map = {
Expand Down Expand Up @@ -129,6 +131,9 @@ def test_check_regex_tag(aggregator, instance_queue_regex_tag, seed_data):

@pytest.mark.usefixtures("dd_environment")
def test_check_channel_count(aggregator, instance_queue_regex_tag, seed_data):
# Late import to not require it for e2e
import pymqi

metrics_to_assert = {
"inactive": 0,
"binding": 0,
Expand Down

0 comments on commit 4982a50

Please sign in to comment.