diff --git a/agent_based/curl.py b/agent_based/curl.py index 38f53b8ae30bcaba231c53da731c56150e5aec48..2350da37059427c933af96e75e918c0142f849dc 100644 --- a/agent_based/curl.py +++ b/agent_based/curl.py @@ -23,6 +23,7 @@ # 2022-03-12: added cafile and capath to Cert info section # added max_age # 2022-03-18: added regex pattern match +# 2022-03-22: added curl_error_code_to_ignore and http_error_code_to_ignore options # # Example output from agent: @@ -268,16 +269,29 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: yield Result(state=State.OK, notice=f'{label}: {value}') if curl_error_code != 0: - yield Result( - state=State(params['state_curl_result_not_0']), - 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")}' - ) + if curl_error_code in params['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']), + 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")}' + ) if http_return_code < 400: # no connect, Ok, Redirect yield Result(state=State.OK, notice=f'HTTP Return code: {http_return_code}') else: - yield Result(state=State(params['state_http_result_not_200']), summary=f'HTTP Return code: {http_return_code}') + if http_return_code in params['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']), + 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}') @@ -473,7 +487,9 @@ register.check_plugin( 'max_age': (None, None, None), 'state_item_not_found': 3, 'state_http_result_not_200': 1, + 'http_error_code_to_ignore': [], 'state_curl_result_not_0': 1, + 'curl_error_code_to_ignore': [], 'state_verify_sll_not_0': 1, 'state_expected_str_not_found': 1, 'state_header_str_not_found': 1, diff --git a/agents/bakery/curl.py b/agents/bakery/curl.py index 692606e428353863a1609804dc9a0c51b7cf7042..8c8045bbbbaa9c9bd4f50a3c912034a58c3bf6d7 100755 --- a/agents/bakery/curl.py +++ b/agents/bakery/curl.py @@ -65,13 +65,13 @@ def get_curl_files(conf: Tuple[str, Dict[str, List[any]]]) -> FileGenerator: if conf[0] == 'linux': _os = OS.LINUX _script = 'curl.sh' - _curl_output = '-o /dev/null' + _curl_output = '--output /dev/null' _temp_path = '/var/tmp/' _conf_path = '/etc/check_mk/' elif conf[0] == 'windows': _os = OS.WINDOWS _script = 'curl.ps1' - _curl_output = '-o NUL' + _curl_output = '--output NUL' _temp_path = 'c:/windows/temp/' _conf_path = 'C:/ProgramData/checkmk/agent/config/' else: @@ -400,7 +400,7 @@ def get_curl_files(conf: Tuple[str, Dict[str, List[any]]]) -> FileGenerator: url_settings.pop('ftp_settings') if save_output: - options_array.append(f'-o {_temp_path}curl_output') + options_array.append(f'--output {_temp_path}curl_output') else: options_array.append(_curl_output) diff --git a/agents/plugins/curl.ps1 b/agents/plugins/curl.ps1 index 5df2c0777641874f9012bcfa2a9dc17107722e8c..ba27c302074cb9b8027686dd45268aa8f825afbe 100755 --- a/agents/plugins/curl.ps1 +++ b/agents/plugins/curl.ps1 @@ -58,7 +58,7 @@ if (Test-Path -Path "C:\ProgramData\checkmk\agent\bin\curl.exe" -PathType Leaf) exit 0 } -$CURL_OPTIONS="-q -w %{json} -s --verbose --stderr $TEMP_DIR\curl_session" +$CURL_OPTIONS="--disable --write-out %{json} --silent --verbose --include --stderr $TEMP_DIR\curl_session" $CURL_OPTIONS=$CURL_OPTIONS.Substring(0,$CURL_OPTIONS.Length -0) $CURL_RUN="FIRST" $CURL_RESULT="" diff --git a/agents/plugins/curl.sh b/agents/plugins/curl.sh index df04ec091e9b64a747b0823e4dcddea1220bb5c4..5189a271ab268a3f1181fb7b272e2d535237cb73 100755 --- a/agents/plugins/curl.sh +++ b/agents/plugins/curl.sh @@ -28,7 +28,7 @@ CONF_DIR="/etc/check_mk" LIB_DIR="/usr/lib/check_mk_agent" TEMP_DIR="/var/tmp" -CURL_OPTIONS="-q -w %{json} -s --verbose --stderr $TEMP_DIR/curl_session" +CURL_OPTIONS="--disable --write-out %{json} --silent --verbose --include --stderr $TEMP_DIR/curl_session" CURL_CONFIG=curl.cfg CURL_RUN="FIRST" CURL_OUTPUT="$TEMP_DIR/curl_output" diff --git a/curl.mkp b/curl.mkp index eb67f881b55d9c668db2d90de7a9fc1bda70f58f..15c0725660715888787cdc2de7d669f0716e3c2e 100644 Binary files a/curl.mkp and b/curl.mkp differ diff --git a/packages/curl b/packages/curl index 1881d66dea295850717ae63dbfc1ebe2ed27f768..fb86a1ee723fad1d3c4fa1c1e3448d5c948aef3e 100644 --- a/packages/curl +++ b/packages/curl @@ -21,7 +21,7 @@ 'name': 'curl', 'num_files': 6, 'title': 'cURL agent plugin', - 'version': '20220320.v0.1.2', + 'version': '20220322.v0.1.2', 'version.min_required': '2.0.0', 'version.packaged': '2021.09.20', 'version.usable_until': None} \ No newline at end of file diff --git a/web/plugins/wato/curl.py b/web/plugins/wato/curl.py index 3fd45740788941a7698509eb51ab9e7b7ca0a565..b04b3553f46c23d31f584187477662c3465515e5 100644 --- a/web/plugins/wato/curl.py +++ b/web/plugins/wato/curl.py @@ -58,6 +58,8 @@ # added options --ftp-ssl-control, --ftp-ssl-ccc, --ftp-ssl-ccc-mode # 2022-03-21: moved --connect-timeout, --limit-rate, --max-filesize, --max-time, --speed-limit, --speed-time # to "limits" sub Directory +# 2022-03-22: added curl_error_code_to_ignore and http_error_code_to_ignore options +# import ipaddress from cmk.gui.i18n import _ from cmk.gui.exceptions import MKUserError @@ -137,12 +139,26 @@ _curl_check_elements = [ title=_('State on HTTP result not OK'), help=_('Monitoring state if the HTTP return code is not in 2xx or 3xx. Default is WARN.') )), + ('http_error_code_to_ignore', + ListOfStrings( + title=_('HTTP:q error codes to ignore'), + allow_empty=False, + orientation='horizontal', + valuespec=Integer(size=3, minvalue=0, maxvalue=999), + )), ('state_curl_result_not_0', MonitoringState( default_value=1, title=_('State on cURL exit code not OK'), help=_('Monitoring state if the exit code is not 0. Default is WARN.') )), + ('curl_error_code_to_ignore', + ListOfStrings( + title=_('cURL error codes to ignore'), + allow_empty=False, + orientation='horizontal', + valuespec=Integer(size=3, minvalue=0, maxvalue=999), + )), ('state_verify_sll_not_0', MonitoringState( default_value=1, @@ -683,7 +699,7 @@ _option_header_strings = ('header_strings', title=_('Strings to expect in header'), # orientation='horizontal', allow_empty=False, - valuespec=TextInput(allow_empty=False, regex='[a-zA-Z0-9\.]'), + valuespec=TextInput(allow_empty=False, regex='[a-zA-Z0-9\\.]'), )) _url_header_strings = ('header_strings', CascadingDropdown(