Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit c73d0890 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

update project

parent 7b14e9a2
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,8 @@
# added num_connects, num_redirects, size_download, size_header, speed_download
# added redirect_url, remote_ip, scheme, http_version, http_connect
# 2022-02-22: added params for all values
# 2022-02-23: changed items on service info line
#
# Example output from agent:
#
......@@ -225,14 +227,14 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult:
yield Result(state=State.OK, notice=f'Proxy connect code: {_data["data"]["http_connect"]}')
yield Result(state=State.OK, notice=f'cURL options: {_data["curl_options"]}')
for key, label in [
('time_namelookup', 'Time name lookup',),
('time_connect', 'Time connect',),
('time_appconnect', 'Time app connect',),
('time_pretransfer', 'Time pre transfer',),
('time_redirect', 'Time redirect',),
('time_starttransfer', 'Time start transfer',),
('time_total', 'Time total',),
for key, label, notice_only in [
('time_namelookup', 'Time name lookup', True,),
('time_connect', 'Time connect', True, ),
('time_appconnect', 'Time app connect', True, ),
('time_pretransfer', 'Time pre transfer', True, ),
('time_redirect', 'Time redirect', True,),
('time_starttransfer', 'Time start transfer', True,),
('time_total', 'Time total', False,),
]:
if _data['data'].get(key):
value = float(_data['data'][key].replace(',', '.'))
......@@ -243,15 +245,15 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult:
label=label,
value=value,
metric_name=key,
notice_only=True,
notice_only=notice_only,
render_func=lambda v: f'{value}s',
levels_lower=lower,
levels_upper=upper,
)
for key, label in [
('num_connects', '# of connects',),
('num_redirects', '# of redirects',),
for key, label, notice_only in [
('num_connects', '# of connects', True, ),
('num_redirects', '# of redirects', True, ),
]:
if _data['data'].get(key):
value = float(_data['data'][key].replace(',', '.'))
......@@ -260,15 +262,15 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult:
label=label,
value=value,
metric_name=key,
notice_only=True,
notice_only=notice_only,
render_func=lambda v: f'{value}',
levels_lower=params[key].get('lower'),
levels_upper=params[key].get('upper'),
)
for key, label in [
('size_download', 'Downloaded size',),
('size_header', 'Header size',),
for key, label, notice_only in [
('size_download', 'Downloaded size', False,),
('size_header', 'Header size', True,),
]:
if _data['data'].get(key):
value = float(_data['data'][key].replace(',', '.'))
......@@ -277,14 +279,14 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult:
label=label,
value=value,
metric_name=key,
notice_only=True,
notice_only=notice_only,
render_func=render.bytes,
levels_lower=params[key].get('lower'),
levels_upper=params[key].get('upper'),
)
for key, label in [
('speed_download', 'Download speed',),
for key, label, notice_only in [
('speed_download', 'Download speed', False),
]:
if _data['data'].get(key):
value = float(_data['data'][key].replace(',', '.'))
......@@ -293,7 +295,7 @@ def check_curl(item, params, section: Dict[str, Any]) -> CheckResult:
label=label,
value=value,
metric_name=key,
notice_only=True,
notice_only=notice_only,
render_func=render.networkbandwidth,
levels_lower=params[key].get('lower'),
levels_upper=params[key].get('upper'),
......
......@@ -12,6 +12,8 @@
# 2022-02-19: integrated per url settings
# added proxy settings (--proxy, --proxy-user, --proxy-digest/--proxy-basic/--proxy-ntlm/--proxy-anyauth)
# moved the curl.exe deployment to curl_windows.mkp package
# 2022-02-23: fixed handling aof user_auth settings
# fixed options in curl.cfg for windows
from pathlib import Path
from typing import List
......@@ -28,7 +30,7 @@ from cmk.base.cee.plugins.bakery.bakery_api.v1 import (
)
bakery_version = '20220219.v0.0.2'
bakery_version = '20220223.v0.0.2'
def get_curl_files(conf: List[any]) -> FileGenerator:
......@@ -68,7 +70,8 @@ def get_curl_files(conf: List[any]) -> FileGenerator:
os = conf[0]
options = conf[1].copy()
ca_certs = []
url_cfg_lines = []
url_cfg_lines_linux = []
url_cfg_lines_windows = []
url_list = options['url_list']
default_settings = options.get('default_settings', {})
......@@ -84,12 +87,16 @@ def get_curl_files(conf: List[any]) -> FileGenerator:
# adjust per url settings with default settings
for key in [
'http_proxy',
'user_auth',
# 'user_auth', # is always a tuple
'ca_sert',
]:
if type(url_settings.get(key)) == tuple:
url_settings.update({key: url_settings[key][1]})
if type(url_settings.get('user_auth')) == tuple:
if type(url_settings.get('user_auth')[1]) == dict:
url_settings.update(url_settings.get('user_auth')[1])
if url_settings.get('http_proxy'):
proxy_server, proxy_port = url_settings['http_proxy']['proxy_server']
options_array.append(f'--proxy http://{proxy_server}:{proxy_port}')
......@@ -104,14 +111,14 @@ def get_curl_files(conf: List[any]) -> FileGenerator:
url_settings.pop('http_proxy')
if url_settings.get('user_auth'):
user, user_password, user_auth = url_settings['proxy_auth']
user, user_password, user_auth = url_settings['user_auth']
if user_password[0] == 'store':
pw = password_store.extract(user_password[1])
else:
pw = user_password[1]
options_array.append(f'--user {user}:{pw}')
options_array.append(user_auth)
url_settings.pop('user_proxy')
url_settings.pop('user_auth')
if url_settings.get('ca_cert'):
ca_certs.append((f'{service_name}.pem', url_settings.get('ca_cert')))
......@@ -124,7 +131,9 @@ def get_curl_files(conf: List[any]) -> FileGenerator:
curl_options = options_separator.join(options_array)
# if curl_options:
url_cfg_lines.append(f'{service_name}{field_separator}{url}{field_separator}{curl_options.strip()}')
url_cfg_lines_linux.append(f'{service_name}{field_separator}{url}{field_separator}{curl_options.strip()}')
url_cfg_lines_windows.append(f'{service_name}{field_separator}{url}{field_separator}"{curl_options.strip()}"')
# else:
# url_cfg_lines.append(f'{service_name}{field_separator}"{url}"')
......@@ -141,7 +150,7 @@ def get_curl_files(conf: List[any]) -> FileGenerator:
)
yield PluginConfig(
base_os=OS.LINUX,
lines=url_cfg_lines,
lines=url_cfg_lines_linux,
target=Path('curl.cfg'),
include_header=False,
)
......@@ -159,7 +168,7 @@ def get_curl_files(conf: List[any]) -> FileGenerator:
)
yield PluginConfig(
base_os=OS.WINDOWS,
lines=url_cfg_lines,
lines=url_cfg_lines_windows,
target=Path('curl.cfg'),
include_header=False,
)
......
......@@ -13,13 +13,13 @@
:: 2022-02-16: added file checks for CURL_EXECUTABLE and CURL_FORMAT
:: 2022-02-17: added ERRORLEVEL
:: 2022-02-21: added curl_option to the output
:: 2022-02-22: fixed search for curl.exe
:: 2022-02-23: fixed handling of options from curl.cfg
echo | set /p="<<<curl:sep(0)>>>"
echo.
setlocal
SETLOCAL ENABLEDELAYEDEXPANSION
set CURL_EXECUTABLE=C:\ProgramData\checkmk\agent\bin\curl.exe
set CURL_FORMAT=C:\ProgramData\checkmk\agent\plugins\curl.format
set CURL_CONFIG=C:\ProgramData\checkmk\agent\config\curl.cfg
set CURL_OPTIONS=-q -w @%CURL_FORMAT% -o NUL -s
......@@ -36,24 +36,29 @@ If Not Exist "%CURL_FORMAT%" (
)
:: first check for curl.exe in cmk agent directory
If Not Exist "%CURL_EXECUTABLE%" (
:: if not found check for the system provided curl.exe -> https://curl.se/windows/microsoft.html
set CURL_EXECUTABLE="C:\Windows\System32\curl.exe"
If Not Exist "%CURL_EXECUTABLE%" (
echo {"ERROR":"executable file %CURL_EXECUTABLE% does not exist"}
exit
)
if exist "C:\ProgramData\checkmk\agent\bin\curl.exe" (
set CURL_EXECUTABLE=C:\ProgramData\checkmk\agent\bin\curl.exe
) else (
:: if not found look for system provided file
if exist "C:\Windows\System32\curl.exe" (
set CURL_EXECUTABLE=C:\Windows\System32\curl.exe
) else (
echo {"ERROR":"executable file curl.exe not found"}
)
)
echo | set /p={
FOR /F "tokens=1,2,3 delims=|" %%a IN ('Type "%CURL_CONFIG%"') DO @call :Sub %%a %%b %%c
FOR /F "tokens=1,2,3 delims=|" %%a IN ('Type "%CURL_CONFIG%"') DO @call :GET_URL %%a %%b %%c
echo }
goto :EOF
:Sub
:GET_URL
set OPTIONS=%3
:: trim "options" to options
set STRIP_OPTIONS=%OPTIONS:~1,-1%
if "%CURL_RUN%"=="SECOND" (
echo | set /p=,
) else (
......@@ -62,8 +67,8 @@ goto :EOF
echo | set /p=""%1":{"url":"%2","data""
echo | set /p=:
call "%CURL_EXECUTABLE%" --url %2 %CURL_OPTIONS% %3
call "%CURL_EXECUTABLE%" --url %2 %CURL_OPTIONS% %STRIP_OPTIONS%
echo | set /p=,"error_level":"%ERRORLEVEL%"
echo | set /p=,"curl_options":"%3"
echo | set /p=,"curl_options":"%STRIP_OPTIONS%"
echo | set /p=}
goto :EOF
......@@ -53,6 +53,8 @@ while read -r LINE; do
SERVICE_NAME=$(echo "$LINE" | awk -F'|' '{print $1}')
URL=$(echo "$LINE" | awk -F'|' '{print $2}')
OPTIONS=$(echo "$LINE" | awk -F'|' '{print $3}')
# FIELDS=($(awk -F"|" '{$1=$1} 1' <<<"${LINE}"))
if [ "$CURL_RUN" = "SECOND" ]
then
......
No preview for this file type
......@@ -11,7 +11,7 @@
'name': 'curl',
'num_files': 8,
'title': 'cURL agent plugin',
'version': '20220122.v0.0.2',
'version': '20220123.v0.0.2',
'version.min_required': '2.0.0',
'version.packaged': '2021.09.20',
'version.usable_until': None}
\ No newline at end of file
......@@ -49,7 +49,7 @@ from cmk.gui.cee.plugins.wato.agent_bakery.rulespecs.utils import (
RulespecGroupMonitoringAgentsAgentPlugins,
)
bakery_plugin_version = '20220219.v0.0.2'
bakery_plugin_version = '20220223.v0.0.2'
forbidden_chars = '|<> '
_limits = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment