This is a monitoring script to check availability of webpages, content delivery, uptime of web servers, content negotiation etc... It can be used in any monitoring infrastructure, such as Nagios or Icinga.
The Perl script requires
- the Nagios plugin library in
/usr/lib/nagios/plugins/utils.pm - LWP::UserAgent
- Getopt::Long
- HTTP::Cookies
- URI
perl -w check_links.pl [OPTIONS] -u URL
Here, OPTIONS may be:
--url URLor-u URLthe URL to the site---status STATUSor-s STATUSyou expectSTATUSto be the returned HTTP status code (default:200)---no-statusdo not check the HTTP status---content "CONTENT"or-c "CONTENT"you expectCONTENTto appear within the response---referer "REFERER"or-r "REFERER"useREFERERwhen sending the request---user-agent "USER AGENT"pretend to be the user agentUSER AGENT---header "KEY=VALUE"expected HTTP header value asKEY=VALUE, multiple options are possible andVALUEmay be a regex---cookie "NAME=VALUE"sent a cookieNAME=VALUE, multiple options possible---accept "MIME"or-a "MIME"ask for a result of content typeMIME, especially useful to check for content negotiation---followor-fshould we follow redirects?---timeout INTor-t INTwaitINTseconds before timeout---helpor-hshow this help
The script's return code and message is to be interpreted by your monitoring infrastructure.
perl -w check_links.pl -u https://binfalse.de
perl -w check_links.pl -u http://goo.gl/33e3Lb -s 301 --header location=https://binfalse.de/
perl -w check_links.pl -u http://binfalse.de/ -s 301 --header location=https://binfalse.de/
perl -w check_links.pl -h content-length=191406 -h "server=nginx.*" -u https://binfalse.de/assets/media/pics/2016/drm-inchains.png
Here, the image needs to be exactly of size 191406 Bytes and the regex nginx.* matches to NGINX in any version.
perl -w check_links.pl -c userid=karl -c secret=passwd123456 -u https://secret.site
Check that you get XML when asking for XML:
check_links.pl -u http://purl.uni-rostock.de/comodi/comodi#Attribution -f -a text/xml --header content-type=xml
Check that you get HTML when asking for HTML:
check_links.pl -u http://purl.uni-rostock.de/comodi/comodi#Attribution -f -a text/html --header content-type=text/html
There is a python tool in src/test.py that performs some basic test to verify that check_links.pl is working correctly.
I'd like to encourage you to add further test when extending check_links.pl!
check_links - Monitor web Resources
Copyright (C) 2017 Martin Scharm <https://binfalse.de/contact/>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.