Skip to content

Commit 602ebc1

Browse files
Add new config use_ssl for Tibco EMS (#23732)
* Add option to connect via ssl * Update model for new use_ssl config * Fixing is_affirmative import error * Add unit test for new config * Add changelog * Applying lint * Displaying true as the example for config use_ssl
1 parent 8e13820 commit 602ebc1

7 files changed

Lines changed: 33 additions & 3 deletions

File tree

tibco_ems/assets/configuration/spec.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@ files:
6363
value:
6464
type: string
6565
require_trusted_provider: true
66+
- name: use_ssl
67+
description: |
68+
Set to `true` to connect to the Tibco EMS server using SSL (`ssl://host:port`).
69+
When `false`, the check uses `tcp://host:port`.
70+
value:
71+
type: boolean
72+
default: false
73+
example: true
6674
- template: instances/default

tibco_ems/changelog.d/23732.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add new config ``use_ssl`` to connect via SSL instead of TCP.

tibco_ems/datadog_checks/tibco_ems/config_models/defaults.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ def instance_min_collection_interval():
3434

3535
def instance_port():
3636
return 7222
37+
38+
39+
def instance_use_ssl():
40+
return False

tibco_ems/datadog_checks/tibco_ems/config_models/instance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class InstanceConfig(BaseModel):
4949
service: Optional[str] = None
5050
tags: Optional[tuple[str, ...]] = None
5151
tibemsadmin: Optional[str] = None
52+
use_ssl: Optional[bool] = None
5253
username: Optional[str] = None
5354

5455
@model_validator(mode='before')

tibco_ems/datadog_checks/tibco_ems/data/conf.yaml.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ instances:
5858
#
5959
# tibemsadmin: <TIBEMSADMIN>
6060

61+
## @param use_ssl - boolean - optional - default: false
62+
## Set to `true` to connect to the Tibco EMS server using SSL (`ssl://host:port`).
63+
## When `false`, the check uses `tcp://host:port`.
64+
#
65+
# use_ssl: true
66+
6167
## @param tags - list of strings - optional
6268
## A list of tags to attach to every metric and service check emitted by this instance.
6369
##

tibco_ems/datadog_checks/tibco_ems/tibco_ems.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
import subprocess
66
from typing import Any # noqa: F401
77

8-
from datadog_checks.base import AgentCheck
8+
from datadog_checks.base import AgentCheck, is_affirmative
99

1010
from .constants import SHOW_METRIC_DATA, UNIT_PATTERN
1111

1212
DEFAULT_HOST = 'localhost'
1313
DEFAULT_PORT = 7222
1414
TO_BYTES = {'b': 1, 'kb': 1e3, 'mb': 1e6, 'gb': 1e9, 'tb': 1e12}
15-
CONNECTION_STRING = 'tcp://{}:{}'
15+
TCP_CONNECTION_STRING = 'tcp://{}:{}'
16+
SSL_CONNECTION_STRING = 'ssl://{}:{}'
1617

1718

1819
class TibcoEMSCheck(AgentCheck):
@@ -29,7 +30,11 @@ def __init__(self, name, init_config, instances):
2930
username = self.instance.get('username')
3031
password = self.instance.get('password')
3132
script_path = self.instance.get('script_path')
32-
server_string = CONNECTION_STRING.format(host, port)
33+
use_ssl = is_affirmative(self.instance.get('use_ssl', False))
34+
if not use_ssl:
35+
server_string = TCP_CONNECTION_STRING.format(host, port)
36+
else:
37+
server_string = SSL_CONNECTION_STRING.format(host, port)
3338
self.tags = self.instance.get('tags', [])
3439

3540
self.cmd = tibemsadmin_cmd + [

tibco_ems/tests/test_unit.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,8 @@ def test_base_tags(dd_run_check, instance):
163163

164164
# assert the lenght of tags does not grow indefinitely
165165
assert len(check.tags) == 3
166+
167+
168+
def test_use_ssl_server_string(instance):
169+
check = TibcoEMSCheck('tibco_ems', {}, [{**instance, 'use_ssl': True}])
170+
assert 'ssl://localhost:7222' in check.cmd

0 commit comments

Comments
 (0)