NAME
Monitoring::Sneck::Checks::http - checks a HTTP or HTTPS server
VERSION
Version 0.0.1
SYNOPSIS
www|perl:http -H www.example.org -S -w 1 -c 2 -s 'Welcome'
api|perl:http -u https://api.example.org/health -e 200 -r '"status":\s*"ok"'
feed|perl:http -H www.example.org -u /feed.xml -x '//item'
to_https|perl:http -H www.example.org -L https://www.example.org/
hsts|perl:http -H www.example.org -S -E 'Strict-Transport-Security: max-age=[0-9]{8}' -E Content-Security-Policy
DESCRIPTION
Fetches a URL through LWP::UserAgent. With no --expect, 2xx and 3xx are OK, 4xx is WARNING, and anything else is CRITICAL, including not being able to connect. Content that does not match is CRITICAL.
Certificates are checked for HTTPS unless --insecure is given. See Monitoring::Sneck::Checks::https_cert for when they expire.
OPTIONS
- -H, --hostname :: The host. Required unless --url is a whole URL.
- -u, --url :: The path, or a whole URL, in which case --hostname, --port, and --ssl are ignored. Default :: /
- -p, --port :: The port. Default :: 80, or 443 with --ssl
- -S, --ssl :: Use HTTPS.
- -j, --method :: The method. Default :: GET
- -P, --post :: Content to send, which makes the method POST unless --method is given.
- -T, --content-type :: The type of what --post sends. Default :: application/x-www-form-urlencoded
- -k, --header :: A header to send, as "Name: value". May be given more than once.
- -e, --expect :: Status codes that are OK, comma separated. Anything else is CRITICAL.
- -s, --string :: Text the content must have.
- -r, --regex :: A regex the content must match.
- --invert-regex :: The content must not match --regex.
- -x, --xpath :: A XPath expression that must find something in the content, parsed as XML if it says it is, else as HTML.
- -f, --follow :: Follow up to 5 redirects.
- -E, --expect-header :: "Name", a header that must be there, or "Name: regex", one that must match the regex. Names are not case sensitive. May be given more than once.
- -L, --location :: Where it must redirect to. A relative one is taken from the URL fetched, as is the Location header, so /login and https://www.example.org/login are the same for https://www.example.org/. No Location, or a different one, is CRITICAL. Can not be used with --follow.
- -w, --warning :: Range of seconds for the response time.
- -c, --critical :: Range of seconds for the response time.
- --insecure :: Do not check the certificate.
- --ca-file :: The CA file to check the certificate against.
METHODS
url
Returns the URL to fetch.
check
Does the check.
content_problems
Checks the response as --location, --expect-header, --string, --regex, and --xpath say. A subclass may add its own checks to these.
- response :: The HTTP::Response.
- content :: Its decoded content.
Returns a list of array refs of the code and what is wrong, one for each problem.
foreach my $found ( $check->content_problems( $response, $content ) ) {
my ( $code, $problem ) = @{$found};
}
status_code
Returns the code for a HTTP status, as said under "DESCRIPTION".
$check->status_code(404); # WARNING, unless --expect is given
xpath_count
Returns how many nodes --xpath finds in the content of a response, 0 if it can not be parsed.