From 8b45da49eedefece8543ada451a1f7b5798bebfd Mon Sep 17 00:00:00 2001 From: Phillipe Smith Date: Fri, 26 Feb 2021 16:28:51 -0300 Subject: [PATCH] Fix issue invalid API request #10 --- README.md | 2 ++ rundeck_exporter.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5c461a1..091282b 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,8 @@ docker run --rm -d -p 9620:9620 -e RUNDECK_TOKEN=$RUNDECK_TOKEN rundeck_exporter ``` ## Changelog +`2.2.3`: +* Fix issue invalid API request #10 - Added warning message for API version < 25 `2.2.2`: * Fix GaugeMetricFamily definition location on method get_project_executions to correctly shows the HELP/TYPE diff --git a/rundeck_exporter.py b/rundeck_exporter.py index 39bcfa7..4c26c74 100755 --- a/rundeck_exporter.py +++ b/rundeck_exporter.py @@ -300,12 +300,11 @@ def get_counters(self, metrics: dict): Method to collect Rundeck metrics """ def collect(self): - metrics = self.request_data_from('/metrics/metrics') - system_info = self.request_data_from('/system/info') - """ Rundeck system info """ + system_info = self.request_data_from('/system/info') + api_version = system_info['system']['rundeck']['apiversion'] rundeck_system_info = InfoMetricFamily('rundeck_system', 'Rundeck system info') rundeck_system_info.add_metric([], {x: str(y) for x, y in system_info['system']['rundeck'].items()}) yield rundeck_system_info @@ -319,8 +318,15 @@ def collect(self): """ Rundeck counters """ - for counters in self.get_counters(metrics): - yield counters + if api_version >= self.args.rundeck_api_version < 25: + logging.warning(f'Unsupported API version "{self.args.rundeck_api_version}" ' + + f'for API request: /api/{self.args.rundeck_api_version}/metrics/metrics. ' + + 'Minimum supported version is 25') + else: + metrics = self.request_data_from('/metrics/metrics') + + for counters in self.get_counters(metrics): + yield counters """ Rundeck projects executions info