diff --git a/README.md b/README.md index 52d56f5b22af6dfbb321e401ad00fd35ba5edd4e..3f103c487bb1907d0610789b519ece887be72a54 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[PACKAGE]: ../../raw/2.2.x/mkp/curl-0.2.2-20241123.mkp "curl-0.2.2-20241123.mkp" +[PACKAGE]: ../../raw/2.2.x/mkp/curl-0.2.3-20241124.mkp "curl-0.2.3-20241124.mkp" [EXECUTABLE]: ../../raw/2.2.x/mkp/curl_executable-20220410.v7.82.0.mkp "curl_executable-20220410.v7.82.0.mkp" # cURL agent plugin for Linux and Windows diff --git a/mkp/curl-0.2.3-20241124.mkp b/mkp/curl-0.2.3-20241124.mkp new file mode 100644 index 0000000000000000000000000000000000000000..f42b19a907571001be5041658530f420d3664335 Binary files /dev/null and b/mkp/curl-0.2.3-20241124.mkp differ diff --git a/source/agent_based/curl.py b/source/agent_based/curl.py index 87590b591ffac106b75a18fdd853f2321c1ef4d9..b187697eb013d99819e3fefed61f269cbab39a01 100644 --- a/source/agent_based/curl.py +++ b/source/agent_based/curl.py @@ -30,6 +30,7 @@ # 2022-05-17: fixed wrong import path for _TIME_UNITS and _gen_timespan_chunks # 2023-06-07: moved gui files to ~/local/lib/chek_mk/gui/plugins/... # 2024-11-23: fixed http_error_code_to_ignore and curl_error_code_to_ignore not working (compare int with str) +# 2024-11-24: removed empty default parameters # Example output from agent: # @@ -289,7 +290,7 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: try: _data = section[item] except KeyError: - yield Result(state=State(params['state_item_not_found']), notice='Item not found in agent data') + yield Result(state=State(params.get('state_item_not_found', 3)), notice='Item not found in agent data') return # url = _data['url'].replace('://', ': //') # ugly workaround to stop cmk from replacing the url @@ -314,13 +315,13 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: yield Result(state=State.OK, notice=f'{label}: {value}') if curl_error_code != 0: - if str(curl_error_code) in params['curl_error_code_to_ignore']: + if str(curl_error_code) in params.get('curl_error_code_to_ignore', []): yield Result( state=State.OK, notice=f'curl error code: {curl_error_code}, {_curl_error_codes.get(curl_error_code, "N/A")}') else: yield Result( - state=State(params['state_curl_result_not_0']), + state=State(params.get('state_curl_result_not_0', 1)), summary=f'curl error code: {curl_error_code} see details', details=f'curl error code: {curl_error_code}, {_curl_error_codes.get(curl_error_code, "N/A")}' ) @@ -328,20 +329,20 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: if http_return_code < 400: # no connect, Ok, Redirect yield Result(state=State.OK, notice=f'HTTP Return code: {http_return_code}') else: - if str(http_return_code) in params['http_error_code_to_ignore']: + if str(http_return_code) in params.get('http_error_code_to_ignore', []): yield Result( state=State.OK, notice=f'HTTP Return code: {http_return_code}' ) else: yield Result( - state=State(params['state_http_result_not_200']), + state=State(params.get('state_http_result_not_200', 1)), notice=f'HTTP Return code: {http_return_code}' ) if ssl_verify_result == 0: yield Result(state=State.OK, notice=f'SSL verify result: {ssl_verify_result}') else: - yield Result(state=State(params['state_verify_sll_not_0']), summary=f'SSL verify result: {ssl_verify_result}') + yield Result(state=State(params.get('state_verify_sll_not_0', 1)), summary=f'SSL verify result: {ssl_verify_result}') for key, label in [ ('scheme', 'Scheme (protocol)'), @@ -365,7 +366,7 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: yield Result(state=State.OK, notice=f'Response string: "{expected_string}" found') else: yield Result( - state=State(params['state_expected_str_not_found']), + state=State(params.get('state_expected_str_not_found', 1)), notice=f'Response string: "{expected_string}" not found' ) @@ -375,11 +376,11 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: yield Result(state=State.OK, notice=f'Header string: "{header_strings}" found') else: yield Result( - state=State(params['state_header_str_not_found']), + state=State(params.get('state_header_str_not_found', 1)), notice=f'Header string: "{header_strings}" not found' ) - regex_match, regex_no_match, regex_missing = params['state_for_regex'] + regex_match, regex_no_match, regex_missing = params.get('state_for_regex', (0,1,0)) if _data.get('regex') == 0: # match yield Result(state=State(regex_match), notice='Regex state: pattern matches') elif _data.get('regex') == 1: # no match @@ -387,7 +388,7 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: elif not _data.get('regex'): # missing info yield Result(state=State(regex_missing), notice='Regex state: missing pattern match info') - max_age_warn, max_age_crit, max_age_state = params['max_age'] + max_age_warn, max_age_crit, max_age_state = params.get('max_age', (None, None, None)) if max_age_warn: max_age = None if _data.get('RESPONSE_HEADER'): @@ -426,14 +427,14 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: yield Result(state=State.OK, notice=f'{label}: {_data["tls_info"][key]}') if _data['tls_info'].get('time_left'): - if params['cert_time_left'].get('upper'): - warn, crit = params['cert_time_left'].get('upper') + if params.get('cert_time_left', {}).get('upper'): + warn, crit = paramsget('cert_time_left', {}).get('upper') upper = (warn * 86400, crit * 86400) else: upper = None - if params['cert_time_left'].get('lower'): - warn, crit = params['cert_time_left'].get('lower') + if params.get('cert_time_left', {}).get('lower'): + warn, crit = params.get('cert_time_left', {}).get('lower') lower = (warn * 86400, crit * 86400) else: lower = None @@ -474,8 +475,8 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: metric_name=key, notice_only=notice_only, render_func=render_func, - levels_lower=params[key].get('lower'), - levels_upper=params[key].get('upper'), + levels_lower=params.get(key, {}).get('lower'), + levels_upper=params.get(key, {}).get('upper'), ) for key, label, notice_only, render_func in [ @@ -501,11 +502,11 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: metric_name=key, notice_only=notice_only, render_func=render_func, - levels_lower=params[key].get('lower'), - levels_upper=params[key].get('upper'), + levels_lower=params.get(key, {}).get('lower'), + levels_upper=params.get(key, {}).get('upper'), ) - - show_request_header, show_response_headers, show_session_info, show_raw_data = params['show_additional_info'] + + show_request_header, show_response_headers, show_session_info, show_raw_data = params.get('show_additional_info', (None, None, None, None)) if show_request_header and _data.get('REQUEST_HEADER'): yield Result(state=State.OK, notice=f' ') yield Result(state=State.OK, notice=f'Request headers:') @@ -544,34 +545,34 @@ register.check_plugin( discovery_function=discovery_curl, check_function=check_curl, check_default_parameters={ - 'show_additional_info': (None, None, None, None), - 'max_age': (None, None, None), + # 'show_additional_info': (None, None, None, None), + # 'max_age': (None, None, None), 'state_item_not_found': 3, 'state_http_result_not_200': 1, - 'http_error_code_to_ignore': [], + # 'http_error_code_to_ignore': [], 'state_curl_result_not_0': 1, - 'curl_error_code_to_ignore': [], + # 'curl_error_code_to_ignore': [], 'state_verify_sll_not_0': 1, 'state_expected_str_not_found': 1, 'state_header_str_not_found': 1, 'state_for_regex': (0, 1, 0), - 'time_namelookup': {}, - 'time_connect': {}, - 'time_appconnect': {}, - 'time_pretransfer': {}, - 'time_redirect': {}, - 'time_starttransfer': {}, - 'time_total': {}, - 'num_connects': {}, - 'num_redirects': {}, - 'num_headers': {}, - 'size_download': {}, - 'size_upload': {}, - 'size_header': {}, - 'size_request': {}, - 'speed_download': {}, - 'speed_upload': {}, - 'cert_time_left': {}, + # 'time_namelookup': {}, + # 'time_connect': {}, + # 'time_appconnect': {}, + # 'time_pretransfer': {}, + # 'time_redirect': {}, + # 'time_starttransfer': {}, + # 'time_total': {}, + # 'num_connects': {}, + # 'num_redirects': {}, + # 'num_headers': {}, + # 'size_download': {}, + # 'size_upload': {}, + # 'size_header': {}, + # 'size_request': {}, + # 'speed_download': {}, + # 'speed_upload': {}, + # 'cert_time_left': {}, }, check_ruleset_name='curl' ) diff --git a/source/packages/curl b/source/packages/curl index dd8c68357568485b3d275f0d280443213917e7ee..b12ec028e0102f2f5062ded2e7bdc8ee6cc04694 100644 --- a/source/packages/curl +++ b/source/packages/curl @@ -28,7 +28,7 @@ 'lib': ['python3/cmk/base/cee/plugins/bakery/curl.py']}, 'name': 'curl', 'title': 'cURL agent plugin', - 'version': '0.2.2-20241123', + 'version': '0.2.3-20241124', 'version.min_required': '2.2.0b1', 'version.packaged': '2.2.0p36', 'version.usable_until': '2.3.0b1'}