Skip to content

Commit a026087

Browse files
Fix token auth for teamcity integration (#17478)
* check for auth_token key and skip adding guestAuth or httpAuth to url if present * add changelog
1 parent 971d081 commit a026087

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

teamcity/changelog.d/17478.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
check for auth_token key and skip adding guestAuth or httpAuth to url if present

teamcity/datadog_checks/teamcity/teamcity_openmetrics.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ class TeamCityOpenMetrics(OpenMetricsBaseCheckV2):
1313
__NAMESPACE__ = 'teamcity'
1414
DEFAULT_METRIC_LIMIT = 0
1515

16-
DEFAULT_METRICS_URL = "/{}/app/metrics"
17-
EXPERIMENTAL_METRICS_URL = "/{}/app/metrics?experimental=true"
16+
DEFAULT_METRICS_URL = "/app/metrics"
17+
EXPERIMENTAL_METRICS_URL = "/app/metrics?experimental=true"
1818

1919
def __init__(self, name, init_config, instances):
2020
super(TeamCityOpenMetrics, self).__init__(name, init_config, instances)
2121
self.basic_http_auth = is_affirmative(
2222
self.instance.get('basic_http_authentication', bool(self.instance.get('password')))
2323
)
24+
self.token_auth = is_affirmative(self.instance.get('auth_token'))
2425
self.auth_type = 'httpAuth' if self.basic_http_auth else 'guestAuth'
2526
parsed_endpoint = urlparse(self.instance.get('server'))
2627
self.server_url = "{}://{}".format(parsed_endpoint.scheme, parsed_endpoint.netloc)
@@ -29,9 +30,12 @@ def __init__(self, name, init_config, instances):
2930
experimental_metrics = is_affirmative(self.instance.get('experimental_metrics', False))
3031

3132
if experimental_metrics:
32-
self.metrics_endpoint = self.EXPERIMENTAL_METRICS_URL.format(self.auth_type)
33+
self.metrics_endpoint = self.EXPERIMENTAL_METRICS_URL
3334
else:
34-
self.metrics_endpoint = self.DEFAULT_METRICS_URL.format(self.auth_type)
35+
self.metrics_endpoint = self.DEFAULT_METRICS_URL
36+
37+
if not self.token_auth:
38+
self.metrics_endpoint = '/{}{}'.format(self.auth_type, self.metrics_endpoint)
3539

3640
def configure_scrapers(self):
3741
config = deepcopy(self.instance)

teamcity/datadog_checks/teamcity/teamcity_rest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, name, init_config, instances):
4646
self.basic_http_auth = is_affirmative(
4747
self.instance.get('basic_http_authentication', bool(self.instance.get('password', False)))
4848
)
49+
self.token_auth = is_affirmative(self.instance.get('auth_token'))
4950

5051
self.monitored_projects = self.instance.get('projects', {})
5152
self.default_build_configs_limit = self.instance.get('default_build_configs_limit', DEFAULT_BUILD_CONFIGS_LIMIT)
@@ -67,7 +68,9 @@ def __init__(self, name, init_config, instances):
6768

6869
server = self.instance.get('server')
6970
self.server_url = normalize_server_url(server)
70-
self.base_url = "{}/{}".format(self.server_url, self.auth_type)
71+
self.base_url = self.server_url
72+
if not self.token_auth:
73+
self.base_url = "{}/{}".format(self.server_url, self.auth_type)
7174

7275
instance_tags = [
7376
'server:{}'.format(sanitize_server_url(self.server_url)),

0 commit comments

Comments
 (0)