diff --git a/README.md b/README.md index 2ecf442442e5c54bd0620f3002a27fbfd7eec3e9..71a3cd5fda0670130228a33334037dda95261d81 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[PACKAGE]: ../../raw/master/mkp/agent_ssllabs-2.0.3-20240516.mkp "agent_ssllabs-2.0.3-20240516.mkp" +[PACKAGE]: ../../raw/master/mkp/agent_ssllabs-2.0.4-20240604.mkp "agent_ssllabs-2.0.4-20240604.mkp" # Qualys SSL Labs REST API special agent This Agent uses die Qualys SSL Labs REST API to scan a list of servers for there SSL status. The plugin will check the given server and all end points reported by the SSL Labs scan. diff --git a/mkp/agent_ssllabs-2.0.4-20240604.mkp b/mkp/agent_ssllabs-2.0.4-20240604.mkp new file mode 100644 index 0000000000000000000000000000000000000000..fb1e3389aff67027a0c0e6aba197d64f92fa8265 Binary files /dev/null and b/mkp/agent_ssllabs-2.0.4-20240604.mkp differ diff --git a/source/agent_based/ssllabs_grade.py b/source/agent_based/ssllabs_grade.py index 1cc05d282053b6525fb01569c293ec434c56f2d8..9dd8d96db297ac2703aa4aa85205be75fc5c588b 100644 --- a/source/agent_based/ssllabs_grade.py +++ b/source/agent_based/ssllabs_grade.py @@ -15,6 +15,7 @@ # 2024-05-06: added pending to ok states for end points # 2024-05-07: fixed crash on wrong params int "ERROR" state # changed max CMK version in package info to 2.3.0b1 +# 2024-06-04: added support for API error messages # sample string_table: # [ @@ -163,7 +164,8 @@ class SSLLabsHost: status_message: str | None cache_expiry_time: int | None from_agent_cache: bool | None - end_points: Sequence[SSLLabsEndpoint] + end_points: Sequence[SSLLabsEndpoint] | None + errors: Sequence[str] | None @classmethod def parse(cls, ssl_host): @@ -180,7 +182,8 @@ class SSLLabsHost: status_message=get_str('statusMessage', ssl_host), cache_expiry_time=get_int('cacheExpiryTime', ssl_host), from_agent_cache=get_bool('from_agent_cache', ssl_host), - end_points=[SSLLabsEndpoint.parse(endpoint) for endpoint in ssl_host.get('endpoints', [])] + end_points=[SSLLabsEndpoint.parse(endpoint) for endpoint in ssl_host.get('endpoints', [])], + errors=[str(error) for error in ssl_host.get('errors', [])] if ssl_host.get('errors') else None, ) @@ -299,6 +302,10 @@ def check_ssllabs_grade(item: str, params: Mapping[str: any], section: SECTION) yield Result(state=State.UNKNOWN, summary=f'Item not found in monitoring data. ({str(section)})') return None + if ssl_host.errors: + for error in ssl_host.errors: + yield Result(state=State.WARN, notice=error) + value_store = get_value_store() match ssl_host.status: @@ -343,6 +350,8 @@ def check_ssllabs_grade(item: str, params: Mapping[str: any], section: SECTION) yield from check_has_warning(params, ssl_host.end_points) yield from check_is_exceptional(params, ssl_host.end_points) yield from check_status(params, ssl_host.end_points) + case None: + pass case _: yield Result(state=State.UNKNOWN, notice=f'Unknown test status: {ssl_host.status}') diff --git a/source/lib/python3/cmk/special_agents/agent_ssllabs.py b/source/lib/python3/cmk/special_agents/agent_ssllabs.py old mode 100755 new mode 100644 index b0709eba89a27b5b78a74ed41caa746c994cfa24..432743a8fb32c0676b5d05a978b0048245ea9722 --- a/source/lib/python3/cmk/special_agents/agent_ssllabs.py +++ b/source/lib/python3/cmk/special_agents/agent_ssllabs.py @@ -20,6 +20,7 @@ # 2024-05-01: refactoring # 2024-05-16: fixed proxy usage # removed check_mk section -> no way to differentiate from checkmk agent section check_mk +# 2025-06-04: changed to expose API errors to the check plugin # sample agent output (formatted) # <<<check_mk>>> @@ -183,18 +184,20 @@ def connect_ssllabs_api(ssl_host_address: str, host_cache: str, args: Args, ) -> timeout=args.timeout, proxies=proxies, headers={ - 'User-Agent': f'CMK SSL Labs special agent {VERSION}', + # 'User-Agent': f'CMK SSL Labs special agent {VERSION}', }, ) except ConnectionError as e: - host_data = {'host': ssl_host_address, 'status': 'ConnectionError', 'error': str(e)} + host_data = {'host': ssl_host_address, 'errors': ['status: ConnectionError', str(e)]} else: try: host_data = response.json() except JSONDecodeError as e: - host_data = {'host': ssl_host_address, 'status': 'JSONDecodeError', 'error': str(e)} + host_data = {'host': ssl_host_address, 'errors': ['status: JSONDecodeError', str(e)]} if host_data.get('status') == 'READY': Path(host_cache).write_text(response.text) + elif host_data.get('errors'): + host_data.update({'host': ssl_host_address}) return host_data diff --git a/source/packages/agent_ssllabs b/source/packages/agent_ssllabs index 8568e6654d078600f1e93e1caf077fd6b39a45d4..1ca90e95ee0b33f10ff008e2342a4b476cb90db6 100644 --- a/source/packages/agent_ssllabs +++ b/source/packages/agent_ssllabs @@ -15,7 +15,7 @@ 'web': ['plugins/wato/agent_ssllabs.py']}, 'name': 'agent_ssllabs', 'title': 'ssllabs api check', - 'version': '2.0.3-20240516', + 'version': '2.0.4-20240604', 'version.min_required': '2.2.0b1', 'version.packaged': '2.2.0p24', 'version.usable_until': '2.3.0b1'}