diff --git a/agent_based/curl.py b/agent_based/curl.py index cc80a53bdc5850ff0bbf2f712bc2567c28c393e1..2d88a7c0498cb517ba4c4cb4af410a265cd663c9 100644 --- a/agent_based/curl.py +++ b/agent_based/curl.py @@ -25,7 +25,7 @@ # 2022-03-18: added regex pattern match # 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 # Example output from agent: # @@ -267,7 +267,12 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult: ('referer', 'Referer'), ]: if _data['data'].get(key): - value = _data['data'][key].replace('://', ': //') # ugly workaround to stop cmk from replacing the url + value = _data['data'][key] + if value.startswith('http'): + if params.get('clickable_url'): + value = f'<a href={value} target="blank">{value}</a>' + else: + value = f'{value.replace("://", ": //")}' # ugly workaround to stop cmk from replacing the url yield Result(state=State.OK, notice=f'{label}: {value}') if curl_error_code != 0: diff --git a/agents/bakery/curl.py b/agents/bakery/curl.py index 8360d632aeedb86ec6924269f8a15e273adb112c..50f3ac01cba327cba5ddbbbd0ee29a2b382091a0 100755 --- a/agents/bakery/curl.py +++ b/agents/bakery/curl.py @@ -51,11 +51,10 @@ # 2022-04-10: added deployment of cURL executables # no separate WATO rules per OS necessary anymore # reworked to make scalable for multiple OSs (THX to andreas.doehler[at]gmail[dot]com) -# removed data adjustments between default and per url settings after WATO rework # from pathlib import Path -from typing import List, Dict, Any +from typing import List, Tuple, Dict, Any from dataclasses import dataclass from cmk.utils import ( @@ -180,8 +179,8 @@ def get_curl_files(conf) -> FileGenerator: _headers = [] # filter options - _options.append(f'--head') if url_settings.get('get_header_only') else None - _options.append(f'--compressed') if url_settings.get('compressed') else None + _options.append(url_settings['get_header_only']) if url_settings.get('get_header_only') else None + _options.append(url_settings['compressed']) if url_settings.get('compressed') else None _options.append(f'--max-time {url_settings["max_time"]}') if url_settings.get('max_time') else None _options.append(f'--speed-time {url_settings["speed_time"]}') if url_settings.get('speed_time') else None _options.append(f'--connect-timeout {url_settings["connect_timeout"]}') if url_settings.get('connect_timeout') else None @@ -239,7 +238,7 @@ def get_curl_files(conf) -> FileGenerator: if url_settings.get('advanced_settings'): allow_beast, cr2lf, no_apln, no_buffering, no_npn, no_sessionid, no_keepalive, \ - path_as_is, tcp_fastopen, tcp_nodelay = url_settings['advanced_settings'] + path_as_is, tcp_fastopen, tcp_nodelay = url_settings['advanced_settings'] _options.append(f'--ssl-allow-beast') if allow_beast else None _options.append(f'--crlf') if cr2lf else None @@ -279,7 +278,7 @@ def get_curl_files(conf) -> FileGenerator: _options.append(f'--ftp-pret') if send_pret else None _options.append(f'--ftp-skip-pasv-ip') if skip_ip else None else: - no_send_eprt, active_address = ftp_mode[1] + no_send_eprt, active_address = ftp_options[1] _options.append(f'--disable-eprt') if no_send_eprt else None _options.append(f'--ftp-port {active_address}') if active_address else None if ftp_options.get('ftp_ssl_control'): @@ -335,7 +334,7 @@ def get_curl_files(conf) -> FileGenerator: except ValueError: # 2022-03-23: added ssh settings insecure, ocsp, no_revoke, cert_chain, pub_md5, pub_sha256, pub_key = url_settings['cert_verify'] - _options.append(f'--insecure') if insecure else None + _options.append(f'--insecure') if insecure else None _options.append(f'--cert-status') if ocsp else None _options.append(f'--ssl-no-revoke') if no_revoke else None _options.append(f'--hostpubmd5 {pub_md5}') if pub_md5 else None diff --git a/curl.mkp b/curl.mkp index 4ca1c975b086b2dad4e2dadc997cff0324fa258a..933bf2ad422fab97d505f1a5703c3b51c058f020 100644 Binary files a/curl.mkp and b/curl.mkp differ diff --git a/packages/curl b/packages/curl index fee221aa2f8b180d129a0d90a3139932a3a5c7f4..cd74d0b09c56e79950068be5f53c8460bba7e469 100644 --- a/packages/curl +++ b/packages/curl @@ -26,7 +26,7 @@ 'name': 'curl', 'num_files': 6, 'title': 'cURL agent plugin', - 'version': '20220411.v0.1.7', + 'version': '20220426.v0.1.8a', '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 d24e839fb84c0a194b5b6c9678a8e32c489d1e2f..6a5fce54c8ad690a70ce6c3dd7c9d996e64fb3bd 100644 --- a/web/plugins/wato/curl.py +++ b/web/plugins/wato/curl.py @@ -67,35 +67,34 @@ # 2022-03-28: added options --mail-auth, --mail-from, --mail-rcpt, --mail-rcpt-allowfails, --crlf, --upload-file (SMTP) # 2022-04-10: added options to deploy cURL executable, no separate rules for curl and curl executable anymore # windows/linux summarized under on option, no separate WATO rules per OS necessary anymore -# replaced most CascadingDropdown with Alternative to avoid the need for adusting default and url settings -# in the bakery -# 2020-04-11: fixed user-agent per url (changed from CascadingDropdown to Alternative) +# 2022-04-26: added check option clickable_url +# clarified option 'Don\'t verify certificate/pub key', 'Don\'t stop at verify errors (certificate/pub key)' # import ipaddress from cmk.gui.i18n import _ from cmk.gui.exceptions import MKUserError from cmk.gui.valuespec import ( - Age, - Alternative, - CAorCAChain, - CascadingDropdown, - Checkbox, Dictionary, - DropdownChoice, + ListOf, + CascadingDropdown, + TextUnicode, FixedValue, - Foldable, Integer, - ListOf, - ListOfStrings, + Tuple, + DropdownChoice, MonitoringState, - Optional, + ListOfStrings, TextInput, - TextUnicode, + Checkbox, Transform, - Tuple, - UploadOrPasteTextFile, + CAorCAChain, + Optional, + Foldable, + Age, # Url, + UploadOrPasteTextFile, + Alternative, ) from cmk.gui.plugins.wato import ( rulespec_registry, @@ -111,7 +110,7 @@ from cmk.gui.cee.plugins.wato.agent_bakery.rulespecs.utils import ( RulespecGroupMonitoringAgentsAgentPlugins, ) -bakery_plugin_version = '20220410.v0.0.7' +bakery_plugin_version = '20220426.v0.0.8' # unsafe characters https://www.tutorialspoint.com/html/html_url_encoding.htm forbidden_chars = '"<>#%{}|\^~[]` \'' @@ -140,6 +139,13 @@ _limits_no_transform = [ ] _curl_check_elements = [ + ('clickable_url', + FixedValue( + True, + title=_('Render clickable URLs for HTTP/HTTPS (see Inline help)'), + totext=_(''), + help=_('Needs "Escape HTML in service output" rule or in Global settings enabled to work.') + )), ('state_item_not_found', MonitoringState( default_value=1, @@ -361,7 +367,8 @@ _option_verify_remote_host = ('cert_verify', Tuple( title='Configure verification of remote host (certificate/pub key)', elements=[ - Checkbox('Don\'t verify certificate/pub key'), + # Checkbox('Don\'t verify certificate/pub key'), + Checkbox('Don\'t stop at verify errors (certificate/pub key)'), Checkbox('Use OCSP to check certificate status'), Checkbox('Disable cert revocation checks (WinSSL)'), Optional(Foldable(CAorCAChain()), label='Certificate to verify against', ), @@ -392,8 +399,7 @@ _option_regex_response = ('regex_response', elements=[ TextUnicode( label=_('Regular expression'), - placeholder=_('If empty regex search will be disabled'), - size=70, + placeholder=_('If empty regex search will be disabled') ), Checkbox('Case insensitive'), Checkbox('Multiline string matching'), @@ -419,17 +425,17 @@ _option_advanced_settings = ('advanced_settings', _options_get_header_only = ('get_header_only', FixedValue( - True, - # help=_('cURL will will only download headers. Implements the "--head" option'), + '--head', title=_('Get header only'), - totext=_(''), + totext=_('Only headers will be downloaded'), + help=_('cURL will will only download headers. Implements the "--head" option'), )) _url_get_header_only = ('get_header_only', - Alternative( + DropdownChoice( title=_('Get Header only'), - elements=[ - _options_get_header_only[1], - FixedValue(None, title=_('Get the hole document'), totext=_('')), + choices=[ + ('--head', _('Get header only')), + ('', _('Get the hole document')), ], )) @@ -480,12 +486,8 @@ _option_auth_priv_key = ('priv_key_auth', title=_('Pass phrase'), allow_empty=False, ), - Foldable( - UploadOrPasteTextFile( - title='Private key', - file_title='Private key (PEM)' - ), - title='Private key'), + Foldable(UploadOrPasteTextFile(title='Private key', file_title='Private key (PEM)'), + title='Private key'), ] )) _option_auth = ('user_auth', @@ -530,6 +532,7 @@ _option_proxy_server = ('proxy_server', ], orientation='horizontal', )) + _option_proxy_auth = ('proxy_auth', Tuple( title=_('Proxy authentication'), @@ -561,6 +564,7 @@ _option_proxy_auth = ('proxy_auth', ]), ], )) + _options_proxy = ('http_proxy', Alternative( title=_('Configure proxy server'), @@ -672,7 +676,7 @@ _option_ftp_settings = ('ftp_settings', ('ftp_create_dirs', FixedValue( True, title=_('Create remote dir(s)'), - totext=_('') + totext=_('enabled') )), ('ftp_change_cwd_method', DropdownChoice( title=_('Change working directory method'), @@ -733,17 +737,17 @@ _option_ftp_settings = ('ftp_settings', ('compressed_ssh', FixedValue( True, title=_('Enable ssh compression'), - totext=_(''), + totext=_('enabled'), )), ('list_only', FixedValue( True, title=_('Enable list only'), - totext=_(''), + totext=_('enabled'), )), ('use_ascii', FixedValue( True, title=_('Enable ASCII transfer'), - totext=_(''), + totext=_('enabled'), )), ], ), @@ -850,7 +854,7 @@ _option_mail_settings = ('mail_settings', ('mail_rpct_allowfail', FixedValue( True, title=_('Allow some mail to addresses to fail'), - totext=_('') + totext=_('enabled') )) ] ), @@ -880,7 +884,7 @@ _option_api_key_header = ('api_key_header', )) _url_api_key_header = ('api_key_header', Alternative( - title=_('Override API key header'), + title=_('Set API key header'), elements=[ _option_api_key_header[1], FixedValue(None, title=_('Don\'t configure an API key header'), totext=_('')), @@ -1063,11 +1067,13 @@ _option_user_agent = ('user_agent', forbidden_chars='"|' )) _url_user_agent = ('user_agent', - Alternative( - title=_('Override user agent'), - elements=[ - _option_user_agent[1], - FixedValue(None, title=_('Don\'t configure a user agent'), totext=_('')), + CascadingDropdown( + title=_('Set user agent'), + sorted=False, + choices=[ + ('user_agent', _('Override default user agent'), + _option_user_agent[1],), + ('', _('Don\'t configure a user agent')), ], )) @@ -1090,20 +1096,20 @@ _url_referer = ('referer', _options_compressed = ('compressed', FixedValue( - True, + '--compressed', title=_('Request compressed response'), - totext=_(''), + totext=_('Request compressed response enabled'), )) _url_compressed = ('compressed', - Alternative( + DropdownChoice( title=_('Request compressed response'), - elements=[ - _options_compressed[1], - FixedValue(None, title=_('Don\'t Request compressed response'), totext=_('')), + choices=[ + ('--compressed', _('Request compressed response')), + ('', _('Don\'t Request compressed response')), ], )) -_options_post = ('post_binary', +_option_post = ('post_binary', Tuple( title=_('Send HTTP POST data'), elements=[ @@ -1123,14 +1129,6 @@ _options_post = ('post_binary', ), ] )) -_url_post = ('post_binary', - Alternative( - title=_('Override send HTTP POST data'), - elements=[ - _options_post[1], - FixedValue(None, title='Don\'t send HTTP POST data', totext=_('')), - ] - )) _option_url_settings = ('url_settings', Foldable( @@ -1144,7 +1142,7 @@ _option_url_settings = ('url_settings', _url_get_header_only, _option_regex_response, _url_compressed, - _url_post, + _option_post, _url_api_key_header, _url_referer, _url_request_headers, @@ -1227,7 +1225,7 @@ _option_default_settings = ('default_settings', _options_get_header_only, _option_regex_response, _options_compressed, - _options_post, + _option_post, _option_api_key_header, _option_referer, _option_request_headers,