diff --git a/agent_based/curl.py b/agent_based/curl.py index 4d1ecbc2062ee70cb9883b22d18f78f15dea7f47..cc80a53bdc5850ff0bbf2f712bc2567c28c393e1 100644 --- a/agent_based/curl.py +++ b/agent_based/curl.py @@ -24,6 +24,7 @@ # 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 +# 2022-04-06: removed .replace('://', ': //')) from json.loads() so service name is without space # # Example output from agent: @@ -215,7 +216,8 @@ def _get_tls_info(tls_lines: List[str]): def parse_curl(string_table): try: - section = json.loads(string_table[0][0].replace('://', ': //')) + # section = json.loads(string_table[0][0].replace('://', ': //')) # removed so service name is without space + section = json.loads(string_table[0][0]) except (IndexError, TypeError, json.JSONDecodeError): return {} if 'ERROR' not in section.keys(): @@ -224,7 +226,7 @@ def parse_curl(string_table): for line in string_table[1][0].replace('}{', '}|||{').split('|||'): # '{'thl-cmk.hopto.org': {'expected_strings': [['string1', 1], ['string2', 1], ['html', 0]]}}' try: - line = line.replace('://', ': //') + # line = line.replace('://', ': //') # removed so service name is without space line = json.loads(line) except json.JSONDecodeError: continue diff --git a/agents/bakery/curl.py b/agents/bakery/curl.py index 196c6e1a3e38283866c01ddf2abe31888ae0bd60..c28137e7dd4c20fe4c786afa6c1aa6633c2e761a 100755 --- a/agents/bakery/curl.py +++ b/agents/bakery/curl.py @@ -46,6 +46,8 @@ # 2022-03-24: added options --key --passs # 2022-03-25: added options --compressed-ssh, --list-only, --use-ascii # added options --path-as-is, --ssl-allow-beast, --no-buffer, --no-keepalive, --no-sessionid +# 2022-03-28: added option --crlf +# added SMTP settings: --mail-auth, --mail-from, --mail-rcpt, --mail-rcpt-allowfails, --upload-file (SMTP) # from pathlib import Path @@ -128,7 +130,8 @@ def get_curl_files(conf: Tuple[str, Dict[str, List[any]]]) -> FileGenerator: for key in [ 'ftp_settings', 'ip_address_resolution', - 'limits' + 'limits', + 'mail_settings', ]: if (key in url_settings.keys()) and (key in entry.keys()): url_settings[key].update(entry[key]) @@ -346,10 +349,12 @@ def get_curl_files(conf: Tuple[str, Dict[str, List[any]]]) -> FileGenerator: url_settings.pop('cert_verify') if url_settings.get('advanced_settings'): - allow_beast, no_apln, no_buffering, no_npn, no_sessionid, no_keepalive, \ + allow_beast, cr2lf, no_apln, no_buffering, no_npn, no_sessionid, no_keepalive, \ path_as_is, tcp_fastopen, tcp_nodelay = url_settings['advanced_settings'] if allow_beast: options_array.append(f'--ssl-allow-beast') + if cr2lf: + options_array.append(f'--crlf') if no_apln: options_array.append(f'--no-alpn') if no_buffering: @@ -455,6 +460,35 @@ def get_curl_files(conf: Tuple[str, Dict[str, List[any]]]) -> FileGenerator: options_array.append(f'--use-ascii') url_settings.pop('ftp_settings') + if url_settings.get('mail_settings'): + mail_options = url_settings['mail_settings'] + if mail_options.get('mail_from'): + options_array.append(f'--mail-from {mail_options["mail_from"]}') + if mail_options.get('mail_rcpt'): + for address in mail_options['mail_rcpt']: + options_array.append(f'--mail-rcpt {address}') + if mail_options.get('mail_auth'): + options_array.append(f'--mail-auth {mail_options["mail_auth"]}') + if mail_options.get('request'): + options_array.append(f'--request {mail_options["request"]}') + if mail_options.get('mail_rpct_allowfail'): + options_array.append(f'--mail-rcpt-allowfails') + message = [] + if mail_options.get('request_headers'): + for header, value in mail_options['request_headers']: + message.append(f'{header}: {value}') + if mail_options.get('message'): + message.append(mail_options['message']) + if message: + options_array.append(f'--upload-file {_conf_path}curl/curl_item_{curl_item}.message') + yield PluginConfig( + base_os=_os, + lines=message, + target=Path(f'curl/curl_item_{curl_item}.message'), + include_header=False, + ) + url_settings.pop('mail_settings') + if save_output: options_array.append(f'--output {_temp_path}curl_output') else: diff --git a/curl.mkp b/curl.mkp index cce478135ad49d04e80f3785b9ec19898a7e80f2..ecf9c70ffb7ca71c57ec484f831358704877964a 100644 Binary files a/curl.mkp and b/curl.mkp differ diff --git a/packages/curl b/packages/curl index b9b250c7c9ff7f9f999b6627f4566052b3dc7dde..1a8e612fd88c6dabfa5c5baf870df88f54d6402f 100644 --- a/packages/curl +++ b/packages/curl @@ -23,7 +23,7 @@ 'name': 'curl', 'num_files': 6, 'title': 'cURL agent plugin', - 'version': '20220325.v0.1.4', + 'version': '20220406.v0.1.6', '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 ac451cf05f3a6e2e9c74e877451c67ce9e48ce40..b051c4b691ffc0c72774484e158ee9a6795aefef 100644 --- a/web/plugins/wato/curl.py +++ b/web/plugins/wato/curl.py @@ -64,7 +64,7 @@ # reworked user_auth section # 2022-03-25: added options --compressed-ssh, --list-only, --use-ascii # added options --path-as-is, --ssl-allow-beast, --no-buffer, --no-keepalive, --no-sessionid -# +# 2022-03-28: added options --mail-auth, --mail-from, --mail-rcpt, --mail-rcpt-allowfails, --crlf, --upload-file (SMTP) import ipaddress from cmk.gui.i18n import _ @@ -397,6 +397,7 @@ _option_advanced_settings = ('advanced_settings', title='Advanced settings', elements=[ Checkbox('Allow SSL beast security flaw to improve interoperability'), + Checkbox('Convert LF to CRLF in upload'), Checkbox('Disable Application Layer Protocol Negotiation (ALPN)'), Checkbox('Disable buffering of the output stream'), Checkbox('Disable Next Protocol Negotiation (NPN)'), @@ -778,35 +779,35 @@ _url_header_strings = ('header_strings', _option_request_headers = ('request_headers', ListOf( Tuple( - title=_('Set request headers'), + title=_('Set headers'), orientation='horizontal', elements=[ TextUnicode( label=_('Header'), allow_empty=False, placeholder='X-your-header', - regex='[a-zA-Z0-9_\-]', + regex='[a-zA-Z0-9_\\-]', # size=30, ), TextUnicode( label=_('Value'), # allow_empty=False, placeholder='value of header', - regex='[a-zA-Z0-9_ :;.,=<>#\-@\+\*\'\\\/\?!\(\)\{\}\[\]\$\&~\^%|"`]', + # regex='[a-zA-Z0-9_ :;.,=<>#\\-@\\+\\*\'/\\?!\\(\\)\\{\\}\\[\\]\\$\\&~\\^%|"`\\]', size=50, empty_text=';' ), ] ), allow_empty=False, - title=_('Set request headers'), - add_label=_('Add reuest header'), + title=_('Set headers'), + add_label=_('Add header'), movable=True, )) _url_request_headers = ('request_headers', CascadingDropdown( - title=_('Set request headers'), + title=_('Set headers'), sorted=False, choices=[ ('request_headers', _('Override default request headers'), _option_request_headers[1]), @@ -814,6 +815,44 @@ _url_request_headers = ('request_headers', ], )) +_option_mail_settings = ('mail_settings', + Foldable( + Dictionary( + title=_('SMTP settings'), + elements=[ + ('mail_from', TextUnicode( + title=_('Mail from address'), + allow_empty=False, + )), + ('mail_rcpt', ListOfStrings( + title=_('Mail to address'), + allow_empty=False, + max_entries=5, + )), + ('mail_auth', TextUnicode( + title=_('Mail originator address'), + )), + # ('oauth2_header', TextUnicode( + # title=_('Oauth2 token'), + # )), + ('request', TextUnicode( + title=_('REQUEST command'), + help=_('Send this command instead of LIST (POP3/IMAP) or HELP/VRFY (SMTP).') + )), + _option_request_headers, + ('message', UploadOrPasteTextFile( + title=_('Message to send'), + )), + ('mail_rpct_allowfail', FixedValue( + True, + title=_('Allow some mail to addresses to fail'), + totext=_('enabled') + )) + ] + ), + title=_('Set SMTP options'), + )) + _option_api_key_header = ('api_key_header', Tuple( title=_('Set API key header'), @@ -1117,6 +1156,7 @@ _option_url_settings = ('url_settings', _option_limits, _option_address_resolution, _option_ftp_settings, + _option_mail_settings, _option_tls_ssl_version, _option_http_version, _option_advanced_settings, @@ -1199,6 +1239,7 @@ _option_default_settings = ('default_settings', _option_limits, _option_address_resolution, _option_ftp_settings, + _option_mail_settings, _option_http_version, _option_tls_ssl_version, _option_advanced_settings,