diff --git a/agent_based/curl.py b/agent_based/curl.py index 2d88a7c0498cb517ba4c4cb4af410a265cd663c9..19bd5a5b65668e66a3e8ac3684446f0b0da27728 100644 --- a/agent_based/curl.py +++ b/agent_based/curl.py @@ -26,6 +26,8 @@ # 2022-03-22: added curl_error_code_to_ignore and http_error_code_to_ignore options # 2022-04-06: removed .replace('://', ': //')) from json.loads() so service name is without space # 2022-04-26: made http(s) URLs clickable +# 2022-05-15: added workaround for raise ValueError("Cannot render negative timespan") +# # Example output from agent: # @@ -61,7 +63,7 @@ import json import time -from typing import Dict, Any, List +from typing import Dict, Any, List, Iterable from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( DiscoveryResult, CheckResult, @@ -76,6 +78,40 @@ from cmk.base.plugins.agent_based.agent_based_api.v1 import ( render, ) +# +# start workaround for : raise ValueError("Cannot render negative timespan") +# +from cmk.base.plugins.agent_based.agent_based_api.v1.render import ( + _TIME_UNITS, + _gen_timespan_chunks, +) + + +def timespan(seconds: float) -> str: + """Render a time span in seconds + + Example: + >>> timespan(1606721) + '18 days 14 hours' + >>> timespan(0.0001) + '100 microseconds' + + """ + if seconds >= 0: + ts = " ".join(_gen_timespan_chunks(float(seconds), nchunks=2)) + else: + seconds = -1 * seconds + ts = " ".join(_gen_timespan_chunks(float(seconds), nchunks=2)) + ts = f"-{ts}" + if ts == "0 %s" % _TIME_UNITS[-1][0]: + ts = "0 seconds" + return ts + +# +# end workaround for : raise ValueError("Cannot render negative timespan") +# + + _curl_error_codes = { 1: 'Unsupported protocol. This build of curl has no support for this protocol.', 2: 'Failed to initialize.', @@ -404,7 +440,7 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: label='Certificate time left', value=_data['tls_info']['time_left'], metric_name='cert_time_left', - render_func=render.timespan, + render_func=timespan, notice_only=True, levels_upper=upper, levels_lower=lower, diff --git a/curl.mkp b/curl.mkp index 933bf2ad422fab97d505f1a5703c3b51c058f020..7d2cb034671bf9523285f562bea3dfa1581441a3 100644 Binary files a/curl.mkp and b/curl.mkp differ diff --git a/packages/curl b/packages/curl index cd74d0b09c56e79950068be5f53c8460bba7e469..b8df7912d5737c199429248b7342009d4fdc4eb5 100644 --- a/packages/curl +++ b/packages/curl @@ -26,7 +26,7 @@ 'name': 'curl', 'num_files': 6, 'title': 'cURL agent plugin', - 'version': '20220426.v0.1.8a', + 'version': '20220515.v0.1.8b', 'version.min_required': '2.0.0', 'version.packaged': '2021.09.20', 'version.usable_until': None} \ No newline at end of file