Skip to content

Commit

Permalink
Add windows support (#10737)
Browse files Browse the repository at this point in the history
* Add support for windows

Co-authored-by: Ofek Lev <ofekmeister@gmail.com>
  • Loading branch information
hithwen and ofek authored Dec 23, 2021
1 parent d2c93d1 commit 709a9d0
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- template: './templates/test-single-windows.yml'
parameters:
job_name: Changed
check: '--changed datadog_checks_base datadog_checks_dev active_directory aspdotnet disk dns_check dotnetclr exchange_server iis network pdh_check sqlserver tcp_check win32_event_log windows_performance_counters windows_service wmi_check'
check: '--changed datadog_checks_base datadog_checks_dev active_directory aspdotnet disk dns_check dotnetclr exchange_server ibm_mq iis network pdh_check sqlserver tcp_check win32_event_log windows_performance_counters windows_service wmi_check'
${{ if eq(variables['System.PullRequest.IsFork'], 'False') }}:
ddtrace_flag: '--ddtrace'
validate_changed: changed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
from tempfile import TemporaryDirectory
from zipfile import ZipFile

import requests


CLIENT_VERSION = '9.2.2.0'
CLIENT_ARCHIVE_NAME = f'{CLIENT_VERSION}-IBM-MQC-Redist-Win64.zip'
CLIENT_URL = f'https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist/{CLIENT_ARCHIVE_NAME}'
CLIENT_TARGET_DIR = 'C:\\ibm_mq'


def download_file(url, file_name):
response = requests.get(url, stream=True)
response.raise_for_status()

with open(file_name, 'wb') as f:
for chunk in response.iter_content(16384):
f.write(chunk)


def main():
with TemporaryDirectory() as d:
temp_dir = os.path.realpath(d)

print('Downloading client')
client_archive_path = os.path.join(temp_dir, CLIENT_ARCHIVE_NAME)
download_file(CLIENT_URL, client_archive_path)

print('Extracting client')
with ZipFile(client_archive_path) as zip_file:
zip_file.extractall(CLIENT_TARGET_DIR)


if __name__ == '__main__':
main()
5 changes: 4 additions & 1 deletion .azure-pipelines/templates/test-all-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,11 @@ jobs:
displayName: IBM i
os: linux
- checkName: ibm_mq
displayName: IBM MQ
displayName: IBM MQ (Linux)
os: linux
- checkName: ibm_mq
displayName: IBM MQ (Windows)
os: windows
- checkName: ibm_was
displayName: IBM WAS
os: linux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pyhdb==0.3.4
pyjwt==1.7.1; python_version < "3.0"
pyjwt==2.0.1; python_version > "3.0"
pymongo==3.11.4
pymqi==1.12.0; sys_platform != "win32"
pymqi==1.12.0
pymysql==0.9.3
pyodbc==4.0.26
pyro4==4.73; sys_platform == "win32"
Expand Down
15 changes: 11 additions & 4 deletions ibm_mq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ This check monitors [IBM MQ][1] versions 8 to 9.0.

The IBM MQ check is included in the [Datadog Agent][2] package.

To use the IBM MQ check, you need to:
To use the IBM MQ check, you need to make sure the [IBM MQ Client][3] 9.1+ is installed (unless a compatible version of IBM MQ server is installed on the Agent host).

#### On Linux

1. Make sure the [IBM MQ Client][3] 9.1+ is installed (unless a compatible version of IBM MQ server is installed on the Agent host).
2. Update your `LD_LIBRARY_PATH` and `C_INCLUDE_PATH` to include the location of the libraries. (Create these two environment variables if they don’t exist yet.) For example:
Update your `LD_LIBRARY_PATH` and `C_INCLUDE_PATH` to include the location of the libraries. (Create these two environment variables if they don’t exist yet.)
For example, if you installed it in `/opt`:

```text
export LD_LIBRARY_PATH=/opt/mqm/lib64:/opt/mqm/lib:$LD_LIBRARY_PATH
Expand Down Expand Up @@ -129,7 +131,12 @@ Update the bindings:
sudo ldconfig
```

#### Permissions and authentication
#### On Windows

There is a file called `mqclient.ini` in the IBM MQ data directory. It is normally `C:\ProgramData\IBM\MQ`.
Configure the environment variable `MQ_FILE_PATH`, to point at the data directory.

### Permissions and authentication

There are many ways to set up permissions in IBM MQ. Depending on how your setup works, create a `datadog` user within MQ with read only permissions.

Expand Down
3 changes: 2 additions & 1 deletion ibm_mq/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"support": "core",
"supported_os": [
"linux",
"mac_os"
"mac_os",
"windows"
],
"public_title": "Datadog-IBM MQ Integration",
"categories": [
Expand Down
2 changes: 1 addition & 1 deletion ibm_mq/requirements.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pymqi==1.12.0; sys_platform != 'win32'
pymqi==1.12.0
8 changes: 8 additions & 0 deletions ibm_mq/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@

import os

import pytest

from datadog_checks.dev import get_docker_hostname
from datadog_checks.dev.ci import running_on_ci
from datadog_checks.dev.utils import ON_WINDOWS

# Ignore missing library to not require it for e2e
try:
from datadog_checks.ibm_mq.metrics import COUNT, GAUGE
except ImportError:
COUNT = GAUGE = ''

RUNNING_ON_WINDOWS_CI = ON_WINDOWS and running_on_ci()
skip_windows_ci = pytest.mark.skipif(RUNNING_ON_WINDOWS_CI, reason='MQ server cannot be setup on Windows VMs in CI')


HERE = os.path.dirname(os.path.abspath(__file__))
COMPOSE_DIR = os.path.join(HERE, 'compose')

Expand Down
6 changes: 3 additions & 3 deletions ibm_mq/tests/test_ibm_mq_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

from datadog_checks.dev.utils import get_metadata_metrics

from .common import MQ_VERSION, assert_all_metrics
from .common import MQ_VERSION, assert_all_metrics, skip_windows_ci

pytestmark = [skip_windows_ci, pytest.mark.e2e]


@pytest.mark.e2e
def test_e2e_check_all(dd_agent_check, instance_collect_all):
aggregator = dd_agent_check(instance_collect_all, rate=True)

assert_all_metrics(aggregator)
aggregator.assert_metrics_using_metadata(get_metadata_metrics())


@pytest.mark.e2e
@pytest.mark.skipif(
MQ_VERSION < 9, reason='Only test for for version >=9, for v8 use a custom image with custom setup.'
)
Expand Down
4 changes: 2 additions & 2 deletions ibm_mq/tests/test_ibm_mq_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from datadog_checks.dev.utils import get_metadata_metrics

from . import common
from .common import QUEUE_METRICS, assert_all_metrics
from .common import QUEUE_METRICS, assert_all_metrics, skip_windows_ci

pytestmark = [pytest.mark.usefixtures("dd_environment"), pytest.mark.integration]
pytestmark = [skip_windows_ci, pytest.mark.usefixtures("dd_environment"), pytest.mark.integration]


def test_no_msg_errors_are_caught(get_check, instance, caplog):
Expand Down
3 changes: 3 additions & 0 deletions ibm_mq/tests/test_ibm_mq_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from datadog_checks.base import AgentCheck, ConfigurationError

from .common import skip_windows_ci

pytestmark = pytest.mark.unit


Expand Down Expand Up @@ -182,6 +184,7 @@ def test_channel_queue_config_error(instance_config):
assert 'channel, queue_manager are required configurations' in str(excinfo.value)


@skip_windows_ci
def test_ssl_connection_creation(get_check, instance):
"""
Test that we are not getting unicode/bytes type error.
Expand Down
3 changes: 2 additions & 1 deletion ibm_mq/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# Licensed under a 3-clause BSD style license (see LICENSE)
import pytest

from .common import MQ_VERSION_RAW
from .common import MQ_VERSION_RAW, skip_windows_ci


@skip_windows_ci
@pytest.mark.integration
def test_metadata(get_check, instance, datadog_agent):
check = get_check(instance)
Expand Down
7 changes: 5 additions & 2 deletions ibm_mq/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ dd_mypy_args =
'.*/config_models/.*\.py$'
dd_mypy_deps =
types-mock==0.1.5
platform = linux|darwin|win32
platform =
linux|darwin
py38-9: linux|darwin|win32
deps =
-e../datadog_checks_base[deps]
-rrequirements-dev.txt
Expand All @@ -33,7 +35,8 @@ commands =
pip install -r requirements.in
pytest -v {posargs}
setenv =
LD_LIBRARY_PATH=/opt/mqm/lib64:/opt/mqm/lib:{env:LD_LIBRARY_PATH:none}
LD_LIBRARY_PATH=/opt/mqm/lib64{:}/opt/mqm/lib{:}C:\ibm_mq{:}{env:LD_LIBRARY_PATH:none}
MQ_FILE_PATH=C:\ibm_mq
8: IBM_MQ_VERSION = 8
8: IBM_MQ_COMPOSE_VERSION = 8
8: IBM_MQ_VERSION_RAW = 8.0.0.4
Expand Down

0 comments on commit 709a9d0

Please sign in to comment.