From 0bf886ca689584d6200d8cb34cd28c2e50b5fad0 Mon Sep 17 00:00:00 2001 From: Julia Simon <611228+hithwen@users.noreply.github.com> Date: Thu, 4 Feb 2021 11:13:25 +0100 Subject: [PATCH 1/6] Raise config options if incorrect ssl configuration --- ibm_mq/datadog_checks/ibm_mq/config.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ibm_mq/datadog_checks/ibm_mq/config.py b/ibm_mq/datadog_checks/ibm_mq/config.py index 7c5b8f7bdae2d..9a083784b22ea 100644 --- a/ibm_mq/datadog_checks/ibm_mq/config.py +++ b/ibm_mq/datadog_checks/ibm_mq/config.py @@ -102,14 +102,17 @@ def __init__(self, instance): self.tags_no_channel = tags self.tags = tags + ["channel:{}".format(self.channel)] # type: List[str] + # SSL options self.ssl = is_affirmative(instance.get('ssl_auth', False)) # type: bool self.ssl_cipher_spec = instance.get('ssl_cipher_spec', 'TLS_RSA_WITH_AES_256_CBC_SHA') # type: str - self.ssl_key_repository_location = instance.get( 'ssl_key_repository_location', '/var/mqm/ssl-db/client/KeyringClient' ) # type: str - self.ssl_certificate_label = instance.get('ssl_certificate_label') # type: str + if not self.ssl and ( + instance.get('ssl_cipher_spec') or instance.get('ssl_key_repository_location') or self.ssl_certificate_label + ): + raise ConfigurationError("You have provided ssl connection options but ssl authentication is disabled") self.mq_installation_dir = instance.get('mq_installation_dir', '/opt/mqm/') From 56ba8756a0b0b59859168cd6a9b2801136214474 Mon Sep 17 00:00:00 2001 From: Julia <611228+hithwen@users.noreply.github.com> Date: Thu, 4 Feb 2021 12:40:49 +0100 Subject: [PATCH 2/6] Update ibm_mq/datadog_checks/ibm_mq/config.py --- ibm_mq/datadog_checks/ibm_mq/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm_mq/datadog_checks/ibm_mq/config.py b/ibm_mq/datadog_checks/ibm_mq/config.py index 9a083784b22ea..1b4ccdee1ebc7 100644 --- a/ibm_mq/datadog_checks/ibm_mq/config.py +++ b/ibm_mq/datadog_checks/ibm_mq/config.py @@ -112,7 +112,7 @@ def __init__(self, instance): if not self.ssl and ( instance.get('ssl_cipher_spec') or instance.get('ssl_key_repository_location') or self.ssl_certificate_label ): - raise ConfigurationError("You have provided ssl connection options but ssl authentication is disabled") + raise ConfigurationError("You have provided ssl connection options but ssl_auth is disabled. Please enable it or comment/remove the other ssl options") self.mq_installation_dir = instance.get('mq_installation_dir', '/opt/mqm/') From 417fc4ac7732c6edd5ca87f2768d5d4097487875 Mon Sep 17 00:00:00 2001 From: Julia Simon <611228+hithwen@users.noreply.github.com> Date: Thu, 4 Feb 2021 12:46:09 +0100 Subject: [PATCH 3/6] Style fix --- ibm_mq/datadog_checks/ibm_mq/config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ibm_mq/datadog_checks/ibm_mq/config.py b/ibm_mq/datadog_checks/ibm_mq/config.py index 1b4ccdee1ebc7..69c57dbc21968 100644 --- a/ibm_mq/datadog_checks/ibm_mq/config.py +++ b/ibm_mq/datadog_checks/ibm_mq/config.py @@ -112,7 +112,10 @@ def __init__(self, instance): if not self.ssl and ( instance.get('ssl_cipher_spec') or instance.get('ssl_key_repository_location') or self.ssl_certificate_label ): - raise ConfigurationError("You have provided ssl connection options but ssl_auth is disabled. Please enable it or comment/remove the other ssl options") + raise ConfigurationError( + "You have provided ssl connection options but ssl_auth is disabled. " + "Please enable it or comment/remove the other ssl options" + ) self.mq_installation_dir = instance.get('mq_installation_dir', '/opt/mqm/') From 4dcf01454dff3189ad1489cc4dced5ffc0ee9682 Mon Sep 17 00:00:00 2001 From: Julia Simon <611228+hithwen@users.noreply.github.com> Date: Fri, 5 Feb 2021 10:58:27 +0100 Subject: [PATCH 4/6] Use SSL if SSL options are provided --- ibm_mq/datadog_checks/ibm_mq/config.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ibm_mq/datadog_checks/ibm_mq/config.py b/ibm_mq/datadog_checks/ibm_mq/config.py index 69c57dbc21968..231de55da887a 100644 --- a/ibm_mq/datadog_checks/ibm_mq/config.py +++ b/ibm_mq/datadog_checks/ibm_mq/config.py @@ -6,6 +6,7 @@ import logging import re +from datadog_checks.base.log import get_check_logger from dateutil.tz import UTC from six import iteritems @@ -24,9 +25,6 @@ pymqi = None -log = logging.getLogger(__file__) - - class IBMMQConfig: """ A config object. Parse the instance and return it as an object that can be passed around @@ -44,6 +42,7 @@ class IBMMQConfig: ] def __init__(self, instance): + self.log = get_check_logger() self.channel = instance.get('channel') # type: str self.queue_manager_name = instance.get('queue_manager', 'default') # type: str @@ -79,7 +78,7 @@ def __init__(self, instance): ) # type: bool if int(self.auto_discover_queues) + int(bool(self.queue_patterns)) + int(bool(self.queue_regex)) > 1: - log.warning( + self.log.warning( "Configurations auto_discover_queues, queue_patterns and queue_regex are not intended to be used " "together." ) @@ -112,10 +111,9 @@ def __init__(self, instance): if not self.ssl and ( instance.get('ssl_cipher_spec') or instance.get('ssl_key_repository_location') or self.ssl_certificate_label ): - raise ConfigurationError( - "You have provided ssl connection options but ssl_auth is disabled. " - "Please enable it or comment/remove the other ssl options" - ) + self.log.info("ssl_auth has not been explictly enabled but other SSL options have been provided. " + "SSL will be used for connecting") + self.ssl = True self.mq_installation_dir = instance.get('mq_installation_dir', '/opt/mqm/') @@ -145,7 +143,7 @@ def _compile_tag_re(self): try: queue_tag_list.append([re.compile(regex_str), [t.strip() for t in tags.split(',')]]) except TypeError: - log.warning('%s is not a valid regular expression and will be ignored', regex_str) + self.log.warning('%s is not a valid regular expression and will be ignored', regex_str) return queue_tag_list @staticmethod From 1a2041433a1462820b283abdc69c4f1c4a23168e Mon Sep 17 00:00:00 2001 From: Julia Simon <611228+hithwen@users.noreply.github.com> Date: Mon, 8 Feb 2021 13:21:23 +0100 Subject: [PATCH 5/6] Style fix --- ibm_mq/datadog_checks/ibm_mq/config.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ibm_mq/datadog_checks/ibm_mq/config.py b/ibm_mq/datadog_checks/ibm_mq/config.py index 231de55da887a..d15b24df56236 100644 --- a/ibm_mq/datadog_checks/ibm_mq/config.py +++ b/ibm_mq/datadog_checks/ibm_mq/config.py @@ -3,15 +3,14 @@ # Licensed under a 3-clause BSD style license (see LICENSE) import datetime as dt -import logging import re -from datadog_checks.base.log import get_check_logger from dateutil.tz import UTC from six import iteritems from datadog_checks.base import AgentCheck, ConfigurationError, is_affirmative from datadog_checks.base.constants import ServiceCheck +from datadog_checks.base.log import get_check_logger try: from typing import Dict, List, Pattern @@ -111,8 +110,10 @@ def __init__(self, instance): if not self.ssl and ( instance.get('ssl_cipher_spec') or instance.get('ssl_key_repository_location') or self.ssl_certificate_label ): - self.log.info("ssl_auth has not been explictly enabled but other SSL options have been provided. " - "SSL will be used for connecting") + self.log.info( + "ssl_auth has not been explictly enabled but other SSL options have been provided. " + "SSL will be used for connecting" + ) self.ssl = True self.mq_installation_dir = instance.get('mq_installation_dir', '/opt/mqm/') From 8dcc529020d08aa0271f8f1da96835fd4555a27e Mon Sep 17 00:00:00 2001 From: Julia Simon <611228+hithwen@users.noreply.github.com> Date: Mon, 8 Feb 2021 15:00:28 +0100 Subject: [PATCH 6/6] Do not override if specificly disabled --- ibm_mq/datadog_checks/ibm_mq/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm_mq/datadog_checks/ibm_mq/config.py b/ibm_mq/datadog_checks/ibm_mq/config.py index d15b24df56236..6e25daa4e1a02 100644 --- a/ibm_mq/datadog_checks/ibm_mq/config.py +++ b/ibm_mq/datadog_checks/ibm_mq/config.py @@ -107,7 +107,7 @@ def __init__(self, instance): 'ssl_key_repository_location', '/var/mqm/ssl-db/client/KeyringClient' ) # type: str self.ssl_certificate_label = instance.get('ssl_certificate_label') # type: str - if not self.ssl and ( + if instance.get('ssl_auth') is None and ( instance.get('ssl_cipher_spec') or instance.get('ssl_key_repository_location') or self.ssl_certificate_label ): self.log.info(