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 f5bf5a32 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

update project

parent 8c14406f
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2022-02-15
#
# based on the work by Christian Wirtz doc[at]snowheaven[dot]de
#
# 2022-02-15: rewritten for cmk 2.0
# 2022-02-20: removed "url_effective" from format file (bad output with linux: "url_effective":http://"https//checkmk.com")
# added num_connects, num_redirects, size_download, size_header, speed_download
# added redirect_url, remote_ip, scheme, http_version, http_connect
# Example output from agent:
#
# <<<curl>>>
# {
# "www.heise.de": {
# "url": "https://www.heise.de",
# "data": {
# "ssl_verify_result": "0",
# "http_return_code": "000",
# "time_namelookup": "0,000000",
# "time_connect": "0,000000",
# "time_appconnect": "0,000000",
# "time_pretransfer": "0,000000",
# "time_redirect": "0,000000",
# "time_starttransfer": "0,000000",
# "time_total": "0,000000",
# "http_connect": "000",
# "http_version": "0",
# "num_connects": "0",
# "num_redirects": "0",
# "redirect_url": "",
# "remote_ip": "",
# "scheme": "(nil)",
# "size_download": "0",
# "size_header": "0",
# "speed_download": "0,000",
# },
# "error_level": "6"
# }
# }
#
import json
from typing import Dict, Any
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import (
DiscoveryResult,
CheckResult,
)
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
register,
Service,
State,
check_levels,
Result,
render,
)
_curl_error_codes = {
1: 'Unsupported protocol. This build of curl has no support for this protocol.',
2: 'Failed to initialize.',
3: 'URL malformed. The syntax was not correct.',
4: 'A feature or option that was needed to perform the desired request was not enabled or was explicitly '
'disabled at build-time. To make curl able to do this, you probably need another build of libcurl.',
5: 'Could not resolve proxy. The given proxy host could not be resolved.',
6: 'Could not resolve host. The given remote host could not be resolved.',
7: 'Failed to connect to host.',
8: 'Weird server reply. The server sent data curl could not parse.',
9: 'FTP access denied. The server denied login or denied access to the particular resource or directory you '
'wanted to reach. Most often you tried to change to a directory that does not exist on the server.',
10: 'FTP accept failed. While waiting for the server to connect back when an active FTP session is used, '
'an error code was sent over the control connection or similar.',
11: 'FTP weird PASS reply. Curl could not parse the reply sent to the PASS request.',
12: 'During an active FTP session while waiting for the server to connect back to curl, the timeout expired.',
13: 'FTP weird PASV reply, Curl could not parse the reply sent to the PASV request.',
14: 'FTP weird 227 format. Curl could not parse the 227-line the server sent.',
15: 'FTP cannot use host. Could not resolve the host IP we got in the 227-line.',
16: 'HTTP/2 error. A problem was detected in the HTTP2 framing layer. This is somewhat generic and can be one '
'out of several problems, see the error message for details.',
17: 'FTP could not set binary. Could not change transfer method to binary.',
18: 'Partial file. Only a part of the file was transferred.',
19: 'FTP could not download/access the given file, the RETR (or similar) command failed.',
21: 'FTP quote error. A quote command returned error from the server.',
22: 'HTTP page not retrieved. The requested url was not found or returned another error with the HTTP error '
'code being 400 or above. This return code only appears if --fail is used.',
23: 'Write error. Curl could not write data to a local filesystem or similar.',
25: 'FTP could not STOR file. The server denied the STOR operation, used for FTP uploading.',
26: 'Read error. Various reading problems.',
27: 'Out of memory. A memory allocation request failed.',
28: 'Operation timeout. The specified time-out period was reached according to the conditions.',
30: 'FTP PORT failed. The PORT command failed. Not all FTP servers support the PORT command, '
'try doing a transfer using PASV instead!',
31: 'FTP could not use REST. The REST command failed. This command is used for resumed FTP transfers.',
33: 'HTTP range error. The range "command" did not work.',
34: 'HTTP post error. Internal post-request generation error.',
35: 'SSL connect error. The SSL handshaking failed.',
36: 'Bad download resume. Could not continue an earlier aborted download.',
37: 'FILE could not read file. Failed to open the file. Permissions?',
38: 'LDAP cannot bind. LDAP bind operation failed.',
39: 'LDAP search failed.',
41: 'Function not found. A required LDAP function was not found.',
42: 'Aborted by callback. An application told curl to abort the operation.',
43: 'Internal error. A function was called with a bad parameter.',
45: 'Interface error. A specified outgoing interface could not be used.',
47: 'Too many redirects. When following redirects, curl hit the maximum amount.',
48: 'Unknown option specified to libcurl. This indicates that you passed a weird option to curl that was'
' passed on to libcurl and rejected. Read up in the manual!',
49: 'Malformed telnet option.',
51: 'The peer\'s SSL certificate or SSH MD5 fingerprint was not OK.',
52: 'The server did not reply anything, which here is considered an error.',
53: 'SSL crypto engine not found.',
54: 'Cannot set SSL crypto engine as default.',
55: 'Failed sending network data.',
56: 'Failure in receiving network data.',
58: 'Problem with the local certificate.',
59: 'Could not use specified SSL cipher.',
60: 'Peer certificate cannot be authenticated with known CA certificates.',
61: 'Unrecognized transfer encoding.',
62: 'Invalid LDAP URL.',
63: 'Maximum file size exceeded.',
64: 'Requested FTP SSL level failed.',
65: 'Sending the data requires a rewind that failed.',
66: 'Failed to initialise SSL Engine.',
67: 'The user name, password, or similar was not accepted and curl failed to log in.',
68: 'File not found on TFTP server.',
69: 'Permission problem on TFTP server.',
70: 'Out of disk space on TFTP server.',
71: 'Illegal TFTP operation.',
72: 'Unknown TFTP transfer ID.',
73: 'File already exists (TFTP).',
74: 'No such user (TFTP).',
75: 'Character conversion failed.',
76: 'Character conversion functions required.',
77: 'Problem reading the SSL CA cert (path? access rights?).',
78: 'The resource referenced in the URL does not exist.',
79: 'An unspecified error occurred during the SSH session.',
80: 'Failed to shut down the SSL connection.',
82: 'Could not load CRL file, missing or wrong format.',
83: 'Issuer check failed.',
84: 'The FTP PRET command failed.',
85: 'Mismatch of RTSP CSeq numbers.',
86: 'Mismatch of RTSP Session Identifiers.',
87: 'Unable to parse FTP file list.',
88: 'FTP chunk callback reported error.',
89: 'No connection available, the session will be queued.',
90: 'SSL public key does not matched pinned public key.',
91: 'Invalid SSL certificate status.',
92: 'Stream error in HTTP/2 framing layer.',
93: 'An API function was called from inside a callback.',
94: 'An authentication function returned an error.',
95: 'A problem was detected in the HTTP/3 layer. This is somewhat generic and can be one out of '
'several problems, see the error message for details.',
96: 'QUIC connection error. This error may be caused by an SSL library error. QUIC is the '
'protocol used for HTTP/3 transfers.',
}
def parse_curl(string_table):
try:
section = json.loads(string_table[0][0])
except (IndexError, TypeError, json.JSONDecodeError):
return {}
if 'ERROR' not in section.keys():
return section
def discovery_curl(section: Dict[str, Any]) -> DiscoveryResult:
for key in section.keys():
yield Service(item=key)
def check_curl(item, params, section: Dict[str, Any]) -> CheckResult:
try:
_data = section[item]
except KeyError:
yield Result(state=State.UNKNOWN, notice='Item not found in agent data')
return
url = _data['url'].replace('://', ':__')
http_return_code = _data['data']['http_return_code']
ssl_verify_result = int(_data['data']['ssl_verify_result'])
curl_error_code = int(_data['error_level'])
yield Result(state=State.OK, summary=f'URL: {url}')
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 http_return_code[0] in ['0', '2', '3']: # 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']), notice=f'HTTP Return code: {http_return_code}')
if ssl_verify_result != 0:
yield Result(state=State(params['state_verify_sll_not_0']), notice=f'SSL verify result: {ssl_verify_result}')
else:
yield Result(state=State.OK, notice=f'SSL verify result: {ssl_verify_result}')
yield Result(state=State.OK, notice=f'Scheme (protocol): {_data["data"]["scheme"]}')
yield Result(state=State.OK, notice=f'HTTP version: {_data["data"]["http_version"]}')
yield Result(state=State.OK, notice=f'Redirect URL: {_data["data"]["redirect_url"]}')
yield Result(state=State.OK, notice=f'Remote IP: {_data["data"]["remote_ip"]}')
yield Result(state=State.OK, notice=f'Proxy connect code: {_data["data"]["http_connect"]}')
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',),
]:
if _data['data'].get(key):
value = float(_data['data'][key].replace(',', '.'))
if value != 0:
yield from check_levels(
label=label,
value=value,
metric_name=key,
notice_only=True,
render_func=lambda v: f'{value}s'
)
for key, label in [
('num_connects', '# of connects',),
('num_redirects', '# of redirects',),
]:
if _data['data'].get(key):
value = float(_data['data'][key].replace(',', '.'))
if value != 0:
yield from check_levels(
label=label,
value=value,
metric_name=key,
notice_only=True,
render_func=lambda v: f'{value}'
)
for key, label in [
('size_download', 'Downloaded size',),
('size_header', 'Header size',),
]:
if _data['data'].get(key):
value = float(_data['data'][key].replace(',', '.'))
if value != 0:
yield from check_levels(
label=label,
value=value,
metric_name=key,
notice_only=True,
render_func=render.bytes
)
for key, label in [
('speed_download', 'Download speed',),
]:
if _data['data'].get(key):
value = float(_data['data'][key].replace(',', '.'))
if value != 0:
yield from check_levels(
label=label,
value=value,
metric_name=key,
notice_only=True,
render_func=render.networkbandwidth
)
# yield Result(state=State.OK, notice=f'Details: {_data}')
register.agent_section(
name="curl",
parse_function=parse_curl,
)
register.check_plugin(
name='curl',
service_name='cURL %s',
discovery_function=discovery_curl,
check_function=check_curl,
check_default_parameters={
'state_http_result_not_200': 1,
'state_curl_result_not_0': 1,
'state_verify_sll_not_0': 1,
},
check_ruleset_name='curl'
)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2022-02-15
#
# bakery curl plugin
#
# 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
from pathlib import Path
from typing import List
from cmk.utils import (
password_store,
)
from cmk.base.cee.plugins.bakery.bakery_api.v1 import (
FileGenerator,
OS,
Plugin,
PluginConfig,
register
)
bakery_version = '20220219.v0.0.2'
def get_curl_files(conf: List[any]) -> FileGenerator:
# cconf = (
# 'windows',
# {
# 'url_list': [
# {
# 'service_name': 'test.home.intern',
# 'url': 'https://test.home.intern',
# 'url_settings': {
# 'follow_redirects': '',
# 'ssl_no_verify': '',
# 'http_proxy': (
# 'http_proxy',
# {
# 'proxy_server': ('url.proxy.server', 80),
# 'proxy_auth': ('urluser', ('store', 'default_proxy'), '--proxy-digest')
# }
# )
# }
# }
# ],
# 'default_settings': {
# 'follow_redirects': '-L',
# 'ssl_no_verify': '-k',
# 'http_proxy': {
# 'proxy_server': ('default.proxy.intern', 3128),
# 'proxy_auth': ('defaultuser', ('password', 'defaultpassword'), '--proxy-digest')
# }
# }
# }
# )
field_separator: str = '|' # needs matching separator in the shell scripts
options_separator: str = ' '
os = conf[0]
options = conf[1].copy()
url_cfg_lines = []
url_list = options['url_list']
default_settings = options.get('default_settings', {})
for entry in url_list:
options_array = []
service_name = entry['service_name']
url = entry['url']
url_settings = default_settings.copy()
# merge per url settings with default settings
url_settings.update(entry.get('url_settings', {}))
# if proxy settings from per url settings --> move up once
if type(url_settings.get('http_proxy')) == tuple:
url_settings.update({'http_proxy': url_settings['http_proxy'][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}')
if url_settings['http_proxy'].get('proxy_auth'):
proxy_user, proxy_password, proxy_auth = url_settings['http_proxy']['proxy_auth']
if proxy_password[0] == 'password':
options_array.append(f'--proxy-user {proxy_user}:{proxy_password[1]}')
elif proxy_password[0] == 'store':
pw = password_store.extract(proxy_password[1])
options_array.append(f'--proxy-user {proxy_user}:{pw}')
options_array.append(proxy_auth)
url_settings.pop('http_proxy')
for value in url_settings.values():
options_array.append(value)
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()}')
# else:
# url_cfg_lines.append(f'{service_name}{field_separator}"{url}"')
if os == 'linux':
yield Plugin(
base_os=OS.LINUX,
source=Path('curl.sh'),
target=Path('curl.sh'),
)
yield Plugin(
base_os=OS.LINUX,
source=Path('curl.format'),
target=Path('curl.format'),
)
yield PluginConfig(
base_os=OS.LINUX,
lines=url_cfg_lines,
target=Path('curl.cfg'),
include_header=False,
)
elif os == 'windows':
yield Plugin(
base_os=OS.WINDOWS,
source=Path('curl.cmd'),
target=Path('curl.cmd'),
)
yield Plugin(
base_os=OS.WINDOWS,
source=Path('curl.format'),
target=Path('curl.format'),
)
yield PluginConfig(
base_os=OS.WINDOWS,
lines=url_cfg_lines,
target=Path('curl.cfg'),
include_header=False,
)
register.bakery_plugin(
name='curl',
files_function=get_curl_files,
)
ample cfg
@echo off
:: License: GNU General Public License v2
:: Author: thl-cmk[at]outlook[dot]com
:: URL : https://thl-cmk.hopto.org
:: Date : 2022-02-10
:: based on the work by Christian Wirtz doc[at]snowheaven[dot]de and
:: Wrapper around: https://curl.se/
:: 2022-02-10: rewritten by thl-cmk[at]outlook.com to output json string
:: 2022-02-16: added file checks for CURL_EXECUTABLE and CURL_FORMAT
:: 2022-02-17: added ERRORLEVEL
echo | set /p="<<<curl:sep(0)>>>"
echo.
setlocal
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
set CURL_RUN="FIRST"
If Not Exist "%CURL_CONFIG%" (
echo {"ERROR":"config file %CURL_CONFIG% does not exist"}
exit
)
If Not Exist "%CURL_FORMAT%" (
echo {"ERROR":"format file %CURL_FORMAT% does not exist"}
exit
)
:: 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
)
)
echo | set /p={
FOR /F "tokens=1,2,3 delims=|" %%a IN ('Type "%CURL_CONFIG%"') DO @call :Sub %%a %%b %%c
echo }
goto :EOF
:Sub
if "%CURL_RUN%"=="SECOND" (
echo | set /p=,
) else (
set "CURL_RUN=SECOND"
)
echo | set /p=""%1":{"url":"%2","data""
echo | set /p=:
call "%CURL_EXECUTABLE%" --url %2 %CURL_OPTIONS% %3
echo | set /p=,"error_level":"%ERRORLEVEL%"
echo | set /p=}
goto :EOF
{
"ssl_verify_result":"%{ssl_verify_result}",
"http_return_code":"%{http_code}",
"time_namelookup":"%{time_namelookup}",
"time_connect":"%{time_connect}",
"time_appconnect":"%{time_appconnect}",
"time_pretransfer":"%{time_pretransfer}",
"time_redirect":"%{time_redirect}",
"time_starttransfer":"%{time_starttransfer}",
"time_total":"%{time_total}",
"http_connect":"%{http_connect}",
"http_version":"%{http_version}",
"num_connects":"%{num_connects}",
"num_redirects":"%{num_redirects}",
"redirect_url":"%{redirect_url}",
"remote_ip":"%{remote_ip}",
"scheme":"%{scheme}",
"size_download":"%{size_download}",
"size_header":"%{size_header}",
"speed_download":"%{speed_download}"
}
\ No newline at end of file
#!/bin/bash
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2022-02-20
#
# Wrapper around: https://curl.se/
#
# curl plugin for the check_mk linux agent
#
#
CONF_DIR="/etc/check_mk"
LIB_DIR="/usr/lib/check_mk_agent"
CURL_EXECUTABLE=$(which curl)
CURL_FORMAT=curl.format
CURL_CONFIG=curl.cfg
CURL_RUN=FIRST
printf "<<<curl:sep(0)>>>\n"
if [ ! -x "$CURL_EXECUTABLE" ]; then
printf '{"ERROR":"executable file curl not found"}\n'
exit
fi
if [ -f "$MK_LIBDIR/plugins/$CURL_FORMAT" ]; then
CURL_FORMAT=$MK_LIBDIR/plugins/$CURL_FORMAT
elif [ -f "$LIB_DIR/plugins/$CURL_FORMAT" ]; then
CURL_FORMAT=$LIB_DIR/plugins/$CURL_FORMAT
else
printf '{"ERROR":"format file %s not found"}\n' "$CURL_FORMAT"
exit
fi
if [ -f "$MK_CONFDIR/$CURL_CONFIG" ]; then
CURL_CONFIG=$MK_CONFDIR/$CURL_CONFIG
elif [ -f "$CONF_DIR/$CURL_CONFIG" ]; then
CURL_CONFIG=$CONF_DIR/$CURL_CONFIG
else
printf '{"ERROR":"config file %s not found"}\n' "$CURL_CONFIG"
exit
fi
CURL_OPTIONS="-q -w @$CURL_FORMAT -o /dev/null -s"
# start JSON
printf "{"
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}')
if [ "$CURL_RUN" = "SECOND" ]
then
printf ','
else
CURL_RUN="SECOND"
fi
printf '"%s":{"url":"%s","data":' "$SERVICE_NAME" "$URL"
$CURL_EXECUTABLE --url $URL $CURL_OPTIONS $OPTIONS
ERROR_LEVEL=$?
printf ',"error_level":"%s"}' "$ERROR_LEVEL"
done <"$CURL_CONFIG"
printf "}\n"
# end JSON
unset CONF_DIR
unset LIB_DIR
unset CURL_EXECUTABLE
unset CURL_FORMAT
unset CURL_CONFIG
unset CURL_OPTIONS
unset CURL_RUN
unset SERVICE_NAME
unset URL
unset OPTIONS
unset LINE
unset ERROR_LEVEL
exit 0
curl.mkp 0 → 100644
File added
{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)',
'description': 'cURL CheckMK agent plugin\n',
'download_url': 'https://thl-cmk.hopto.org',
'files': {'agent_based': ['curl.py'],
'agents': ['bakery/curl.py',
'plugins/curl.format',
'plugins/curl.sh',
'plugins/curl.cfg',
'plugins/curl.cmd'],
'web': ['plugins/wato/curl.py', 'plugins/metrics/curl.py']},
'name': 'curl',
'num_files': 8,
'title': 'cURL agent plugin',
'version': '20220120.v0.0.2',
'version.min_required': '2.0.0',
'version.packaged': '2021.09.20',
'version.usable_until': None}
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2022-02-15
#
# Metrics file for the curl plugin
#
# 2022-02-15: rewritten form cmk 2.0, based on the work by doc[at]snowheaven[dot]de
# 2022-02-20: added num_connects, num_redirects, size_download, size_header and speed_download
from cmk.gui.i18n import _
from cmk.gui.plugins.metrics import (
metric_info,
graph_info,
perfometer_info,
check_metrics,
)
metric_info['time_namelookup'] = {
'title': _('Name lookup'),
'unit': 's',
'color': '11/a',
}
metric_info['time_connect'] = {
'title': _('Connect'),
'unit': 's',
'color': '21/a',
}
metric_info['time_appconnect'] = {
'title': _('App connect'),
'unit': 's',
'color': '31/b',
}
metric_info['time_pretransfer'] = {
'title': _('Pre transfer'),
'unit': 's',
'color': '41/c',
}
metric_info['time_starttransfer'] = {
'title': _('Start transfer'),
'unit': 's',
'color': '13/b',
}
metric_info['time_total'] = {
'title': _('Total'),
'unit': 's',
'color': '25/a',
}
metric_info['time_redirect'] = {
'title': _('Redirect'),
'unit': 's',
'color': '33/b',
}
metric_info['num_connects'] = {
'title': _('# of connects'),
'unit': 'count',
'color': '14/a',
}
metric_info['num_redirects'] = {
'title': _('# of redirects'),
'unit': 'count',
'color': '24/b',
}
metric_info['size_download'] = {
'title': _('Download'),
'unit': 'bytes',
'color': '15/b',
}
metric_info['size_header'] = {
'title': _('Header'),
'unit': 'bytes',
'color': '25/b',
}
metric_info['speed_download'] = {
'title': _('Speed'),
'unit': 'bytes/s',
'color': '23/a',
}
graph_info['curl_speed'] = {
'title': _('Speed'),
'metrics': [
('speed_download', 'area'),
],
'optional_metrics': [
'speed_download',
],
}
graph_info['curl_size'] = {
'title': _('Size'),
'metrics': [
('size_header', '-area'),
('size_download', 'area'),
],
'optional_metrics': [
'size_download',
'size_header',
],
}
graph_info['curl_counts'] = {
'title': _('Counts'),
'metrics': [
('num_redirects', '-area'),
('num_connects', 'area'),
],
'optional_metrics': [
'num_connects',
'num_redirects',
],
}
graph_info['curl_times'] = {
'title': _('Times'),
'metrics': [
('time_total', 'line'),
('time_redirect', 'line'),
('time_starttransfer', 'line'),
('time_pretransfer', 'line'),
('time_appconnect', 'line'),
('time_connect', 'line'),
('time_namelookup', 'line'),
],
'optional_metrics': [
'time_total',
'time_redirect',
'time_starttransfer',
'time_pretransfer',
'time_appconnect',
'time_connect',
'time_namelookup',
],
}
perfometer_info.append(
{
'type': 'logarithmic',
'metric': 'time_total',
'half_value': 1.0,
'exponent': 6,
},
)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2022-02-15
#
# WATO file for curl plugin (bakery and check)
#
# 2022-02-19: moved global options under "Default settings"
# added per url settings
# added proxy settings (--proxy, --proxy-user, --proxy-digest/--proxy-basic/--proxy-ntlm/--proxy-anyauth)
# added follow redirects (--location)
# added don't verify certificates (--insecure)
#
from cmk.gui.i18n import _
from cmk.gui.valuespec import (
Dictionary,
ListOf,
CascadingDropdown,
TextUnicode,
FixedValue,
Integer,
Tuple,
DropdownChoice,
)
from cmk.gui.plugins.wato import (
rulespec_registry,
HostRulespec,
)
from cmk.gui.plugins.wato.utils import (
PasswordFromStore,
)
from cmk.gui.cee.plugins.wato.agent_bakery.rulespecs.utils import (
RulespecGroupMonitoringAgentsAgentPlugins,
)
bakery_plugin_version = '20220219.v0.0.2'
_option_service_name = (
'service_name',
TextUnicode(
title=_('Service name'),
help=_('Name for the discovered service, for example www.example.com'),
allow_empty=False,
)
)
_option_url = (
'url',
TextUnicode(
title=_('URL to check'),
help=_('URL to check with cURL, for example https://www.example.com'),
allow_empty=False
)
)
_options_ssl_no_verify = (
'ssl_no_verify',
FixedValue(
'--insecure',
title=_('Don\'t verify certificates'),
totext=_('Certificates will not be verified (insecure)'),
help=_('Disables the certificate check on TLS/SSL connections. Implements the "-k" option'),
)
)
_options_follow_redirects = (
'follow_redirects',
FixedValue(
'--location',
title=_('Follow redirects'),
totext=_('Follow redirects enabled'),
help=_('curl will follow redirects. Implements the "-L" option'),
)
)
_option_proxy_server = (
'proxy_server',
Tuple(
elements=[
TextUnicode(
label=_('Proxy server address'),
help=_('Name or IP-address of the proxy server.'),
allow_empty=False,
),
Integer(
label=_('TCP port'),
default_value=3128,
minvalue=1,
maxvalue=65565,
),
],
)
)
_option_proxy_auth = (
'proxy_auth',
Tuple(
title=_('Proxy authentication'),
help=_(
'The password entered here is stored in plain text within the monitored host. This is '
'needed because the agent plugin process needs to have access to the unencrypted password '
'because it needs to submit it to authenticate with the proxy.'
),
elements=[
TextUnicode(title=_('Username'), allow_empty=False),
PasswordFromStore(title=_('Password of the user'), allow_empty=False),
DropdownChoice(
title=_('Authentication method'),
choices=[
('--proxy-basic', _('Digest authentication')),
('--proxy-digest', _('Basic authentication')),
('--proxy-ntlm', _('NTLM authentication')),
('--proxy-anyauth', _('Negotiate authentication')),
]),
],
)
)
_options_proxy = (
'http_proxy',
Dictionary(
title='Use HTTP proxy',
elements=[
_option_proxy_server,
_option_proxy_auth,
],
required_keys=['proxy_server'],
),
)
_option_url_settings = (
'url_settings',
Dictionary(
title=_('Override default settings'),
elements=[
('follow_redirects',
DropdownChoice(
title=_('Redirects'),
choices=[
('--location', _('Follow redirects')),
('', _('Don\'t follow redirects')),
],
)),
('ssl_no_verify',
DropdownChoice(
title=_('Certificates'),
choices=[
('--insecure', _('Verify certificates')),
('', _('Don\'t verify certificates')),
],
)),
('http_proxy',
CascadingDropdown(
title=_('HTTP proxy'),
sorted=False,
choices=[
('http_proxy', _('Use HTTP proxy'),
Dictionary(
title='Use HTTP proxy',
elements=[
_option_proxy_server,
_option_proxy_auth,
],
required_keys=['proxy_server'],
)),
('', _('Don\'t use HTTP proxy')),
],
)),
]
)
)
_option_url = (
'url_list',
ListOf(
Dictionary(
elements=[
_option_service_name,
_option_url,
_option_url_settings,
],
required_keys=['service_name', 'url'],
),
add_label=_('Add URL'),
movable=True,
title=_('URLs to check'),
allow_empty=False,
)
)
_option_default_settings = (
'default_settings',
Dictionary(
title=_('Default settings'),
elements=[
_options_follow_redirects,
_options_ssl_no_verify,
_options_proxy,
]
)
)
elements = [
_option_url,
_option_default_settings
]
def _valuespec_agent_config_curl():
return CascadingDropdown(
title=_('cURL'),
sorted=False,
choices=[
('linux',
_('Deploy Linux cURL agent plugin'),
Dictionary(
elements=elements,
required_keys=['url_list'],
)),
('windows',
_('Deploy Windows cURL agent plugin'),
Dictionary(
elements=elements,
required_keys=['url_list'],
)),
(None, _('Do not deploy the cURL agent plugin')),
],
)
rulespec_registry.register(
HostRulespec(
group=RulespecGroupMonitoringAgentsAgentPlugins,
name='agent_config:curl',
valuespec=_valuespec_agent_config_curl,
)
)
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