diff --git a/docs/20_Checks/_index.md b/docs/20_Checks/_index.md index 134d2b73d377dd1dc1001d1974c46c5cfa3d5599..c02273cecd0e289f662c907420303686f4024179 100644 --- a/docs/20_Checks/_index.md +++ b/docs/20_Checks/_index.md @@ -25,6 +25,7 @@ There is one include script used by all checks: * [check_fs_writable](check_fs_writable.md) * [check_haproxy_health](check_haproxy_health.md) * [check_haproxy_status](check_haproxy_status.md) +* [check_http](check_http.md) * [check_memory](check_memory.md) * [check_mysqlserver](check_mysqlserver.md) * [check_netio](check_netio.md) diff --git a/docs/20_Checks/check_httpd.md b/docs/20_Checks/check_httpd.md new file mode 100644 index 0000000000000000000000000000000000000000..30a03fc10af2d4877de3fbc5773cc7024e22990d --- /dev/null +++ b/docs/20_Checks/check_httpd.md @@ -0,0 +1,137 @@ +# Check Httpd + +## Introduction + +Makes an http request with a given method. +Additionally you can verify the response. + +## Requirements + +* `curl` binary + +## Syntax + +```txt +______________________________________________________________________ + +CHECK_HTTP +v1.0 + +(c) Institute for Medical Education - University of Bern +Licence: GNU GPL 3 + +https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_http.html +______________________________________________________________________ + +Makes an http request with a given method. +Additionally you can verify the response by +- http status code +- content in http response header +- content in http response body +- content that is NOT in http response body + +SYNTAX: + check_http [-h] + check_http [-m METHOD] -u URL \ + [-b REGEX] [-j FILTER] [-n REGEX] \ + [-r REGEX] \ + [-s STATUSCODE] \ + [-l LABEL] + +OPTIONS: + + -h this help + +PARAMETERS: + + Define request: + -u URL Set url to fetch; eg. https://www.example.com/ + -m METHOD Set a method, eg. HEAD; default: GET + + What to check: + -s STATUSCODE exact Statuscode to check; 3 digits; by default critical + is a statuscode greater equal 400 + -r REGEX Regex must match in http response header + -j JQ-FILTER for JSON Response: filter data by a jq + -b REGEX Regex must match in response body + -n REGEX Regex must NOT match in response body + + Output: + -l LABEL set a custom label; default: METHOD + URL eg. + "GET https://example.com/status" + +EXAMPLES: + + check_http -u https://www.example.com/ + Check if GET request to url responds with 200..3xx status. + + check_http -m HEAD -u https://www.example.com/ + Check if HEAD request to url responds with 200..3xx status + + check_http -u [URL] -s 403 + Check if the GET request to url has a wanted status code. + You can verify if a protected url is not accessible. + + check_http -u [URL] -b "contact" + Check if the GET request to url responds with 200..3xx + status and the response body contains "contact". + + check_http -u [URL] -n "error occured" + Check if the GET request to url responds with 200..3xx + status and the response body NOT contains "error occured". + + check_http -u [URL] -s 200 -b -b "contact" -n "error occured" + Combine code, a matching search and a non matching one. + +``` + +## Examples + +### Simple check of an url + +``check_http -u https://www.example.com/`` is a check that makes an http GET request. +The queck is OK if the responded status code is no error - if it is 2xx (OK) or a redirect (3xx). + +```txt +OK: GET https://www.example.com/ (200) + +Command: curl -si -X GET https://www.example.com/ + +Found: +- Http status is a 2xx OK [200]; +``` + +### Http HEAD of an url + +You can set the method with ``-m``. +``./check_http -m head -u https://www.example.com/`` responds + + +```txt +OK: HEAD https://www.example.com/ (200) + +Command: curl -si -X HEAD https://www.example.com/ + +Found: +- Http status is a 2xx OK [200]; +``` + +### Exact status code + +With ``-m`` you can verify if the status code matches exactly a given value. +You also can set a code for http error to ensure if a protected url really is blocking the request. + +Maybe you don't deny the access like + +* ``./check_http -u https://www.example.com/memberarea -s 403`` +* ``./check_http -u https://www.example.com/config/settings.json -s 403`` + +Or you can check a flag file that must be absent. + +* ``./check_http -u https://www.example.com/flag_maintenance.txt -s 404`` + +### Matching content + +You can verify if the response matches a given regex. You can search in the response header with ``-r REGEX`` and in the response body with ``-b REGEX``. + +``check_http -u [URL] -b "contact"`` will resppns OK if the status code is not an error (lower 400) and the word "contact" is found in response body.